javascript - 未捕获的类型错误:尽管具有存储权限,但无法读取未定义错误的属性“本地”
问题描述
与在类似的SO帖子中添加“存储”作为权限解决了问题不同,尽管拥有存储权限,但我还是收到了错误。我不是在 chrome://extension 中收到错误,但是当我打开实时服务器并检查控制台时
背景.js:
chrome.storage.local.set({event: 'test'}, function() {
console.log('Value is set to ' + 'test');
});
内容.js
chrome.storage.local.get(['event'], function(result) {
console.log('Value currently is ' + result.key);
});
清单.json:
{
"manifest_version": 2,
"name": "To be named",
"description": "This extension helps...",
"version": "0.1.0",
"permissions": [
"storage",
"identity",
"identity.email",
"http://127.0.0.1:5000/test",
"http://127.0.0.1:5000/Time"
],
"background": {
"scripts": ["background.js"],
"persistent": false
},
"content_scripts": [{
"matches": ["https://www.youtube.com/"],
"js": ["content.js"],
"css": ["styles.css"]
}]
}
错误:
Uncaught TypeError: Cannot read property 'local' of undefined in content.js but not background in the console.
解决方案
推荐阅读
- identityserver4 - Web 应用程序中的 IdentityServer4 登录名和用户
- javascript - AJAX jQuery。从 SharePoint 列表中提取日期和时间字段。为什么它以时髦的格式显示?
- java - Spring MVC 和 Maven(404 错误:资源)
- sql - SQL查询不返回任何数据
- servlets - 如何为每个路径指定 servlet 错误页面
- c++ - 如何从 C++/WinRT 代码动画移动图像?
- python - 调整 DHT22 python 脚本的温度输出
- php - WINdows10/Chrome 中的 Jquery 自动完成功能
- javascript - 我的 JavaScript 倒数计时器无法正常工作
- javascript - React 基于三个逻辑路径渲染各种组件