For content scripts in chrome extensions, you can specify matches and exclude_matches to control what pages they are injected in. This has to be specified in the manifest of the extension like this
{
"name": "Color picker",
...
"content_scripts": [
{
"matches": ["http://*/*", "https://*/*"],
"exclude_matches": ["http://www.google.com/*"],
"css": ["color_picker.css"],
"js": ["jquery.js", "color_picker.js"]
}
],
...
}
I was wondering if I could add ["http://www.yahoo.com/*"],to exclude_matches as and when the extension is in use. This way, I can allow the user to control the exclude_matches
An extension cannot modify any local files, including the extension’s
manifest.json. Chrome offers an API for optional permissions, but this does not include Content scripts.You can manually create flexible patterns:
Regular expressions are very powerful for this purpose, though not necessary. Instead of
location.href, otherlocationproperties, such aslocation.hostcan be used.See also: MDN:
window.location.