Skip to content

feat(mcp): allow creating tabs in isolated browser contexts - #43087

Merged
Pavel Feldman (pavelfeldman) merged 1 commit into
microsoft:mainfrom
pavelfeldman:mcp-isolated-contexts
Oct 3, 2026
Merged

Pavel Feldman (pavelfeldman) merged 1 commit into
microsoft:mainfrom
pavelfeldman:mcp-isolated-contexts

Conversation

@pavelfeldman

Copy link
Copy Markdown
Member

Summary

  • browser_tabs action: 'new' takes an optional isolatedContext name; tabs with the same name share cookies and storage, different names (or the default context) are fully isolated
  • CLI: tab-new <url> --isolated-context=<name>; tab list and page header show the context name
  • Init scripts, origin filters and routes apply to every context; tracing and video span all contexts; cookie, storage and network tools act on the current tab's context

`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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(() => {})));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will it also start video for a context created later?

@pavelfeldman Pavel Feldman (pavelfeldman) Oct 3, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Video is wired per page.

}

private async _setupRequestInterception(context: playwrightTypes.BrowserContext) {
private async _setupRequestInterception(context: playwrightTypes.BrowserContext, disposables: Disposable[]) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it also add entries from this._routes ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, in _initializeBrowserContext

@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Test results for "tests 1"

6 flaky ⚠️ [chromium-library] › library/webmcp.spec.ts:238 › should call same-name tools in their own frame `@frozen-time-library-chromium-linux`
⚠️ [chromium-library] › library/webmcp.spec.ts:256 › should list and call tools in cross-origin and nested frames `@chromium-ubuntu-22.04-node20`
⚠️ [chromium-library] › library/popup.spec.ts:260 › should not throw when click closes popup `@chromium-ubuntu-22.04-node22`
⚠️ [chromium-library] › library/video.spec.ts:762 › screencast › should work with video+trace `@chromium-ubuntu-22.04-node22`
⚠️ [firefox-library] › library/browsercontext-cookies-third-party.spec.ts:257 › third party 'Partitioned;' cookies `@firefox-ubuntu-22.04-node20`
⚠️ [firefox-library] › library/browsercontext-cookies-third-party.spec.ts:470 › top level 'Partitioned;' cookie and same origin iframe `@firefox-ubuntu-22.04-node20`

52485 passed, 1268 skipped


Merge workflow run.

@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Test results for "MCP"

1 failed
❌ [firefox] › mcp/annotate.spec.ts:446 › should switch screencast to -s session on show --annotate @mcp-windows-latest-firefox

9014 passed, 1489 skipped


Merge workflow run.

@pavelfeldman
Pavel Feldman (pavelfeldman) merged commit c2a031e into microsoft:main Oct 3, 2026
45 of 46 checks passed
@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

🟢 The failure is a pre-existing flake

Hi, 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.

Details

This 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

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.

2 participants