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

后端 未结 2 1413
-上瘾入骨i
-上瘾入骨i 2021-01-16 01:27

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

相关标签:
2条回答
  • 2021-01-16 02:13

    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"]
        }
    ]
    
    0 讨论(0)
  • 2021-01-16 02:24

    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.

    0 讨论(0)
提交回复
热议问题