2023 replacing WebSQL - CameronD73/529renew GitHub Wiki

groan - WebSQL is disappearing soon- scheduled for removal in Chrome V119 (early November 2023).

Options for replacement

Google and others offers lots of less than optimim suggestions:

  • indexedDB (no SQL)
  • sql.js (in-memory operation only) - transient - have to explicitly convert to another format every time you want to save to permanent storage, so very liable to loss through crashing.
  • absurd.js - using indexedDB as the permanent storage for sql.js. The name says it all.
  • sqlite3-wasm : web Assembly version of sqlite3. This seems the only viable possibility to retain full function. By default it is also transient, although use with OPFS can make it permanent.

Options for future direction

  • Full support for current features: sqlite3-wasm seems to be the only viable option to retain full features
  • remove graphics and possibly gexf export - this would make indexedDB viable.
  • give up.

Sqlite3-wasm

  • intro by Google on sqlite-wasm + OPFS
  • There is a Google blog on migration but it is just about transferring your data rather than the code.
  • Documentation by SQLite.org
  • There is a lot of contradictory "advice" popping up, because the WASM concept seems to be focussed on code supplied by original web pages, rather than extensions. For example, "wasm files must be loaded from a remote web server (that supports specific header options)", and "wasm files for an extension cannot be loaded from a remote server".
  • a Worker thread is required for OPFS operation.
  • concurrent access is regarded by sqlite as being somewhat flakey.

Sqlite3-wasm in an Extension

  • Some discussion here
  • V3 manifest blocks loading remote code (WASM library)
  • you cannot create a worker from the content pages, only oner of the extension's pages
  • you cannot load a Worker from the service worker (they are unrelated)
  • example Whosum extension code linked from above discussion loads Worker from extension page:popup. Also uses local storage for intermediate buffering
  • Even a Chrome dev was suggesting (Feb 2023) using an offscreen document in the extension context, but was not sure if it would be viable. It then seems to have been permitted from V113.

It looks like I'll try sticking with the kludgy "results tab" for the moment.

Apparent Bugs encountered

The following problems arose while trying to implement the sqlite-Wasm code.

  • The saveSql option to DB.exec() seems to always return the original string, and never with the bound parameters - a bit pointless for debugging.
  • the OPFS read() method under Chrome refuses to accept an ArrayBuffer type - must be a DataView, despite spec saying ArrayBuffer is suitable.