Serj.by
Serj.by

Reputation: 604

Code injection using executeScript never call callback in Chrome extension

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...

Upvotes: 0

Views: 1636

Answers (1)

woxxom
woxxom

Reputation: 73516

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);
});

Upvotes: 1

Related Questions