get script result chrome tabs executescript

Solutions on MaxInterview for get script result chrome tabs executescript by the best coders in the world

showing results for - "get script result chrome tabs executescript"
Michele
22 Jun 2017
1chrome.browserAction.onClicked.addListener(function(tab) {
2    console.log('Injecting content script(s)');
3    //On Firefox document.body.textContent is probably more appropriate
4    chrome.tabs.executeScript(tab.id,{
5        code: 'document.body.innerText;'
6        //If you had something somewhat more complex you can use an IIFE:
7        //code: '(function (){return document.body.innerText;})();'
8        //If your code was complex, you should store it in a
9        // separate .js file, which you inject with the file: property.
10    },receiveText);
11});
12
13//tabs.executeScript() returns the results of the executed script
14//  in an array of results, one entry per frame in which the script
15//  was injected.
16function receiveText(resultsArray){
17    console.log(resultsArray[0]);
18}
19