I want to be able to send a message from my background-script to my content-script, but wont work.
I get these errors:
Error: Incorrect argument types for tabs.sendMessage. background-script.js:27:16
Unchecked lastError value: Error: Could not establish connection. Receiving end does not exist.
Error: Error: Could not establish connection. Receiving end does not exist.
This is my code (copied from MDN):
browser.windows.onFocusChanged.addListener(event => update(event.tabId))
browser.tabs.onActivated.addListener(event => update(event.tabId))
async function update(tabId) {
browser.tabs.sendMessage(
tabId,
{greeting: "Hi from background script"}
).then(response => {
console.log("Message from the content script:");
console.log(response.response);
}).catch(onError);
function onError(error) { console.error(`Error: ${error}`) }
}