I’ve done some message passing to prevent my code from executing while it is waiting for user input.
One small problem is that the listener is not being removed, so the second time, I am getting the information pasted into the text box twice.
I am probably missing something in the syntax for removeListener.
Here is my (fabulously ugly) code:
browser.menus.onClicked.addListener((info, tab, defaultMenu) => {
if (info.menuItemId.substring(0, 6) == "bbcwbx") {
for (i = 0; i < defMenu.length; i++) {
if (info.menuItemId == defMenu[i].menuId) {
var clickArg = defMenu[i].menuArg;
if (clickArg.includes("{{zzGetColor")){
let moo = browser.browserAction.openPopup();
console.log(moo);
browser.runtime.onMessage.addListener(function(message, sender) {
console.log("message received")
browser.tabs.sendMessage(tab.id, clickArg); // send argument to content script for execution
});
browser.runtime.onMessage.removeListener(function(message, sender ){});
} else {
browser.tabs.sendMessage(tab.id, clickArg); // send argument to content script for execution
}
}
}
}});
The arguments for both the add and remove listener are the same, so the remove listener should remove the add listener, but it isn’t.