I've recently started developing my first Google Chrome Extension, and am experiencing an issue that I'm not entirely sure how to fix.
In my script, I'm checking if a tab is open to a specific website, and, if so, I'm performing the following code:
chrome.tabs.update(tab.id, {active: true}); // Execute code on the existing tab to open the Message. chrome.tabs.executeScript(tab.id, { "code": "messageOpen(15, false);" }); The above code should update the tab setting it as active and should then attempt to execute a function called messageOpen(). The problem I'm experiencing is that the function messageOpen() exists as a function that was included in the <HEAD> of my website, but not my extension.
Hence, when attempting to execute the messageOpen() function, I'm receiving this error:
Uncaught ReferenceError: messageOpen is not defined I'm 100% positive that the messageOpen() function works if I browse the website regularly, but when using executeScript, it's as if the extension is incapable of running functions that have already been loaded in my active tab.
Does anybody have some suggestions or alternatives?