Skip to content

feat(mcp): forward noDefaults to connectOverCDP for --cdp-endpoint connections#41686

Closed
geun9716 wants to merge 1 commit into
microsoft:mainfrom
geun9716:feat/mcp-cdp-no-defaults
Closed

feat(mcp): forward noDefaults to connectOverCDP for --cdp-endpoint connections#41686
geun9716 wants to merge 1 commit into
microsoft:mainfrom
geun9716:feat/mcp-cdp-no-defaults

Conversation

@geun9716

@geun9716 geun9716 commented Jul 8, 2026

Copy link
Copy Markdown

Fixes #41661

Summary

--cdp-endpoint connections (used by both @playwright/mcp and @playwright/cli) go through createCDPBrowser() in packages/playwright-core/src/tools/mcp/browserFactory.ts, which calls chromium.connectOverCDP() but never forwards the noDefaults option added in #40185. It also isn't exposed in config.d.ts's browser section, nor as a CLI flag.

This makes it impossible to attach to CDP targets that reject Playwright's default context-management overrides (e.g. Browser.setDownloadBehavior) sent on connect — the same class of problem noDefaults was introduced to solve (#40158), also reported for other non-Chromium CDP targets (#36961, #15370).

This PR exposes noDefaults as a browser.cdpNoDefaults config field / --cdp-no-defaults CLI flag, mirroring the existing cdpEndpoint / cdpHeaders / cdpTimeout options. Since browserFactory.ts is shared, this fixes both @playwright/mcp and @playwright/cli in one change.

Changes

  • packages/playwright-core/src/tools/mcp/config.d.ts: add browser.cdpNoDefaults?: boolean field with JSDoc, documenting that it only affects the pre-existing default context (not newContext()/--isolated), per noDefaults's own design.
  • packages/playwright-core/src/tools/mcp/config.ts: add cdpNoDefaults to CLIOptions, forward it in configFromCLIOptions(), and read PLAYWRIGHT_MCP_CDP_NO_DEFAULTS in configFromEnv().
  • packages/playwright-core/src/tools/mcp/program.ts: register --cdp-no-defaults CLI flag.
  • packages/playwright-core/src/tools/mcp/configIni.ts: register browser.cdpNoDefaults as boolean in longhandTypes for INI config support.
  • packages/playwright-core/src/tools/mcp/browserFactory.ts: forward noDefaults: config.browser.cdpNoDefaults into the connectOverCDP call in createCDPBrowser.
  • tests/mcp/cdp.spec.ts: add a test that connects with --cdp-no-defaults and asserts that clicking a download link does not produce the usual "Downloading file .../Downloaded file ..." events, mirroring the existing should skip default overrides with noDefaults assertion style from tests/library/chromium/connect-over-cdp.spec.ts (no page.on('download') firing implies Browser.setDownloadBehavior was skipped on connect).

Notes

  • noDefaults only ever applies to the pre-existing default context (browser.contexts()[0]), never to contexts created via browser.newContext(). So --isolated combined with --cdp-no-defaults will still fail against targets that reject Target.createBrowserContext — that's expected, not a regression, and matches feat(connectOverCDP): add noDefaults option #40185's original design.
  • Naming: I went with cdpNoDefaults / --cdp-no-defaults to match the existing cdp* prefix convention used by cdpEndpoint/cdpHeaders/cdpTimeout. Happy to rename to plain noDefaults if maintainers prefer matching the underlying Playwright API name exactly.
  • Verified manually against a real non-Chromium CDP target (a WebKit-based embedded remote debugging endpoint) that previously failed immediately with Protocol error (Browser.setDownloadBehavior): Browser context management is not supported. — with this change and --cdp-no-defaults, the connection succeeds and MCP tools work end-to-end (non-isolated mode). Full write-up is linked from [MCP]: Expose noDefaults for --cdp-endpoint connections (also affects @playwright/cli) #41661.

Versions tested locally: @playwright/mcp@0.0.77, @playwright/cli@0.1.15, playwright-core@1.62.0-alpha-2026-06-29 (this PR is against current main, tip-of-tree).

…nnections

createCDPBrowser() calls chromium.connectOverCDP() but never forwards the
noDefaults option added in microsoft#40185, and it isn't exposed anywhere in
config.d.ts or as a CLI flag. This makes it impossible to attach
--cdp-endpoint (and playwright-cli's `attach --cdp`, which shares the same
browserFactory.ts) to CDP targets that reject Playwright's default
context-management overrides (e.g. Browser.setDownloadBehavior), since both
share this same connectOverCDP call.

Adds a browser.cdpNoDefaults config field and a matching --cdp-no-defaults
CLI flag (plus PLAYWRIGHT_MCP_CDP_NO_DEFAULTS env var and INI support),
forwarded into connectOverCDP as noDefaults. Includes a test mirroring the
existing --cdp-header coverage in tests/mcp/cdp.spec.ts.

Fixes microsoft#41661
@geun9716

geun9716 commented Jul 8, 2026

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@pavelfeldman

Copy link
Copy Markdown
Member

We are going with #41676

@geun9716

geun9716 commented Jul 8, 2026

Copy link
Copy Markdown
Author

Thanks for the quick turnaround! Looks like #41676 already covers this (and more simply — unconditionally passing noDefaults: true for CDP connections rather than adding an opt-in flag). Closing this one in favor of that PR to avoid duplicate work.

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.

[MCP]: Expose noDefaults for --cdp-endpoint connections (also affects @playwright/cli)

3 participants