feat(mcp): allow creating tabs in isolated browser contexts - #43087
Pavel Feldman (pavelfeldman) merged 1 commit into
Conversation
`browser_tabs` with `action: 'new'` accepts an optional `isolatedContext` name. Tabs with the same name share cookies and storage, tabs in different contexts (or the default one) are fully isolated. The CLI exposes it as `tab-new --isolated-context=<name>`. Context keeps all browser contexts in one map, applies init scripts, origin filters and routes to each of them, and tracing and video span all contexts. Cookie, storage and network tools act on the current tab's context.
| private _browserContextPromise: Promise<playwrightTypes.BrowserContext> | undefined; | ||
| private _defaultBrowserContext: playwrightTypes.BrowserContext; | ||
| // Keyed by isolated context name, undefined for the default context. | ||
| // Resolves once the context exists and has routes, init scripts and page listeners installed. |
There was a problem hiding this comment.
drop the comment?
| this._tabs.length = 0; | ||
| this._setCurrentTab(undefined); | ||
| await this.stopVideoRecording(); | ||
| await Promise.all([...this._browserContexts].filter(([isolatedContext]) => isolatedContext).map(([, browserContext]) => browserContext.then(c => c.close()).catch(() => {}))); |
There was a problem hiding this comment.
can context name be '' ?
| async startVideoRecording(fileName: string, params: VideoParams) { | ||
| if (this._video) | ||
| throw new Error('Video recording has already been started.'); | ||
| await this.ensureBrowserContext(); |
There was a problem hiding this comment.
will it also start video for a context created later?
There was a problem hiding this comment.
Video is wired per page.
| } | ||
|
|
||
| private async _setupRequestInterception(context: playwrightTypes.BrowserContext) { | ||
| private async _setupRequestInterception(context: playwrightTypes.BrowserContext, disposables: Disposable[]) { |
There was a problem hiding this comment.
should it also add entries from this._routes ?
There was a problem hiding this comment.
yes, in _initializeBrowserContext
Test results for "tests 1"6 flaky52485 passed, 1268 skipped Merge workflow run. |
Test results for "MCP"1 failed 9014 passed, 1489 skipped Merge workflow run. |
c2a031e
into
microsoft:main
🟢 The failure is a pre-existing flakeHi, I'm the Playwright bot and I triaged the MCP failure. The same test has failed with the same session-selection assertion on unrelated PRs, so this does not look caused by this change. DetailsThis PR changes shared MCP browser-context lifecycle and therefore reaches adjacent screencast code, but the failure is an established Windows/Firefox flake rather than a new correlation with this branch. Pre-existing flake / infra
Triaged by the Playwright bot - agent run |
Summary
browser_tabsaction: 'new'takes an optionalisolatedContextname; tabs with the same name share cookies and storage, different names (or the default context) are fully isolatedtab-new <url> --isolated-context=<name>; tab list and page header show the context name