0

I am learning to make a chrome extension and deveoped one with a popup browser action and have the following js file (called in popup.html via )

chrome.tabs.executeScript({
    code: 
    "var frameworks = [];" +
    "if(!!window.Vue) frameworks.push('Vue.js');" +
    "if(!!window.jQuery) frameworks.push('jQuery.js');" +
    "frameworks;"
}, (frameworks) => {
    document.body.innerHTML = frameworks[0].length
})

But when I am testing it on my website made using both vue and jquery it returns 0, I also checked it on other websites but all behaved same. What am I doing wrong here?

Anmol Gautam
  • 949
  • 1
  • 12
  • 27
  • To insert code into a page, your extension must have cross-origin permissions for the page. It also must be able to use the chrome.tabs module. You can get both kinds of permission using the manifest file's permissions field – kiviak Apr 10 '18 at 21:25
  • Possible duplicate of [Use existing jQuery in Chrome extension content script?](https://stackoverflow.com/questions/36957125/use-existing-jquery-in-chrome-extension-content-script) – rsanchez Apr 10 '18 at 22:26
  • 1
    You simply need to go a level deeper and put that code string inside a `script` element to be able to [access the page context](https://stackoverflow.com/questions/9515704/insert-code-into-the-page-context-using-a-content-script). To pass the results back to the content script, you can use CustomEvent messaging, for example. – wOxxOm Apr 11 '18 at 04:47

0 Answers0