Using IndexedDB in chrome

The indexedDB API is typically used to store data in the user's browser from content JavaScript.  (See Using IndexedDB for an overview.)  However, the APIs can be also be accessed from system-privileged JavaScript using the Components.utils.importGlobalProperties() function:

JavaScript
Components.utils.importGlobalProperties(["indexedDB"]);

// From here on, it's like using IndexedDB from content
var req = indexedDB.open("my-database");
// ...

If you are creating a sandbox, and want indexedDB to be available in it, use the wantGlobalProperties option in the Sandbox constructor:

JavaScript
var options = {
  "wantGlobalProperties": ["indexedDB"]           
}
var principal = Cc["@mozilla.org/systemprincipal;1"].createInstance(Ci.nsIPrincipal);
var sandbox = Components.utils.Sandbox(principal, options);

// The sandbox will have access to indexedDB
var sandboxScript = 'var req = indexedDB.open("my-database");';
Components.utils.evalInSandbox(sandboxScript, sandbox);

Before Firefox 33, you would access indexedDB from chrome code using the initWindowless method of the nsIIndexedDatabaseManager service. This method was removed in Firefox 33.

License

© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/api/indexeddb_api/using_indexeddb_in_chrome