'Chrome Extension - sendMessage from any web page [duplicate]

on every page I am injecting a widget (html + javascript). Later when I click on a button, I want the widget to send a message to the extension service_worker.

to use this :

chrome.runtime.sendMessage('extension_id', { foo: 'bar' },
    function (response) {
        console.log(response);
    }
);

I need to add this in the manifest.js

"externally_connectable": {
    "matches": [
      "https://*.example.com/*"
    ]
}

But want it to work on every website, and as said here I can't use "<all_urls>".

Is there another way to comunicate with my extemsion from the widget I injected in a webpage ?

Thanks !



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source