How to load a content script on all Google (international) pages?

北战南征 提交于 2019-12-18 04:47:07

问题


For a Google-Chrome extension, I would like to load a content script on all Google pages. What is the best way to do this?

I tried this, in the manifest.json, but it does not work:

"matches": ["http://www.google.*/*", "https://www.google.*/*"],


This "works" but it is a bit long to write and I do not think it is the best practice:

"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..."],

回答1:


See Match patterns and globs. Unfortunately, Google-Chrome doesn't have a nice mechanism for top-level-domains (TLD's) in its matches specification. So, http://www.google.*/* throws an error and http://www.google.tld/* (Greasemonkey syntax) is not supported.

To work around this, widen the matches parameter and filter the results with the include_globs parameter.
Like so:

"matches":        ["http://*/*", "https://*/*"],
"include_globs":  ["http://www.google.*/*", "https://www.google.*/*"],


来源:https://stackoverflow.com/questions/16186956/how-to-load-a-content-script-on-all-google-international-pages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!