I want to call a function in the chrome.tabs.executeScript that returns a string that I will be sending it in chrome.runtime.sendMessage().
code:
chrome.tabs.executeScript(tab.id, {code:var string1= ??? ;
chrome.runtime.sendMessage(string1);"});
How do I do this . My function contains Javascript code that returns a string or an array of strings.
Some help would be appreciated.
Update:
function(array_of_Tabs) {
var tab = array_of_Tabs[0];
//tab.url; - url of the active tab
chrome.tabs.executeScript(tab.id, {code: 'var test = document.body,text= test.textContent,bodyStart="<BODY",bodyEnd="</BODY>",regex=bodyStart+"(.*?)"+ bodyEnd,regexg = new RegExp(regex, "g"),match = regexg.exec(text);' + 'chrome.runtime.sendMessage(match);'});
});
chrome.runtime.onMessage.addListener(function(request) {
document.getElementsByTagName('html')[0].innerHTML = request;
});
This should've worked according to what you told me, But doesn't . Why.?
And yes BTW I am not parsing pure html on the page it may be anything say to for that matter.