Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/470.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Firefox插件的内容脚本不';t写入IndexedDB_Javascript_Firefox_Firefox Addon_Indexeddb_Dexie - Fatal编程技术网

Javascript Firefox插件的内容脚本不';t写入IndexedDB

Javascript Firefox插件的内容脚本不';t写入IndexedDB,javascript,firefox,firefox-addon,indexeddb,dexie,Javascript,Firefox,Firefox Addon,Indexeddb,Dexie,我正在开发Firefox插件,它有一些内容脚本来将数据保存到IndexedDB。同样的代码在Chrome扩展中工作得非常好,但在Firefox扩展中却不行。在Firefox上,一切正常,直到数据写入数据库的部分 index.js var data = require("sdk/self").data; var pageMod = require("sdk/page-mod"); var { indexedDB } = require('sdk/indexed-db'); var request

我正在开发Firefox插件,它有一些内容脚本来将数据保存到IndexedDB。同样的代码在Chrome扩展中工作得非常好,但在Firefox扩展中却不行。在Firefox上,一切正常,直到数据写入数据库的部分

index.js

var data = require("sdk/self").data;
var pageMod = require("sdk/page-mod");
var { indexedDB } = require('sdk/indexed-db');

var request = indexedDB.open("myDatabase");

request.onerror = function(event) {
    console.log("Failure.");
};

request.onsuccess = function(event) {
    console.log("Success.");
};

pageMod.PageMod({
    include: "*",
    contentScriptWhen: "start",
        //contentScriptFile: ["./js/jquery.min.js", "./js/jquery-ui.min.js", "./js/Dexie.min.js", "./js/content-script.js"]
    contentScriptFile: [data.url("js/jquery.min.js"), data.url("js/content-script.js"), data.url("js/jquery-ui.min.js"), data.url("js/Dexie.min.js")],
    contentStyleFile: [data.url("css/jquery-ui.min.css")]
});
content script.js//它在Firefox中不起作用的部分

我也签入了存储检查器,数据库中没有添加任何内容。还有一个细节:我认为这个问题可能是由脚本加载引起的,因为我在content-script.js的开头定义了在DOM就绪时加载所有内容(可能是这样,但我不确定是否是因为这个原因,我在contentScriptWhen参数中尝试了“start”、“ready”和“end”)


content script.js中的所有内容都在此事件侦听器中。

默认情况下,Dexie将使用indexedDB from window或self。在firefox中,加载项没有在窗口中运行,因此Dexie可能找不到它。在Dexie v1.3.6中,可以在构造函数中提供indexedDB API

尝试最新的Dexie v1.3.6并执行以下操作:

var idb = require('sdk/indexed-db');
var db = new Dexie("myDatabase", {
    indexedDB: idb.indexedDB,
    IDBKeyRange: idb.IDBKeyRange
});

开发人员工具控制台中是否有任何错误?您是在firefox中使用JPM扩展还是WebExtensions?@JaromandaX Nope,这也很奇怪,我在控制台中没有发现任何与此相关的错误。我正在使用JPM。谢谢你的回答。它仍然不起作用,但至少在尝试添加/获取数据时,我最终得到了一个错误:
MissingAPIError:indexeddbapi未找到。如果使用IE10+,请确保在服务器URL(而不是本地)上运行代码。如果使用Safari,请确保包含indexedDB polyfill。
我现在真的很困惑,它应该可以在FF 47上使用……您确定您使用的是Dexie v1.3.6,并且正确拼写indexedDB,包括下半身和上半身吗?是的,我从GitHub下载了最新版本的Dexie,并检查了整个代码两次。只是为了确定-第一行是index.js,第二行是我的内容脚本?
document.addEventListener("DOMContentLoaded", function(event) {
var idb = require('sdk/indexed-db');
var db = new Dexie("myDatabase", {
    indexedDB: idb.indexedDB,
    IDBKeyRange: idb.IDBKeyRange
});