Hi all,
I have been working on upgrading my add-on from Manifest V2 to V3. However, I have been running in a few problems.
Context: My add-on is a simple pop-up that modifies JS on the webpage that it is opened on via content scripts. The add-on works in 2 steps:
- Step 1: the scripts are all injected when the popup is opened.
- Step 2: a checkbox input is used to allow the users to remove the visual modifications that the JS scripts added to the page, or to add them back.
I successfully updated my code for step 1 to work as shown below:
async function getCurrentTabId() {
let queryOptions = {
active: true,
currentWindow: true
};
let [tab] = await browser.tabs.query(queryOptions);
return await tab.id;
}
window.onload = async () => { // https://developer.mozilla.org/en-US/docs/Web/API/Window/load_event
browser.scripting.executeScript({
target: {tabId: await getCurrentTabId()},
files: [
"/browser-polyfill.min.js",
"/content_scripts/create_total_cards_button.js",
"/content_scripts/create_avg_cards_button.js",
"/content_scripts/show_card_counters.js"
]
});
};
However, for step 2, when trying to follow the same logic for the event listener, it didnât seem to work as expected. My function was originally not an async
function, but I had to transform it to an async
one to be able to retrieve the current tab id:
document.addEventListener("click", async (e) => {
let currentTabId = await getCurrentTabId();
// Show the number of Trello card in each column.
if (e.target.checked === true) {
browser.scripting.executeScript({
target: {tabId: currentTabId},
file: "/content_scripts/show_card_counters.js"
});
}
// Hide the number of Trello card in each column.
if (e.target.checked === false) {
browser.scripting.executeScript({
target: {tabId: currentTabId},
file: "/content_scripts/hide_card_counters.js"
});
}
});
Any idea what could be going wrong? Am I tackling this problem with the wrong logic?
Also, another small problem I ran into is when executing web-ext lint
in the command line to make sure everything is fine with my add-on I get the following error:
Thanks in advance for the help!