0

i want to send message from Background.js to Content.js which in currently inactive or active:false in the browser.

Here is manifest.js

    {
  "manifest_version": 2,
  "browser_action":{
      "default_icon": "",
      "default_popup": "index.html"
  },
  "permissions": [
      "activeTab",
      "declarativeContent",
      "tabs", 
      "background",
      "downloads",
      "cookies",
      "<all_urls>"
  ],
  "content_scripts": [
    {
      "matches": [
        "https://someurls",
        "https://someurls"
      ],
      "js": ["jquery-3.4.1.min.js","content.js"]
    }
  ],
    "background":
    {
        "scripts": ["background.js"],
        "persistent": true
    }
}
  • The solution depends on the condition/event. If you use onUpdated event then it already has tabId parameter which you can use to send a message in chrome.tabs.sendMessage. Add more details or describe the final workflow, how and when this will be used. – wOxxOm May 06 '20 at 17:58
  • Hi, Thanks for answering. Actually i want to run the extension on the specific url and navigate to other tabs which are not related to extension so i added a script in "background.js" to send message to "content script" whenever task will done but script looks paused or freezed when i left the tab. – Asjad Waseeq May 06 '20 at 18:06
  • 1) Sites often pause themselves by listening to `pagehide` event so to prevent that from happening you would have to hack EventTarget.prototype.addEventListener and window.onpagehide in [page context](/a/9517879). 2) If you don't know the tab id to send the message then you can [send the message to all tabs](https://stackoverflow.com/a/16046641). – wOxxOm May 06 '20 at 18:13
  • Problem is solved by sending message to all tabs. Many Thanks! – Asjad Waseeq May 06 '20 at 18:23

0 Answers0