如何在所有Google(国际)网页上加载内容脚本?

Pau*_*nel 8 google-chrome manifest internationalization google-chrome-extension content-script

对于Google-Chrome扩展程序,我想在所有Google网页上加载内容脚本.做这个的最好方式是什么?

我试过这个,manifest.json但它不起作用:

"matches": ["http://www.google.*/*", "https://www.google.*/*"],
Run Code Online (Sandbox Code Playgroud)


这"有效"但写起来有点长,我不认为这是最好的做法:

"matches": ["http://www.google.com/*", "https://www.google.com/*", "http://www.google.fr/*", "https://www.google.fr/*", "http://www.google.de/*", "https://www.google.de/*", etc..."],
Run Code Online (Sandbox Code Playgroud)

Bro*_*ams 17

请参阅匹配模式和globs.不幸的是,Google-Chrome在其matches规范中没有一个很好的顶级域名(TLD)机制.因此,http://www.google.*/*抛出错误并且不支持http://www.google.tld/*(Greasemonkey语法).

要解决此问题,请扩展matches参数并使用参数过滤结果include_globs.
像这样:

"matches":        ["http://*/*", "https://*/*"],
"include_globs":  ["http://www.google.*/*", "https://www.google.*/*"],
Run Code Online (Sandbox Code Playgroud)

  • 这就是我要说的。“*://...”是`http` 和`https` 而不是所有协议的简写。请参阅 [文档](https://developer.chrome.com/extensions/match_patterns)。_“如果方案是 *,那么它匹配 http 或 https,而不是文件或 ftp。”_ (3认同)
  • 从技术上讲,从安全角度来看,这个答案是错误的。这就是Google首先禁止采用明显路线的原因。 (2认同)