I'm developing Firefox add-on which has some content scripts to save data to IndexedDB. Same code works perfectly fine in Chrome extension, but not in Firefox extension. On Firefox everything works fine until part where data has to be written to database.
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 // part where it doesn't work in Firefox
function transition(location, time, date) {
var db = new Dexie("myDatabase");
db.version(1).stores({
likes: 'url, date, time'
});
db.open();
db.likes.add({url: location, date: date, time: time}).then (function(){
alert("Informations are added.");
}).catch( function(error) {
alert("There's an error: " + error);
});
}
I checked in Storage Inspector too, nothing is added to database. One more detail: I think that problem may be caused by script loading because I defined at start of content-script.js to load everything when DOM is ready (maybe, but I'm not sure if it's caused by that, I tried "start" , "ready" and "end" in contentScriptWhen parameter).
document.addEventListener("DOMContentLoaded", function(event) {
Everything in content-script.js is inside this event listener.