Skip to content

fix: improve connection reliability with retry logic and stale target handling#1177

Closed
znetstar wants to merge 1 commit intoChromeDevTools:mainfrom
znetstar:fix/connection-reliability
Closed

fix: improve connection reliability with retry logic and stale target handling#1177
znetstar wants to merge 1 commit intoChromeDevTools:mainfrom
znetstar:fix/connection-reliability

Conversation

@znetstar
Copy link
Copy Markdown

Summary

  • Retry puppeteer.connect with exponential backoff on transient failures, clearing stale browser references before reconnecting
  • Extract readDevToolsActivePort helper with I/O-only retry (validation errors fail immediately instead of waiting 5s)
  • Wrap browser.pages() with a single retry + 100ms delay to handle stale CDP targets (Target.attachToTarget errors)
  • Guard detectOpenDevToolsWindows() in the tool handler so transient failures don't break tool calls
  • Dispose previous McpContext before creating a new one to prevent resource leaks

Test plan

  • Run list_pages via MCP after Chrome restarts — should return page list instead of Protocol error (Target.attachToTarget)
  • Verify reconnection works when Chrome's debug port changes (close and reopen Chrome)
  • Confirm tools still work normally when no connection issues are present

🤖 Generated with Claude Code

… handling

Add resilience to browser connection and page enumeration:

- Retry puppeteer.connect with exponential backoff on transient failures
- Extract readDevToolsActivePort helper with I/O retry (fail fast on
  validation errors)
- Clear stale browser reference before reconnecting
- Dispose previous McpContext before creating a new one
- Wrap browser.pages() in try/catch with a single retry for stale targets
- Guard detectOpenDevToolsWindows() so failures don't break tool calls
- Catch per-page hasDevTools()/openDevTools() errors individually

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@google-cla
Copy link
Copy Markdown

google-cla Bot commented Mar 14, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@znetstar znetstar closed this Mar 16, 2026
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