Skip to content

Conversation

@shpeedle
Copy link
Contributor

Add CDP connection resilience and improved error handling

Summary

  • Add retry mechanism to CDP connection with configurable attempts and delay
  • Support flexible CDP endpoints (URLs or port numbers)
  • Detect whether Chrome is running to provide contextual error messages
  • Extract CDP setup logic into separate method for better code organization

Changes

Retry Logic (connectViaCDP)

  • Added retry support with configurable retries (default: 3) and retryDelayMs (default: 1000ms)
  • Smart retry behavior: skips retries for validation errors (no browser context/page) since those won't resolve with retries

Chrome Detection (isChromeRunning)

  • Cross-platform detection for Windows (tasklist) and Unix (pgrep), but I was not able to test on windows for I use Ubuntu desktop but figured it would be nice to add.
  • Specifically matches actual browser processes, excluding helper processes like crashpad handlers

Improved Error Messages

  • When connecting to localhost with Chrome running but not debuggable: explains that Chrome likely opened in an existing session without debugging enabled, and provides two solutions
  • When connecting to localhost with Chrome not running: provides the simple command to start Chrome with debugging
  • When connecting to remote URLs: provides appropriate error message for remote connections

Code Organization

  • Extracted setupCDPConnection() method to separate connection validation from retry logic
  • Added sleep() utility method

Test plan

  • Test CDP connection when Chrome is running with --remote-debugging-port
  • Test CDP connection with full WebSocket URL
  • Test error message when Chrome is running without debugging enabled
  • Test error message when Chrome is not running
  • Test error message for remote URL connection failures
  • Test retry behavior on transient connection failures

@vercel
Copy link
Contributor

vercel bot commented Jan 23, 2026

@shpeedle 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.

1 participant