browser.tabs.query still has removed tab when tabs.onRemoved fires
Categories
(WebExtensions :: General, defect, P3)
Tracking
(firefox142 affected, firefox143 affected, firefox144 affected)
People
(Reporter: jannis.baum, Unassigned, Mentored)
References
Details
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:142.0) Gecko/20100101 Firefox/142.0
Steps to reproduce:
Create a directory with a manifest.json with
{
"manifest_version": 3,
"name": "broken-onRemove",
"version": "1.0",
"permissions": ["tabs"],
"background": {
"scripts": ["background.js"],
"type": "module"
}
}
and a background.js with
browser.tabs.onRemoved.addListener(async () => {
console.log("tabs.onRemoved triggered. Tabs:")
console.log(await browser.tabs.query({}));
});
Then go to (about:debugging#/runtime/this-firefox)[about:debugging#/runtime/this-firefox), click "Load Temporary Add-on" and select the manifest.json you created. Next, click "Inspect" to open the console. Open at least 2 tabs and close one.
I have tested this on Firefox 142.0.1 (both via Zen 1.15.5b and in Vanilla Firefox)
Actual results:
The browser.tabs.query will return all tabs, including the one that was removed onRemoved.
Expected results:
browser.tabs.query should have only returned the open tabs, i.e. without the one that was removed. This is how it used to be up until a recent version
Comment 1•6 months ago
|
||
The Bugbug bot thinks this bug should belong to the 'WebExtensions::Untriaged' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.
Comment 2•6 months ago
|
||
I reproduced the issue on the latest Nightly (144.0a1/20250909205747), Beta (143.0/20250908174027) and Release (142.0.1/20250827004350) under Windows 11 and Ubuntu 24.04 LTS.
As soon as I close a tab, the add-on console logs a tabs.onRemoved triggered. Tabs: followed by an array that indeed contains all tabs, including the one that was removed.
However, manually running browser.tabs.query({}) in the console will return only the open tabs.
Comment 3•6 months ago
|
||
There was a fix for this in bug 1291830, but that piece of code is no longer around.
The reason for the tab being around is because we fire tabs.onRemoved on TabClose internally, which is during _beginRemoveTab. The actual removal is a bit later if animations are involved. A more detailed write-up was posted before at https://bugzilla.mozilla.org/show_bug.cgi?id=1396758#c11
We could fix this by using a different event to dispatch tabs.onRemoved, or by somehow hiding tabs from TabTracker after the TabClose event. The downside to the latter is that information may become unavailable if an event is fired after TabClose. So I'm inclined to delay tabs.onRemoved.
Comment 4•6 months ago
|
||
The severity field is not set for this bug.
:willdurand, could you have a look please?
For more information, please visit BugBot documentation.
Updated•6 months ago
|
Description
•