localforage 的作者不打算支持 Firefox 插件,但这并不意味着不可能。这是相关问题:https ://github.com/mozilla/localForage/issues/584
您可以为 localforage 编写自定义驱动程序:https ://github.com/mozilla/localForage/pull/282
dist/localforage.min.js
或者在将其包含在您的插件中之前将此代码添加到文件顶部:
/**
* Detect Firefox SDK Addon environment and prepare some globals
*
* @author Dumitru Uzun (DUzun.Me)
*/
(function (window, undefined) {
if (typeof exports != "object" || typeof module == "undefined") return;
if ( window && window.Array === Array ) try {
window.window = window;
// Timers
if ( typeof setTimeout == 'undefined' ) {
expo(
require("sdk/timers")
, [
'setTimeout' , 'clearTimeout',
'setImmediate', 'clearImmediate'
]
);
}
// Blob, FileReader
var Cu = require("chrome").Cu;
var Services = Cu['import']("resource://gre/modules/Services.jsm", {});
expo(
Services
, ['Blob', 'FileReader']
);
expo(
Services.appShell && Services.appShell.hiddenDOMWindow
, ['Blob', 'FileReader']
);
// IndexedDB
expo(require('sdk/indexed-db'));
} catch(err) {
console.log('error', err);
}
function expo(ctx, props) {
if ( !ctx ) return;
if ( !props ) props = Object.keys(ctx);
for(var i=props.length,p; i--;) {
p = props[i];
if ( ctx[p] != undefined && !(p in window) ) {
window[p] = ctx[p];
}
}
return ctx;
}
}(this));