"Cannot attach ID to a tab in a closed window" error (or tabs.onActivated event for new tab ID) when moving multiple tabs to a different window at once
Categories
(WebExtensions :: Frontend, defect)
Tracking
(firefox149 fixed)
| Tracking | Status | |
|---|---|---|
| firefox149 | --- | fixed |
People
(Reporter: robwu, Assigned: robwu)
References
(Blocks 1 open bug)
Details
(Whiteboard: [addons-jira])
Attachments
(1 file)
|
48 bytes,
text/x-phabricator-request
|
Details |
While working on bug 2017148, I noticed an unhandled Promise rejection, "Cannot attach ID to a tab in a closed window." in the the updated browser/components/tabbrowser/test/browser/tabs/browser_replacewithwindow_splitview.js test of https://phabricator.services.mozilla.com/D283805
The scenario leading to this error is as follows:
- Create a window with two tabs, where the first tab is selected.
- Move both tabs to a another window.
- Note: the two steps above can also be done manually: select tabs (with: multi-selecting tabs with Shift, using split views, or tab groups) and then drag it to a different window. The browser console will report "Cannot attach ID to a tab in a closed window."
- Upon adapting the tab in the new window, the second tab in the old window becomes selected, which triggers TabSelect
- The second tab is meanwhile adopted in another window (still part of step 2, synchronously).
- The old window now closes because there are no tabs left.
- When the
this.maybeWaitForTabOpen(nativeTab)promise inTabSelectresolves and resumes execution,nativeTabpoints to the tab in the closed window. Its tab ID is unknown because as part of adoption we reassigned the tabId to the ID in the destination window. Consequently, we enter thesetIdlogic in an attempt to mint a new ID, which throws "Cannot attach ID to a tab in a closed window." due tonativeTabbeing in the old (closed) window.
Upon observing the error at first, I fixed the issue by returning early if nativeTab.ownerGlobal.closed is true.
But given this analysis, a better fix would be this.adoptedTabs.has(nativeTab); otherwise we would mint a tabId for an already-adopted tab and fire a tabs.onActivated event for that.
browser/components/tabbrowser/test/browser/tabs/browser_replacewithwindow_splitview.js
FAIL browser/components/tabbrowser/test/browser/tabs/browser_replacewithwindow_splitview.js - A promise chain failed to handle a rejection: Cannot attach ID to a tab in a closed window. - stack: setId@chrome://browser/content/parent/ext-browser.js:389:13
getId@chrome://browser/content/parent/ext-browser.js:365:10
emitActivated@chrome://browser/content/parent/ext-browser.js:681:19
handleEvent/<@chrome://browser/content/parent/ext-browser.js:584:16
Rejection date: Wed Feb 18 2026 23:16:42 GMT+0100 (Central European Standard Time) - false == true
resource://testing-common/PromiseTestUtils.sys.mjs:assertNoUncaughtRejections:266
chrome://mochikit/content/browser-test.js:handleTask:1334
chrome://mochikit/content/browser-test.js:_runTaskBasedTest:1392
chrome://mochikit/content/browser-test.js:Tester_execTest:1539
chrome://mochikit/content/browser-test.js:nextTest/<:1282
chrome://mochikit/content/tests/SimpleTest/SimpleTest.js:SimpleTest.waitForFocus/<:1063
FAIL browser/components/tabbrowser/test/browser/tabs/browser_replacewithwindow_splitview.js - finished in 580ms
Updated•2 months ago
|
| Assignee | ||
Comment 1•2 months ago
|
||
This bug was originally found with split views, because split views always involve moving two tabs at once.
I'm also linking bug 1972379 for visibility, since it has the same error message, and the analysis here might be helpful for debugging that other one as well.
| Assignee | ||
Comment 2•2 months ago
|
||
Comment 4•2 months ago
|
||
| bugherder | ||
Description
•