我无法理解 Chrome 扩展程序的结构。
我的扩展有两个不同的部分:
它使用后台页面通过oAuth登录,然后整理来自oAuth的大量数据并将其保存到
chrome.storage.local
。浏览网页时,它会调用
chrome.storage.local
来检查当前域是否与 oAuth 存储的信息匹配,如果匹配,则使用显示通知>[丰富通知 API][1]
我的 manifest.json
的结构正在破坏事物。
{
"name": "API Test",
"version": "3.1.2",
"manifest_version": 2,
"minimum_chrome_version": "29",
"app": {
"background": {
"scripts": ["main.js"]
}
},
"permissions": ["identity", "storage", "*://*/*"],
"oauth2": {
"client_id": "<<client_id>>",
"scopes": [
"https://www.googleapis.com/auth/plus.login",
"https://www.google.com/m8/feeds",
"https://www.googleapis.com/auth/contacts.readonly"
]
},
"content_scripts": [
{
"matches": ["*://*/*"],
"js": ["domchecker.js"]
}
]
}
执行此操作时,我从 Chrome 收到以下错误:
There were warnings when trying to install this extension:
'content_scripts' is only allowed for extensions and
legacy packaged apps, but this is a packaged app.
这两个过程是否可以同时进行?如果没有,如何使用后台页面检查页面刷新并运行脚本?
最佳答案
您的 list 是一个应用程序 list ,正如错误所提示的那样。
要修复此问题,请删除 app
“包装”,它应该只是 background.scripts
键。那么它将是一个有效的扩展 list 。
值得注意的是:chrome.notifications
不适用于内容脚本;您需要使用 Messaging请求您的背景页面显示它。
关于javascript - 使用后台页面 + 内容脚本的 Chrome 扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28657752/