Using indexedDB in a Firefox extension

前提是你 提交于 2019-12-10 10:54:37

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/9042390/using-indexeddb-in-a-firefox-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!