如何将JS包含到另一个JS文件中以用于chrome扩展?
我有这 3 个文件:
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(在 Chrome 扩展包中)
if (window.location.hostname === "www.sample.com") {
console.log("Hi console");
}
sample.js(文件存在于我的主机中)
if (window.location.hostname === "www.demo.com") {
console.log("My message from Space");
}
我知道 content_script.js
不正确;我测试了一些代码,但没有得到任何正确的结果。
我该如何解决这个问题?
最佳答案
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"]
关于javascript - 将 JS 包含到 Chrome 扩展的 JS 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54637902/