So, I am making a very small extension, basically once you press a button inside the extension popup, an alert is sent (“alert(“ALERT”);”). Very simple.
The problem is that I have tried this on Youtube and couple of certain websites and they have worked, but on Twitch.tv this does not work. The extension is giving me the error:
- “Uncaught (in promise) Error: Could not establish connection. Receiving end does not exist. popup.html:0”
I have read multiple StackOverflow problems regarding this, but for myself they have not helped. What I believe the problem is that Twitch is blocking my content.js from executing. Like I said before, my extensions has worked on Youtube and multiple other sites.
Popup.js:
document.addEventListener('DOMContentLoaded', function () {
var alert_button = document.getElementById("alertbutton");
alert_button.addEventListener("click", function() {
chrome.tabs.query({ active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, { action: 'sendalerttt'})
});
});
content.js:
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if (request.action === 'sendalerttt') {
alert("LOL");
sendResponse({ message: 'Alert Sent.' });
console.log("Alert Sent")
}
});
I tried changing everything in the popup.html, but after an hour I read that its just horrible Chrome Extension error.
I have tried reading about “Chrome Extension Twitch”, this leads to Twitch API articles but these articles talk about twitch’s inner code that is used to create automated chat moderation such as Nightbot.
I have tried changing my Manifest, my current manifest is like this:
{
"manifest_version": 3,
"name": "Alert Sender",
"version": "1.0.0",
"description": "Send a simple JS Alert!",
"permissions": [
"activeTab"
],
"background": {
"service_worker": "background.js" // There is nothing in my background.js file btw
},
"action": {
"default_popup": "popup.html"
},
"content_scripts": [
{
"matches": ["*://*.twitch.tv/*"],
"js": ["content.js"]
}
]
}
Joona Neittamo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.