Skip to content

Reopen a page in its container in the window of the tab it replaces - #2957

Open
mitar wants to merge 1 commit into
mozilla:mainfrom
mitar:tab-fix
Open

mitar wants to merge 1 commit into
mozilla:mainfrom
mitar:tab-fix

Conversation

@mitar

@mitar mitar commented Nov 9, 2026

Copy link
Copy Markdown

Before submitting your pull request

  • I agree to license my code under the MPL 2.0 license.
  • I rebased my work on top of the main branch.
  • I ran npm test and all tests passed.
  • I added test coverages if relevant.

Description

When a page assigned to a container opens in a tab of another container, onBeforeRequest() reopens it with tabs.create() and removes the tab it replaces when that tab was new. createTabWrapper() calls tabs.create() without windowId, so the new tab opens in the current window, the one which had the focus last: windowId "defaults to the current window"), while index is the position after the tab it replaces in that tab's own window. When the current window is another window than the one of the tab it replaces, this shows in two ways:

  • When the tab it replaces is removed, the page moves to the other window, and when it was the only tab of its window, that window closes. This is Tabs reopen to the wrong window, if the wrong window is the last window active. #2000. It happens for example with a link from another application, which Firefox opens in a new window (when browser.link.open_newwindow.override.external is 2), while another window still counts as the current one, as during a start of Firefox which restores the previous session: the link's window disappears, and the page appears as a tab of a restored window.
  • When the tab it replaces stays, it is passed as openerTabId, and the opener tab "must be in the same window as the newly created tab", so Firefox refuses to create the tab and the page does not open at all.

This PR passes the window of the tab it replaces to tabs.create(), through an optional windowId parameter. onBeforeRequest() removes the tab it replaces only once the new tab exists, since removing the only tab of a window closes the window. When the new tab cannot be created, the tab stays and the error is logged. The callers in messageHandler.js, which reopen the active tab from the popup, are unchanged.

The confirm page test now also checks that the new tab opens in the window of the tab it replaces, which fails without the change, and the test of the removal waits for it, since the removal now follows the creation of the new tab.

Type of change

Select all that apply.

  • Bug fix
  • New feature
  • Major change (fix or feature that would cause existing functionality to work differently than in the current version)

Tag issues related to this pull request:

The tab which reopens a page assigned to a container was created in the
window which had the focus last, at the index the tab it replaces has in
its own window, and the tab it replaces was removed at once. When that
tab was the only tab of another window, as for a link from another
application which Firefox opens in a new window, the page moved to the
window which had the focus last, and the link's window closed.

The new tab is now created in the window of the tab it replaces, and
that tab is removed only once the new one exists.

Fixes mozilla#2000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tabs reopen to the wrong window, if the wrong window is the last window active.

1 participant