Skip to content

fix: replace ws library with native WebSocket for CDP reliability - #29

Open
Parithosh-Varma wants to merge 1 commit into
different-ai:mainfrom
Parithosh-Varma:fix/native-websocket
Open

Parithosh-Varma wants to merge 1 commit into
different-ai:mainfrom
Parithosh-Varma:fix/native-websocket

Conversation

@Parithosh-Varma

Copy link
Copy Markdown

Problem

The bundled ws WebSocket library causes Unexpected server response: 101 errors when tools like browser_navigate, browser_click, and browser_fill try to connect to Chrome's CDP endpoint. This happens because the ws library bundled via bun build doesn't handle the WebSocket handshake correctly in all runtimes.

Fix

  • Replaced ws import with the native WebSocket API (available in Node 21+ and Bun)
  • Added connection retries (3 attempts) with backoff
  • Added a 5-second connect timeout
  • Changed readyState checks to use numeric constants instead of WebSocket.OPEN

Testing

Verified locally that browser_list, browser_navigate, browser_snapshot, browser_click, browser_fill, browser_eval, and browser_screenshot all work with Chrome started via:

/Applications/Google Chrome.app/Contents/MacOS/Google Chrome --remote-debugging-port=9222 --user-data-dir=/tmp/chrome-debug --disable-gpu --no-first-run &

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