Repository navigation
window new always creates a fresh BrowserContext, so there is no way to open a second window in the current profile #2334
Replies: 1 comment
|
A data point for why a second window in the current profile matters beyond login. We run several agents against one browser with Giving each session its own window in the default context ( |
Uh oh!
There was an error while loading. Please reload this page.
Summary
window newis the only way to get a second OS-level window, and it always creates a fresh CDP BrowserContext to hold that window. The resulting window starts with an empty cookie jar, so it cannot be used for work that depends on the profile's existing logins. There is no way to ask for a window inside the context the session is already using.Why a window rather than a tab
Two separate problems are both mitigated by giving an automation its own window instead of its own tab.
First, Chromium throttles background tabs. A tab that is not the active tab in its window reports
document.visibilityState === "hidden", and the heavy SPAs we drive routinely never finish hydrating in that state, so snapshots come back against a half-rendered page. A tab that has its own window keeps reportingvisibleeven when that window is fully occluded, as long as Chrome is running with--disable-backgrounding-occluded-windows.Second, when more than one automation shares a browser, the active tab is contended (#1530). A separate window reduces how often two drivers end up pointed at the same target.
Both mitigations only help if the new window carries the profile's existing session state, because the pages being automated are sites the user is already signed into.
Current behaviour
handle_window_newincli/src/native/actions.rscallsTarget.createBrowserContextand then creates the target inside the returnedbrowserContextId. That does produce a separate window, but it is a storage-isolated one, so none of the default context's logins are present.tab newstays in the current context but produces a tab, which brings back the throttling problem above.The two properties cannot currently be combined.
tab newkeeps the session state,window newprovides the window, and neither provides both.Repro sketch
Against a headed Chrome with an existing login (any site where you are already signed in):
Expected by the caller: the page renders signed in, as it would in a normal new window of the same profile.
Actual: the page renders signed out, because the window lives in a new BrowserContext.
Expected
Some way to open a window that stays in the session's current browser context.
Possible directions
Any one of these would cover the case:
--windowflag ontab new, passingnewWindow: truetoTarget.createTargetwithout abrowserContextId. CDP supports this directly and it keeps the target in the current context.window newselecting the context behaviour, in whichever polarity you prefer as the default (--same-context, or--isolatedif the current isolation should remain default).window new, which it does not currently take, so the window can be opened straight onto the target page rather thanabout:blank.This is worth considering alongside #1068, which requests BrowserContext isolation as an opt-in flag.
window newalready performs exactly that isolation, but unconditionally and as a side effect of windowing rather than as a selectable behaviour. Splitting the two concerns apart (windowing on one axis, storage isolation on the other) would serve both requests.Environment
--cdp 9222with a second automation on the same endpoint.window newmyself, because it does not exist in 0.27.2 (we are pinned there by a Node 22 constraint). The description of its behaviour above is read frommainat 0.33.1, so please correct me if the context isolation is not what it appears to be in that code path.All reactions