使用背景页面和内容脚本的Chrome扩展程序

JVG*_*JVG 0 javascript google-chrome oauth google-chrome-extension

我无法绕过Chrome扩展程序的结构。

我的扩展程序有两个不同的部分:

  1. 它使用后台页面通过oAuth登录,然后从oAuth整理大量数据并将其保存到chrome.storage.local

  2. 浏览网页时,它会调用来chrome.storage.local检查当前域是否与从oAuth存储的信息匹配,如果匹配,则使用[Rich Notifications 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"]
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

这样做时,我从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.
Run Code Online (Sandbox Code Playgroud)

是否可以同时进行这两个过程?如果没有,如何使用后台页面检查页面刷新并运行脚本?

Xan*_*Xan 5

您的清单是应用清单,如错误提示所提示。

要修复,请删除app“包装纸”,它只是background.scripts关键。然后它将是有效的扩展清单。


注意:chrome.notifications不适用于内容脚本;您将需要使用“ 消息传递”来请求背景页面进行显示。