Say I have two content scripts, codeA.js
and codeB.js
. I am wondering if it possible to run codeA.js
on http://www.example.com and hav
Note that content_scripts
is an array:
"content_scripts": [
{
"matches": ["http://www.example.com/*"],
"js": ["codeA.js"]
},
{
"matches": ["http://www.domain.com/*"],
"js": ["codeB.js"]
}
]
Make a single script file and check for the domain name like below
if(document.location == domain1){
// load script file for domain1
} else {
// load script for other domains
}
AFAIK you cannot mention different content script files for different domains in manifest.json
file.
As per the edit of your method, that code does not work. You must check it using regular expression not just ==
as your domain contains *
in between. And script Web Accessible Resources before hand.