[英]Access local storage from content script in Chrome extension programing
I'm trying to develop a Chrome extension. 我正在尝试开发Chrome扩展程序。 In it I have one option page and a
contentscript.js
both registered in manifest.js
. 在其中,我有一个选项页和一个
contentscript.js
都注册在manifest.js
。
I have used local storage in option.js
. 我在
option.js
使用了本地存储。 Now I want to access data of local storage from contentscript.js
so I found following code to send request to background.js
from contentscript.js
: 现在我想从
contentscript.js
访问本地存储的数据,所以我找到了以下代码以将请求从contentscript.js
发送到background.js
:
chrome.extension.sendRequest({method: "getStatus"}, function(response) {
console.log(response.status);
});
And background.js
using following to respond: 然后
background.js
使用以下响应:
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
if (request.method == "getStatus")
sendResponse({status: localStorage['status']});
else
sendResponse({}); });
Now it is showing following error: 现在显示以下错误:
undefined in line "console.log(response.status);"
在“ console.log(response.status)”行中未定义; in file contentscript.js .
在contentscript.js文件中。
What is the problem with that? 这是什么问题? How can I get whole local storage access from
contentscript.js
? 如何从
contentscript.js
获取整个本地存储访问权限?
It looks like working code. 看起来像工作代码。 Check your manifest file and localStorage.status
检查清单文件和localStorage.status
http://code.google.com/chrome/extensions/messaging.html http://code.google.com/chrome/extensions/content_scripts.html http://code.google.com/chrome/extensions/messaging.html http://code.google.com/chrome/extensions/content_scripts.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.