Is it possible to have two content scripts run on two separate pages?

有些话、适合烂在心里 提交于 2019-12-01 13:28:08

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.

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