2

This works perfectly in my Chrome Extension :

chrome.tabs.executeScript( null, {code:"var x = 53; x"},
function(results){ alert(results[0]); } );

However, I want to return two variables, but I don't know how to do it ..

chrome.tabs.executeScript( null, {code:"var x = 53; var y = 71; ??? x,y ???"},
function(results){ alert(results[0]); alert(results[1]); } );

Thank you in advance !

Mayusu
  • 91
  • 1
  • 2
  • 11

1 Answers1

3

You can put values into an array or a Javascript object and return it. For example:

chrome.tabs.executeScript( null, {code:"var x = [53,71]; x "},
            function(results){ alert(results); } );
Valerio
  • 110
  • 4
  • 1
    And I should use results[0][0] and results[0][1] to get the two values .. thanks ! :) – Mayusu Jan 07 '16 at 00:50
  • @Mayusu, Indeed, since this is the case why is the result even an array in the first place? Why not just an object? – Pacerier Aug 06 '17 at 03:17
  • @Pacerier as explained [here](https://stackoverflow.com/questions/13166293/about-chrome-tabs-executescript-id-details-callback), you can inject your code into all frames of current page. So, results contains all the execution results. – Valerio Dec 18 '17 at 16:47