My chrome extension has the following two javascripts:
background.js, running as background script:
chrome.runtime.onMessage.addListene
Some security changes in chrome seems like you have to take a slightly different approach when messaging between content scripts and the background script.
The calls to use are
chrome.runtime.onMessageExternal.addListener Notice the
External part.
manifest.json needs extra permissions "externally_connectable": {
"ids": ["abcdefghijklmnopqrstuvwxyzabcdef"],
"matches": ["https://example.com/*"],
"accepts_tls_channel_id": false
},
"abcdefghijklmnopqrstuvwxyzabcdef" is your extension id.
"https://example.com/*" is the domain the content script runs on.
From the content script:
chrome.runtime.sendMessage / chrome.runtime.connect with a extensionId as the first parameter.
Read more here https://developer.chrome.com/extensions/manifest/externally_connectable