2

I am reading Chrome.tabs.executeScript and do not known how to use the callback function of executeScript.

for example i have

function button(){
        chrome.browserAction.onClicked.addListener(function(tab) {          
            chrome.tabs.executeScript(tab.id, {file: "content_script.js", allFrames: true}, function(results){
                for(var index in results){
                    console.log(results[index]);
                }
            });
        });
    }

According to that page "result ( optional array of any ) The result of the script in every injected frame."

Is this mean the callback is fired when content_script.js had executed in all injected page and frames? And How can I return a result from my content_script.js?

Thanks.

Answer: Find the answer at here, "The result of a script is the last expression being evaluated."

Community
  • 1
  • 1
user200340
  • 3,301
  • 13
  • 52
  • 74
  • I assume you return a result by ending your script with a `return` statement. – Barmar Nov 08 '12 at 11:01
  • No, it's simply the last expression evaluated. You don't actually return anything since the code passed via `code` or `file` isn't a function. – Hengjie Mar 12 '14 at 12:12
  • 1
    possible duplicate of [about chrome.tabs.executeScript( id,details, callback)](http://stackoverflow.com/questions/13166293/about-chrome-tabs-executescript-id-details-callback) – TimothyP Jun 13 '15 at 12:47

0 Answers0