问题
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 ();
Second debugger
function and console.log
and all subsequent code never executing. Any thoughts? Thanks in advance! And sorry for my English...
回答1:
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.
Solution: force an immediate execution with runAt: 'document_start'
:
chrome.tabs.executeScript (null, {
file: 'extfiller.js',
runAt: 'document_start'
}, function(results) {
console.log(results);
});
来源:https://stackoverflow.com/questions/42509273/code-injection-using-executescript-never-call-callback-in-chrome-extension