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