Skip to content

fix: prevent browser.close() from killing external Chrome via CDP#661

Open
juliobrasa wants to merge 1 commit intovercel-labs:mainfrom
juliobrasa:fix/cdp-disconnect-without-killing
Open

fix: prevent browser.close() from killing external Chrome via CDP#661
juliobrasa wants to merge 1 commit intovercel-labs:mainfrom
juliobrasa:fix/cdp-disconnect-without-killing

Conversation

@juliobrasa
Copy link

Summary

When connected via connectOverCDP(), calling browser.close() sends the CDP Browser.close command which terminates the external Chrome process. This happens both in connectViaCDP error handling and in BrowserManager.close().

Root cause

Playwright's connectOverCDP() sets _shouldCloseConnectionOnClose = false by default, meaning .close() sends the CDP kill command rather than just dropping the WebSocket.

Fix

Set _shouldCloseConnectionOnClose = true immediately after connecting via CDP. This makes .close() only drop the WebSocket connection, matching the behavior of chromium.connect().

Single line fix that protects both call sites (connectViaCDP catch block and BrowserManager.close() CDP branch).

Test plan

  • TypeScript compiles without errors
  • Connect to external Chrome via --cdp 9222, then close — Chrome stays alive
  • Connect to external Chrome via --cdp 9222 with invalid state — Chrome stays alive after error

Closes #539

🤖 Generated with Claude Code

When connected via `connectOverCDP()`, Playwright's `browser.close()`
sends the CDP `Browser.close` command which terminates the external
browser process. This happens both in the `connectViaCDP` error handler
and in `BrowserManager.close()`.

Fix: set `_shouldCloseConnectionOnClose = true` after connecting via
CDP. This makes `.close()` only drop the WebSocket connection without
sending the kill command, matching the behavior of `chromium.connect()`.

Closes vercel-labs#539

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel
Copy link
Contributor

vercel bot commented Mar 6, 2026

Someone is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

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.

CDP: browser.close() kills external Chrome when connectViaCDP validation fails

1 participant