I am injecting a content script on button press using chrome.tabs.executeScript
When injecting programaticaly I can pass in as either
chrome.tabs.executeScript(null, { code: "alert('hello world');"});
or
chrome.tabs.executeScript(null, { file: example.js});
I can pass in a string or a file to execute. Is there a way to inject a function.
something like
chrome.tabs.executeScript(null, {code: function1});
function function1() { alert("hi");}
I think you can’t inject into a content script a function defined in a background page. However, you can get the function source code and make it immediately invoked.