Good day.
I have a problem sending messages from background script to content script. I try to send messages every time a user switches between browser tabs.
I get this error.
Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.
Below is the code for the extension itself.
Background Script:
chrome.tabs.onActivated.addListener(function changeTab(activeInfo) {
    var port = chrome.tabs.connect(activeInfo.tabId);
    console.log(port);
    port.postMessage({tabId: activeInfo.tabId});
});
Content Script:
chrome.runtime.onConnect.addListener(function(port) {
    console.log(11111111);
    port.onMessage.addListener(function(msg) {
        console.log(22222222);
        if(msg == undefined || Object.keys(msg).length == 0) return;
        if(msg.checkExtensionRBPopup)
            port.postMessage({active: window.localStorage.getItem('extension_rb_popup')});
    });
});
Manifest:
{
  "manifest_version": 2,
  "name": "Rebatemango Extension",
  "description": "Rebatemango",
  "version": "1.0",
  "browser_action": {
    "default_popup": "popup.html"
  },
  "content_scripts": [
    {
      "matches": [
        "<all_urls>"
      ],
      "js": [
        "content.js",
      ]
    }
  ],
  "permissions": [
    "background",
    "tabs",
    "activeTab",
    "declarativeContent",
    "storage",
    "clipboardWrite",
    "cookies",
    "tabCapture",
    "displaySource",
    "webNavigation"
  ],
  "background": {
    "scripts": [
      "js/jquery.js",
      "js/libs.js",
      "background.js"
    ],
    "persistent": false
  },
  "icons": {
    "16": "images/mango.png",
    "48": "images/mango.png",
    "128": "images/mango.png"
  }
}
Please tell me what am I doing wrong? How to fix or track this error?
 
     
    