I have this code:
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.query({ active: true, currentWindow: true }, tabs => {
chrome.tabs.executeScript(
tabs[0].id,
{
code: // HERE I want much more space to write
'var to_filter = document.querySelector("iframe").contentDocument.querySelector("body").querySelectorAll("tbody")[1].innerHTML; alert(to_filter);'
},
downloadFiles
);
});
});
function downloadFiles(resultsArray){
}
I have to execute a lot of code inside the code
tag, and after that, I have to send a list of links
to the downloadFiles
function. The problem is that I cannot write all the code in the code
field, I would like to use a function instead. How can I call a function to execute instead of writing only in that line?
------ Update
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.query({ active: true, currentWindow: true }, tabs => {
chrome.tabs.executeScript(
tabs[0].id,
{
code:'(${ inContent })()' // ERROR
//'var to_filter = document.querySelector("iframe").contentDocument.querySelector("body").querySelectorAll("tbody")[1].innerHTML; alert(to_filter);'
},
downloadFiles
);
function inContent() {
alert("test")
}
});
});
I get: VM138:1 Uncaught SyntaxError: Unexpected token '{'
in the commented line above.