close-window-with-last-tab=never is bypassed by chrome.tabs.remove()
OS/Platform
Windows
Installed
https://ungoogled-software.github.io/ungoogled-chromium-binaries/
Version
Version 153.0.8010.52 (Official Build, ungoogled-chromium) (64-bit)
Have you tested that this is not an upstream issue or an issue with your configuration?
- I have tried reproducing this issue in Chrome and it could not be reproduced there
- I have tried reproducing this issue in vanilla Chromium and it could not be reproduced there
- I have tried reproducing this issue in ungoogled-chromium with a new and empty profile using
--user-data-dircommand line argument and it could not be reproduced there
Description
When --close-window-with-last-tab=never is enabled, closing the only tab in a window through the extensions API chrome.tabs.remove() closes the entire window.
How to Reproduce?
- Set
chrome://flags/#close-window-with-last-tabtoNever. - Relaunch the browser.
- Open a window containing only one tab.
- Press
Ctrl+W. - Confirm that the window remains open and a new tab is created.
- Open or return to a window containing only one tab.
- From an extension with the
tabspermission, execute:
chrome.tabs.query({ active: true, currentWindow: true }, ([tab]) => {
chrome.tabs.remove(tab.id);
});Actual behaviour
When the only tab is removed through chrome.tabs.remove(), the entire browser window closes.
The same tab closed through Ctrl+W behaves as expected: the window remains open and a new tab is created.
Expected behaviour
Removing the last tab through chrome.tabs.remove() should respect --close-window-with-last-tab=never, just like closing the tab through Ctrl+W.
The window should remain open and a new tab should be created.
Relevant log output
Additional context
The current add-flag-to-close-window-with-last-tab.patch handles the behavior in TabStripModel::CloseWebContentsAt() and TabStripModel::ExecuteCloseTabs() by adding a replacement tab when closing the final tab.
chrome.tabs.remove() appears to use a different closing path. Chromium's extensions implementation ultimately removes/closes the requested WebContents, so extension-initiated removal can bypass the logic added to the TabStripModel paths covered by the patch.
This is not specific to a particular extension. I initially noticed it with the Close Tab extension:
https://chromewebstore.google.com/detail/close-tab/lnchemdcmhoccciihokpdkkekmnejfhj
but the minimal chrome.tabs.remove() example above reproduces the same behavior.
Downstream report:
Source: ungoogled-software/ungoogled-chromium