feat(mcp): forward noDefaults to connectOverCDP for --cdp-endpoint connections#41686
Closed
geun9716 wants to merge 1 commit into
Closed
feat(mcp): forward noDefaults to connectOverCDP for --cdp-endpoint connections#41686geun9716 wants to merge 1 commit into
geun9716 wants to merge 1 commit into
Conversation
…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
Author
|
@microsoft-github-policy-service agree |
Member
|
We are going with #41676 |
Author
|
Thanks for the quick turnaround! Looks like #41676 already covers this (and more simply — unconditionally passing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #41661
Summary
--cdp-endpointconnections (used by both@playwright/mcpand@playwright/cli) go throughcreateCDPBrowser()inpackages/playwright-core/src/tools/mcp/browserFactory.ts, which callschromium.connectOverCDP()but never forwards thenoDefaultsoption added in #40185. It also isn't exposed inconfig.d.ts'sbrowsersection, 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 problemnoDefaultswas introduced to solve (#40158), also reported for other non-Chromium CDP targets (#36961, #15370).This PR exposes
noDefaultsas abrowser.cdpNoDefaultsconfig field /--cdp-no-defaultsCLI flag, mirroring the existingcdpEndpoint/cdpHeaders/cdpTimeoutoptions. SincebrowserFactory.tsis shared, this fixes both@playwright/mcpand@playwright/cliin one change.Changes
packages/playwright-core/src/tools/mcp/config.d.ts: addbrowser.cdpNoDefaults?: booleanfield with JSDoc, documenting that it only affects the pre-existing default context (notnewContext()/--isolated), pernoDefaults's own design.packages/playwright-core/src/tools/mcp/config.ts: addcdpNoDefaultstoCLIOptions, forward it inconfigFromCLIOptions(), and readPLAYWRIGHT_MCP_CDP_NO_DEFAULTSinconfigFromEnv().packages/playwright-core/src/tools/mcp/program.ts: register--cdp-no-defaultsCLI flag.packages/playwright-core/src/tools/mcp/configIni.ts: registerbrowser.cdpNoDefaultsasbooleaninlonghandTypesfor INI config support.packages/playwright-core/src/tools/mcp/browserFactory.ts: forwardnoDefaults: config.browser.cdpNoDefaultsinto theconnectOverCDPcall increateCDPBrowser.tests/mcp/cdp.spec.ts: add a test that connects with--cdp-no-defaultsand asserts that clicking a download link does not produce the usual "Downloading file .../Downloaded file ..." events, mirroring the existingshould skip default overrides with noDefaultsassertion style fromtests/library/chromium/connect-over-cdp.spec.ts(nopage.on('download')firing impliesBrowser.setDownloadBehaviorwas skipped on connect).Notes
noDefaultsonly ever applies to the pre-existing default context (browser.contexts()[0]), never to contexts created viabrowser.newContext(). So--isolatedcombined with--cdp-no-defaultswill still fail against targets that rejectTarget.createBrowserContext— that's expected, not a regression, and matches feat(connectOverCDP): add noDefaults option #40185's original design.cdpNoDefaults/--cdp-no-defaultsto match the existingcdp*prefix convention used bycdpEndpoint/cdpHeaders/cdpTimeout. Happy to rename to plainnoDefaultsif maintainers prefer matching the underlying Playwright API name exactly.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 currentmain, tip-of-tree).