Yos*_*ale 43 google-chrome-extension google-chrome-storage
我试图通过content_script在扩展中使用chrome存储,但我一直在失败
Uncaught TypeError: Cannot read property 'sync' of undefined
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
testChromeStorage();
function testChromeStorage() {
console.log("Saving");
chrome.storage.sync.set({'value': theValue}, function() {
message('Settings saved');
});
chrome.storage.sync.get("value", function (retVal) {
console.log("Got it? " + retVal.value);
});
}
Run Code Online (Sandbox Code Playgroud)
sfa*_*ota 90
您必须在manifest.json文件中添加"storage"权限,即:
...
"permissions": [
"storage"
],
...
Run Code Online (Sandbox Code Playgroud)
有关更多信息,请参阅:https://developer.chrome.com/extensions/storage
重新加载扩展
我在manifest文件中添加了“ permissions”键,但仍然很难解决此问题。
添加权限后:
"permissions": [
"storage"
]
Run Code Online (Sandbox Code Playgroud)
使用以下网址转到您的扩展程序:chrome:// extensions /,然后点击重新加载按钮:-
| 归档时间: |
|
| 查看次数: |
19455 次 |
| 最近记录: |