I have this in my background.js:
var write = function (line) {
if (localStorage["silent"] == true) {
chrome.extension.getBackgroundPage().console.log(line);
} else {
alert(line);
}
}
var getFromStorage = function (item, default) {
if (localStorage[item] == undefined) {
write("Could not find " + item + " in local storage...");
return default;
} else {
return localStorage[item];
}
}
var isOn = getFromStorage("isOn", true);
var silent = getFromStorage("silent", false);
And this in my popup.js:
var bgPage = chrome.extension.getBackgroundPage();
var isOn = bgPage.getFromStorage("isOn", true);
var silent = bgPage.getFromStorage("silent", false);
And I get this error:
Object [object Window] has no method 'getFromStorage'
Help is greatly appreciated, thanks 🙂
You should change the
defaultparameter in your background scriptBecause
defaultis reserved in javascript. (It is used in conjunction with the Switch statement)Therefore the background page wouldn’t load at all and Inspecting it should result in something like this
Uncaught SyntaxError: Unexpected token default at background.js:8Which then leads to the error
Object [object Window] has no method 'getFromStorage'in your popup script, because
getFromStorageactually never has been loaded in your background script because of terminating at Line 8