I created a firefox extension which contains a content script namely with the following code:
function onGridClick(e) {
if (logToConsole) console.log("Grid icon got clicked:" + e.type);
let id = e.target.parentNode.id;
if (logToConsole) console.log("Search engine clicked:" + id);
let nav = document.getElementById("cs-grid");
nav.style.display = "none";
nav.removeEventListener("click", onGridClick);
nav.removeEventListener("mouseleave", onLeave);
nav = null;
// Get the tab position of the active tab in the current window
let tabIndex = 0;
browser.tabs.query({active:true}).then(function (tab){
if (logToConsole) console.log(tab);
tabIndex = tab.index;
sendMessage("doSearch", {"id": id, "index": tabIndex});
}, onError);
}
The complete content script may be found over at github, here.
The first two console.logs are executed without any problem, but the 3rd one after the browser.tabs.query never gets output to the console. I tried replacing browser.tabs.query with browser.tabs.getCurrent, but to no avail!
sendMessage is a function that sends a message to the background script.
Am I doing something wrong here?