
问了 gpt ,使用了以下两个方法都没用:
function loadScript(url) { var script = document.createElement('script'); script.src = url; script.type = 'text/Javascript'; document.head.appendChild(script); } // 调用函数加载其他 Javascript 文件 loadScript(chrome.runtime.getURL('path/to/your/other-script.js')); "content_scripts": [ { "matches": ["<all_urls>"], "js": [ "content.js", "myfunction.js" ], "type": "module" } ], myfunction.js:
function hello() { console.log("Hello World") } content.js:
hello() 1 AV1 2024-07-29 02:53:59 +08:00 content_scripts 里 js 的顺序错了,调换一下就行了 |
2 Immortal 2024-07-29 04:15:26 +08:00 应该是 1L 说的这样 题外话,现在有不少插件框架,直接用省事很多,例如 wxt |
3 skuuhui 2024-07-29 08:48:54 +08:00 manifest 中添加节点 "web_accessible_resources": [ { "matches": [ "*://你的域名/*" ], resources": [ "myfunction.js" ] } ], |
4 rookiemaster OP @DOLLOR 谢谢,已解决 |
5 rookiemaster OP @skuuhui 谢谢,已解决 |
6 rookiemaster OP @Immortal 原来还有框架,改天看看 |