I'm developing a Chrome extension and encountering an error message in the console: "Uncaught (in promise) Error: Could not establish connection. Receiving end does not exist." I'm having trouble understanding its cause and how to resolve it.
Here's the relevant code snippet from my content script:
service-worker.js
chrome.webRequest.onBeforeRequest.addListener((details) => {
chrome.runtime.sendMessage({
message: "background_to_popup",
data: details,
})
console.log(details);
}, {
urls: ['<all_urls>'],
types: ['main_frame'],
});
I'm not sure what is causing this error and how to establish the connection correctly between the content script and the background script. Any insights or suggestions would be greatly appreciated.