I saw that questions regarding this error apeared a lot but i've tried all the suggested solutions, including disabling all of my other chrome extension, yet nothing fixed the bug. I rememered to reload the extension after each time but the same error kept coming back.
I'll mention that my code does not include a "background.js" file since I didn't find any need in one, but I might be wrong to think I don't need it, I'm pretty new to this.
my code:
popup.js
document.addEventListener("DOMContentLoaded", async () =>
{
var activate_switch = document.querySelector("input[id=activate]");
activate_switch.addEventListener('change', function()
{
if(this.checked)
{
console.log("activated");
chrome.tabs.query({active: true, currentWindow: true}, function(tabs)
{
if(tabs.length == 0)
{
console.log("could not send mesage to current tab");
}
else
{
chrome.tabs.sendMessage(tabs[0].id, {message:"run"}, function(response)
{
console.log("Hello");
});
};
});
}
});
});
content.js
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if( request.message === "run" ) {
console.log("made it");
}
}
);
manifest.json
{
"name": "First Chrome Extension",
"description": "Build an Extension!",
"version": "0.01",
"externally_connectable": {
"ids": [
"*"
]
},
"permissions": [
"tabs",
"background",
"activeTab"
],
"action": {
"default_title": "Scraper",
"default_popup": "popup.html"
},
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": [
"contentScript.js"
],
"run_at": "document_end"
}
],
"manifest_version": 3
}
it raises an error:
Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.