Closed Bug 2017768 Opened 2 months ago Closed 2 months ago

"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)

defect

Tracking

(firefox149 fixed)

RESOLVED FIXED
149 Branch
Tracking Status
firefox149 --- fixed

People

(Reporter: robwu, Assigned: robwu)

References

(Blocks 1 open bug)

Details

(Whiteboard: [addons-jira])

Attachments

(1 file)

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:

  1. Create a window with two tabs, where the first tab is selected.
  2. 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."
  3. Upon adapting the tab in the new window, the second tab in the old window becomes selected, which triggers TabSelect
  4. The second tab is meanwhile adopted in another window (still part of step 2, synchronously).
  5. The old window now closes because there are no tabs left.
  6. When the this.maybeWaitForTabOpen(nativeTab) promise in TabSelect resolves and resumes execution, nativeTab points 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 the setId logic in an attempt to mint a new ID, which throws "Cannot attach ID to a tab in a closed window." due to nativeTab being 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

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.

Blocks: 2016749
See Also: → 1972379
Status: NEW → RESOLVED
Closed: 2 months ago
Resolution: --- → FIXED
Target Milestone: --- → 149 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: