javascript 将脚本加载到 google chrome 扩展

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6938891/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 22:24:38  来源:igfitidea点击:

loading script to google chrome extension

javascriptgoogle-chrome-extension

提问by Yehonatan

I'm trying to create new extensions but I'm having a problem when I include the JavaScript:

我正在尝试创建新的扩展,但在包含 JavaScript 时遇到了问题:

 {
  "name": "<name>",
  "version": "1.0",
  "description": "<description>",
    "default_icon": "icon.png",
    "content_scripts": [
    {
      "matches": ["http://*.com"],
          "js": ["script.js"]
    }
  ],
  "permissions": [
    "http://*.com/"
  ]
}

I'm having this error:

我有这个错误:

could not load extension from <path>
Invaild value for 'content_scripts[0].matches[0]':Empty path

回答by Digital Plane

You have a invalid matchesURL - content script match patternsneed a scheme, host, and a path. The path includes the first slash /after the host (in this case, *.co.il).
Chrome is complaining that you do not have a path, so you have to add one.

您有一个无效的matchesURL 内容脚本匹配模式需要一个方案主机路径。路径包括/主机后的第一个斜杠(在本例中为*.co.il)。
Chrome 抱怨你没有路径,所以你必须添加一个。

  • If you want to match onlyhttp://*.co.il, just change it to http://*.co.il/.
  • If you want to match allpaths change it to http://*.co.il/*.
  • 如果你想匹配http://*.co.il,只是将其更改为http://*.co.il/
  • 如果要匹配所有路径,请将其更改为http://*.co.il/*.