我的 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);
这在我的 popup.js 中:
var bgPage = chrome.extension.getBackgroundPage();
var isOn = bgPage.getFromStorage("isOn", true);
var silent = bgPage.getFromStorage("silent", false);
我得到这个错误:
Object [object Window] has no method 'getFromStorage'
非常感谢您的帮助,谢谢:)