使用executeScript进行代码注入时,永远不会在Chrome扩展程序中调用回调 [英] Code injection using executeScript never call callback in Chrome extension
问题描述
我正在尝试创建我要创建的Chrome扩展程序(打算在第三方网站上自动填写表格-我知道您的想法,不是垃圾邮件,不是).因此,当我尝试使用executeScript将JS注入此页面时,它永远不会调用回调函数.这是代码:
I am trying to create Chrome extension I am creating (intended to automatic fill form on third-party site - I know what you thought, not for spam, no). So when I am trying to inject JS into this page using executeScript it never calls callback function. Here is the code:
function doStepPopup () {
console.log ("Step "+step+" begins");
debugger;
var tab = curTab;
chrome.tabs.executeScript (null, {
file: "extfiller.js"
}, function () {
debugger;
console.log ("Script injected for step "+step);
.........
}
doStepPopup ();
第二个 debugger
函数和 console.log
以及所有后续代码都从不执行.有什么想法吗?提前致谢!对不起,我的英语...
Second debugger
function and console.log
and all subsequent code never executing. Any thoughts? Thanks in advance! And sorry for my English...
推荐答案
chrome.tabs.executeScript
默认情况下在
chrome.tabs.executeScript
by default injects at document_idle so it might not run on some weird pages that for whatever reason remain in "busy" state.
解决方案:使用 runAt:'document_start'
:
chrome.tabs.executeScript (null, {
file: 'extfiller.js',
runAt: 'document_start'
}, function(results) {
console.log(results);
});
这篇关于使用executeScript进行代码注入时,永远不会在Chrome扩展程序中调用回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!