Skip to content

feat(daemon): auto-reconnect when CDP WebSocket closes#193

Open
Hexthebaldy wants to merge 1 commit intoepiral:mainfrom
Hexthebaldy:fix/cdp-auto-reconnect
Open

feat(daemon): auto-reconnect when CDP WebSocket closes#193
Hexthebaldy wants to merge 1 commit intoepiral:mainfrom
Hexthebaldy:fix/cdp-auto-reconnect

Conversation

@Hexthebaldy
Copy link
Copy Markdown

Closes #180

Problem

When Chrome closes or restarts, the CDP WebSocket drops and the daemon
permanently returns HTTP 503 for all subsequent commands. Users must
manually restart both Chrome and the daemon to recover.

Solution

Add auto-reconnect logic to CdpConnection. When the WebSocket closes
unexpectedly, the daemon retries the connection every 5 seconds until
Chrome becomes available again. Commands arriving during reconnect are
queued via waitUntilReady() instead of failing immediately.

Key changes in packages/daemon/src/cdp-connection.ts:

  • intentionalClose flag distinguishes graceful shutdown from unexpected
    disconnects — only the latter triggers reconnect
  • scheduleReconnect() clears stale session state and calls connect()
    on a fixed 5s interval
  • waitUntilReady() queues callers when a reconnect is in progress
    instead of rejecting with the last error
  • disconnect() cancels any pending reconnect timer

packages/daemon/src/http-server.ts:

  • /status endpoint exposes cdpReconnecting field

Screenshots

Chrome killed → auto-reconnect → Chrome restarted → recovered

image

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.

Daemon should auto-reconnect when CDP WebSocket closes (avoid HTTP 503 in normal restart flow)

1 participant