简体   繁体   中英

Include JS into JS for Chrome extension

How to include JS into another JS file for chrome extension?

I have these 3 files:

manifest.json

{
  "name": "Block request",
  "version": "1.0",
  "manifest_version": 2,

  "content_scripts": [{
    "matches": ["<all_urls>"],
       "js": ["content_script.js"]
}],

  "permissions": [
      "webRequest",
      "webRequestBlocking",
      "<all_urls>"
  ]
}



content_script.js

include 'myfile.js';
include 'https://sample.com/sample.js';



myfile.js (in chrome extension pack)

if (window.location.hostname === "www.sample.com") {
    console.log("Hi console");
}



sample.js (file exists in my host)

if (window.location.hostname === "www.demo.com") {
    console.log("My message from Space");
}



I know content_script.js is Not correct; I've tested some code but I didn't get any correct result.
How Can I solve this issue?

https://developer.chrome.com/extensions/content_scripts

The list of JavaScript files to be injected into matching pages. These are injected in the order they appear in this array.

"js": ["content_script.js", "myfile.js", "sample.js"]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM