I am programming a Chrome add-on with Chat GPT-4, which is supposed to automate a process on a website by pressing buttons in a certain order.
But I can’t even get the add-on to run. I keep getting the error message: “background.js: No active tab found to send message to. Please navigate to a compatible website.”
Chat GPT-4 also doesn’t seem to have any further solutions and appears to be going in circles with the troubleshooting.
In chrome://discards/, I have already set the website to “X” under “Auto Discardable”.
In manifest.json, the correct permissions are set, as well as the targeted website. And in background.js, script.js, popup.js, and popup.html, Chat GPT-4 finds no problems.
Could anyone help me with this Problem?
background.js:
let isBotRunning = false;
chrome.runtime.onMessage.addListener((message, _sender, sendResponse) => {
if (message.action === "toggleBot") {
isBotRunning = !isBotRunning;
sendResponse({status: isBotRunning});
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
if (tabs.length > 0 && tabs[0].id !== undefined && tabs[0].url.startsWith("https://[removed by me.](/")) {
chrome.tabs.onUpdated.addListener(function listener(tabId, info) {
if (tabId === tabs[0].id && info.status === 'complete') {
chrome.tabs.onUpdated.removeListener(listener);
chrome.tabs.sendMessage(tabs[0].id, {action: isBotRunning ? "startBot" : "toggleBot", status: isBotRunning}).catch(error => {
console.error("Error sending message:", error);
});
}
});
} else {
console.error("No active tab found to send message to. Please navigate to a compatible website.");
}
});
} else if (message.action === "queryStatus") {
sendResponse({status: isBotRunning});
}
});
I need my add-on to recognize the website I have open and start the script on it, but there are immediate problems right at the start. I had my PC in sleep mode overnight, and in the morning, the browser tab was still open. I hadn’t changed anything, and it worked once but never again after that. I’ve already tried searching the internet for solutions and even used another add-on that sets the tabs as active. However, I can’t find a solution and really need help.