我试图开发一个铬扩展名。 其中我有一个选项页面和一个 contentscript.js
, 都在 manifest.js
中注册 。
我在 option.js
中使用了本地存储。 现在我想从 contentstatim.js
访问本地存储的数据, 因此我找到了以下代码来发送请求到 beground.js
从 contentstatim.js
发送请求到 beground.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({}); });
它现在显示以下错误:
未定义的行“conole.log( responsid. status) ” 中, 在文件内容描述. js 中 。
What is the problem with that?
How can I get whole local storage access from contentscript.js
?