about chrome.tabs.executeScript( id,details, callback)

前端 未结 1 1292
失恋的感觉
失恋的感觉 2020-11-28 08:39

This function has a callback like function(array of any result) {...};

But I don\'t know what is the result means.

For example,

         


        
相关标签:
1条回答
  • 2020-11-28 09:23

    The result of a script is the last expression being evaluated. So in your example you could use:

    chrome.tabs.executeScript( null, {code:"var x = 10; x"},
       function(results){ console.log(results); } );
    

    This will log [10] to the extension's console.

    results is actually an array of values because if the page has more than one frame you can specify that the script should be injected in each one of them and get the result of all injections. See the specification for executeScript. If you don't specify allFrames: true, then results will always be a single element array.

    0 讨论(0)
提交回复
热议问题