Currently, I have this in my background script:
function disable(tabs) {
for (var i = 0; i < tabs.length; ++i) {
browser.tabs.sendMessage(tabs[i].id, {
command: "Disable"
});
}
}
else if (e.target.classList.contains("disable")) {
browser.tabs.query({})
.then(disable)
}
I have this in my content script:
(function () {
if (window.hasRun) {
return;
}
window.hasRun = true;
function disableHelper() {
clearInterval(Interval1)
console.log("Helper has been disabled")
}
browser.runtime.onMessage.addListener((message) => {
if (message.command === "Blah") {
var Interval1 = setInterval(changeToHelper, 15000);
Interval1;
} else if (message.command === "Disable") {
disableHelper();
}
});
})();
I have permissions set to only run this on sites with specified URLs and it works when the tab is in focus/active.
However, if I click "Disable" within my popup on another tab that is not part of the permissions it won't Disable properly on the desired tab.
Is there a way to 'sendMessage' to all tabs regardless if they're in focus/active?