Silviu-Marian
Silviu-Marian

Reputation: 10907

Shipping SQLite dbs with Chrome Extensions?

I want to be able to include an sqlite file with a Chrome Extension, and make it so that the extension can perform read/write ops on that db. I will be using it for process intercom (by lack of alternatives) so I can override configs / pass command-line parameters / etc. to Chrome.

Can someone please point me in the right direction?

Upvotes: 1

Views: 534

Answers (3)

Silviu-Marian
Silviu-Marian

Reputation: 10907

OP here. Partially solved. Chrome supports passing --user-data-dir=%appdata%/whatever

From where in my external application I can access %appdata%/Whatever/databases/Databases.db, open Databases table, filter by origin, get an ID and open %appdata%/Whatever/databases/origin/ID. It's somewhat hackish but will do.

What puzzles me now is that:

  • It did't yell at my attempt to openDatabase('X','1.0','plm',100*1024*1024); I was expecting some resistance at asking 100MB without "unlimitedStorage" permission
  • not sure what the _0 postfix in origin
  • chrome-extension_bhapcikibejcipnnpimookjaibhlddfd_0 might be inconsistent; is it safe to hardcode in the other application?

Upvotes: 0

Marius Kjeldahl
Marius Kjeldahl

Reputation: 6824

You can't do what you want by shipping a file AFAIK, but since WebSQL in Chrome is essentially SQLite you could ship your "database" as JSON datastructures in your code, and use that to initialize a WebSQL instance in Chrome when you initialize the WebSQL database for your application/extension.

Upvotes: 1

Joao
Joao

Reputation: 7486

Chrome is very strict when it comes to use outside files.

Anyway, Chrome extensions should use localStorage. Something like:

localStorage["varName"] = data;

or

localStorage.varName = data

and

var data = localStorage.varName

Check for more info here

Upvotes: 0

Related Questions