Skip to content

fix: resolve stale DevToolsActivePort browser UUID via /json/version fallback#35

Open
yusuftok wants to merge 1 commit intopasky:mainfrom
yusuftok:fix/stale-devtoolsactiveport-uuid
Open

fix: resolve stale DevToolsActivePort browser UUID via /json/version fallback#35
yusuftok wants to merge 1 commit intopasky:mainfrom
yusuftok:fix/stale-devtoolsactiveport-uuid

Conversation

@yusuftok
Copy link
Copy Markdown

Summary

  • getWsUrl() reads the browser WebSocket UUID from DevToolsActivePort, but this UUID can go stale after Chrome restarts or creates a new debug session
  • When stale, all CDP commands fail with "Received network error or non-101 status code" — including list
  • This PR adds a live fallback: before using the file-based UUID, fetch the current one from http://{host}:{port}/json/version (always returns the active UUID)
  • If the HTTP fetch fails, falls back to the file-based URL as before (zero regression risk)

Root cause

Chrome writes DevToolsActivePort on startup with a browser-level WebSocket UUID. But when remote debugging is toggled or Chrome's internal debug session refreshes, a new UUID is issued without always updating the file. The HTTP endpoint /json/version always reflects the current session.

Example of the mismatch:

Source Browser UUID
DevToolsActivePort file c9af5dba-... (stale)
/json/version endpoint f0645277-... (current)

Meanwhile, per-page endpoints (/json/list) work fine — they don't depend on the browser UUID.

Changes

  • getWsUrl()async getWsUrl() — adds fetch() call to /json/version
  • 3 call sites updated: getWsUrl()await getWsUrl() (all were already in async functions using await)
  • Fallback preserved: if HTTP fetch fails, uses file-based URL as before

Test plan

  • Reproduced on macOS with Chrome 146 — cdp.mjs list failed before fix, works after
  • Verified /json/version returns the correct live UUID
  • Confirmed fallback path: if debug port is unreachable, file-based URL is still used

…fallback

The browser WebSocket UUID stored in DevToolsActivePort can become stale
after Chrome restarts or creates a new debug session, causing all CDP
commands to fail with "non-101 status code". This is because Chrome
writes a new UUID on each debug session but the file may retain the old
one.

This change makes getWsUrl() async and adds a fallback: before using the
file-based UUID, it tries to fetch the live browser WebSocket URL from
the /json/version HTTP endpoint (which always returns the current UUID).
If the HTTP fetch fails (e.g. port not open), it falls back to the
file-based URL as before.

All three call sites already use await, so the only caller change is
adding await before getWsUrl().

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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