I wrote a self-invoking function in background.js that does everything I need (subscribes to events, etc.). as soon as i add in manifest.json

"browser_action": { "default_icon": "64.png", "default_popup": "popup.html" }, 

in this case, background.js is not executed; only the popup.html output is performed without any

How to first execute the js script in the chrome extension, and then output a specific (depending on the conditions in background.js) popup.html?

  • one
    and you send the message of their main (not content) js file? - Andrew Bystrov
  • "background": {"persistent": false, "scripts": ["data / jquery.min.js", "background.js"]}, - Aliaksandr Y
  • I mean inside the script itself do you send a message? via chrome.tabs.sendMessage or chrome.runtime.sendMessage - Andrew Bystrov
  • I'm not sending anything like this, just like that chrome.browserAction.onClicked.addListener (function () {makeMagic ();}); - Aliaksandr Y

1 answer 1

Judging by your comments, you simply do not have a call to the content script.

In your content script, you subscribe to events, but you don’t send anything from basic js scripts.

Inside

 chrome.browserAction.onClicked.addListener(function () { makeMagic(); }) 

You need to send messages so that you can process them. This is done using chrome.tabs.sendMessage or chrome.runtime.sendMessage .

You can see more here: Message passing .