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:
Firefox doesnât support Manifest V3 just yet, but they promised to finish till the end of the year:
So if you want to release both now, you will need separate manifest file for each browser.
Additionally you need to use âfeature detectionâ in your code to decide which script injection API to use. Something like:
Thanks for your answer! Iâve removed the await keyword from the return statement, but I am still getting errors for the 2 browser.scripting.executeScript() function calls inside the event listener.
Any idea what else could be causing this?
Iâve tried on both Firefox and Chrome and getting the same error:
Ok I see, I thought that Manifest V3 was already supported on Firefox, so I was trying to upgrade to V3 to get a single extension for both Firefox and Chrome!
Iâll just keep 2 separate versions for now then!
You need to read errors more - âunexpected property âfileââ. That should tell you that your call is not correct.
And then when you check the docs, youâll see the scripting API uses different parameters:
Sorry about that I was confused and thought the scripting API would be the same for Chrome and Firefox, as my goal was to write a single extension that would work for both browsers. Might just duplicate the extensionâs code and just make it work for Chrome separately then!
Thanks for the help though, youâve helped me learn a whole lot about cross-browser extensions and manifest V3!
If you need a change behavior in one browser and not other, use âfeature detectionâ as Iâve mentioned before, for example:
if (browser.scripting) {
// use scripting API
}
else {
// use tabs.executeScript API
}
The only issue is the manifest file, it would be best to bundle Firefox and Chrome with a separate manifest files. You can write a simple âbatchâ script that copies files and folders into some âdist_chromeâ and âdist_firefoxâ folder, each with own specific manifest file.