我正在开发扩展程序,并在这里遇到问题。有需要时可以调用内容脚本的方法吗?找不到关于它的解决方法。
run_at: 'document_idle'
没有帮助。
编辑:run_at
在document_start
一开始启动时,document_end
加载后。内容脚本会一直自动加载,无法在需要时执行它。
您可以chrome.tabs.executeScript
在需要时调用来在网页中运行脚本。
例如:
background.js
if (needed == true) {
chrome.tabs.executeScript(tabId,{file:"myContentScript.js"},function(){
console.log("run when needed");
});
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句