Chrome扩展程序的内容脚本未被注入任何网页

时间:2017-09-01 05:37:42

标签: javascript jquery google-chrome google-chrome-extension

我制作了一个简单的Chrome扩展程序,其中我试图在这些特定网页中包含内容脚本。但问题是他们没有被纳入网站。我使用Chrome的开发者工具工具进行了检查。 然后我将match_urls设置为所有页面,但仍然没有包含它们。

这里是 manifest.json

{
  "manifest_version": 2,

  "name": "TestExten",
  "description": "Test description.",
  "version": "1.0",
  "browser_action": {
   "default_icon": "icon.png",
   "default_popup": "popup.html"
  },
  "content_scripts": [
    {
      "matches": ["http://*/*", "https://*/*"],
      "run_at": "document.end",
      "js": ["content.js"]
    }
  ],
  "permissions": [
    "tabs",
    "http://*/", "https://*/",
    "cookies"
  ],
}

content.js

alert("loaded");
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
     alert("received message");
});

这里出了什么问题?

1 个答案:

答案 0 :(得分:1)

看看这里:https://developer.chrome.com/extensions/content_scripts

参数run_at接受document_end,而非document.end。所以你的清单应该是这样的:

{
  "manifest_version": 2,

  "name": "TestExten",
  "description": "Test description.",
  "version": "1.0",
  "browser_action": {
   "default_icon": "icon.png",
   "default_popup": "popup.html"
  },
  "content_scripts": [
    {
      "matches": ["http://*/*", "https://*/*"],
      "run_at": "document_end",
      "js": ["content.js"]
    }
  ],
  "permissions": [
    "tabs",
    "http://*/", "https://*/",
    "cookies"
  ],
}