我正在尝试开发 Chrome 扩展程序。在其中我有一个选项页面和一个 contentscript.js
都在 manifest.js
中注册。
我在 option.js
中使用了本地存储。现在我想从 contentscript.js
访问本地存储的数据,所以我找到了以下代码将请求从 contentscript.js
发送到 background.js
:
chrome.extension.sendRequest({method: "getStatus"}, function(response) {
console.log(response.status);
});
background.js
使用以下响应:
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
if (request.method == "getStatus")
sendResponse({status: localStorage['status']});
else
sendResponse({}); });
现在它显示以下错误:
undefined in line "console.log(response.status);" in file contentscript.js .
这有什么问题?
如何从 contentscript.js
获取整个本地存储访问权限?
最佳答案
它看起来像工作代码。 检查您的 list 文件和 localStorage.status
http://code.google.com/chrome/extensions/messaging.html http://code.google.com/chrome/extensions/content_scripts.html
关于javascript - 从 Chrome 扩展程序中的内容脚本访问本地存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10703174/