在Firefox扩展中使用indexedDB [英] Using indexedDB in a Firefox extension
问题描述
我无法在Firefox扩展中使用indexedDB保存数据。我还找不到任何有关indexedDB和Firefox扩展的信息。
有没有人处理过这个问题?
唯一的问题是,对于 indexedDB
,您需要一个窗口,除此之外,从附加组件。传统的附加组件通常有一个可以使用的窗口,但是使用附加组件SDK创建的附加组件可以在无窗口的环境下执行。因此,如果您使用SDK,您可以使用内部 window-utils
包:
var window = require(window-utils)。
var indexedDB =(window.indexedDB || window.mozIndexedDB);
var request = indexedDB.open(MyExtensionDB);请注意,所有的扩展名都使用相同的名称空间( chrome://
> code>),就像IndexedDB一样。所以你应该选择数据库名称,使其不会与其他扩展名可能选择的名称相冲突。
从Firefox 12开始,需要有一个窗口被丢弃。 nsIIndexedDatabaseManager.initWindowless()
可用于将 mozIndexedDB
属性注入到任何对象中。相关错误:错误587797 。
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?
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.
这篇关于在Firefox扩展中使用indexedDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!