Reputation: 173
I can't manage to save data using indexedDB in a Firefox extension. I also cannot find any information about indexedDB and Firefox extensions.
Has anyone ever dealt with this?
Upvotes: 3
Views: 1332
Reputation: 57651
The only problem is, for indexedDB
you need a window, other than that there is not much special when using it from an add-on. Classic add-ons usually have a window that they can use, add-ons created with the Add-on SDK execute in a window-less context however. So if you are using the SDK you use the internal window-utils
package:
var window = require("window-utils").activeWindow;
var indexedDB = (window.indexedDB || window.mozIndexedDB);
var request = indexedDB.open("MyExtensionDB");
Note that all extensions use the same namespace (chrome://
) as far as IndexedDB goes. So you should choose the database name in such a way that it doesn't collide with the names other extensions might choose.
Starting with Firefox 12 the requirement to have a window is dropped. nsIIndexedDatabaseManager.initWindowless()
can be used to inject mozIndexedDB
property into any object. Relevant bug: bug 587797.
Upvotes: 3