I hope someone can help me.
I have a content script which shall start when the user enters my website. Then i want to send a message to the background script.
content script:
var sending = browser.runtime.sendMessage({
Call: "StartRead"
});
sending.then(handleResponse, handleError);
function handleResponse(message) {
console.log(`Message from the background script: ${message.response}`);
}
function handleError(error) {
console.log(`Error: ${error}`);
}
My background script:
function handleMessage(request, sender, sendResponse) {
console.log("+++++ Message from the content script: " + request.Call);
sendResponse({ response: "Response from background script" });
if (request.Call == "StartRead") {
Start();
}
}
browser.runtime.onMessage.addListener(handleMessage);
When I start It I get the message in handleError:
Error: Error: Could not establish connection. Receiving end does not exist.
What does this mean? What is wrong in my scripts?