javascript - `chrome.storage.sync.get (['auth'] ... `content.js` 中的 `Alert` 返回一个空对象
问题描述
通过输入 www.app.com 我想访问auth
本地存储中的密钥并将其显示在警报中。在content.js
我使用的文件chrome.storage.sync.get
中。当我访问 www.app.com 时,alert
出现了一个,但它的内容只是一个空对象{}
,并且应该包含auth
密钥的内容。
chrome.storage.sync.get(['auth'], function(result) {
alert(JSON.stringify(result));
});
在本地存储中,我有 key: auth
,
{access_token:"1234567"
expires_in: 86400
refresh_token: "8906789"
scope: null
token_type: "Bearer"
}
内容.js
chrome.storage.sync.get(['auth'], function(result) {
alert(JSON.stringify(result));
chrome.runtime.sendMessage(item, function(response) {
console.log(response);
});
});
清单.json
{
"name": "EXTENSION",
"options_page": "options.html",
"background": {
"page": "background.html"
},
"content_scripts": [{
"matches": [ "*://*.app.com/*" ],
"js": [ "content.js" ],
"all_frames": true
}],
"browser_action": {
"default_popup": "popup.html",
"default_icon": "icon-34.png"
},
"icons": {
"128": "icon-128.png"
},
"permissions": [
"https://*/",
"http://*/",
"*://*.app.com/*",
"storage"
],
"version": "1.0",
"manifest_version": 2,
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"
}
解决方案
推荐阅读
- c# - 当我从 SSRS 报告中保存 PDF 时,文本在保存的 PDF 中被重叠或截断
- java-native-interface - 从 cocos2d-x 到 Android 调用 JNI 在 Release 模式下不会触发
- c - 不带参数的 pthread_create 函数
- python - 在Python中首先是高度还是宽度?
- php - 如何从 php 容器中的 dockerfile 运行 composer install
- python - 加载由 tensorflow 训练的 Keras 模型时出错
- xamarin - 如何根据 Selected Bool 参数更改模板控件的属性 (TextColor)?
- asp.net - 通过 React Axios 使用具有相同路由的 Web API 服务
- javascript - 使用 vanilla javascript 上传 doc 或 excel 文件并在 html 页面上显示时显示垃圾字符
- xunit - xUnit:将夹具作为类型参数传递给另一个 IClassFixture 夹具