Skip to content

fix(browser): bypass proxy for local CDP probes - #31312

Closed
stakeswky wants to merge 2 commits into
openclaw:mainfrom
stakeswky:fix/browser-cdp-proxy-loopback-31219
Closed

stakeswky wants to merge 2 commits into
openclaw:mainfrom
stakeswky:fix/browser-cdp-proxy-loopback-31219

Conversation

@stakeswky

Copy link
Copy Markdown
Contributor

Summary

Fixes browser startup failures when HTTP proxy env vars are set by ensuring loopback CDP health checks do not route through EnvHttpProxyAgent.

Closes #31219

Root cause

isChromeReachable() probes http://127.0.0.1:<port>/json/version via global fetch. When HTTP_PROXY / HTTPS_PROXY / ALL_PROXY is configured, undici may route this loopback probe through proxy infrastructure, causing timeout/failure even though Chrome is healthy on localhost.

Changes

  • In src/browser/chrome.ts:
    • Detect loopback CDP URLs using isLoopbackHost.
    • For loopback CDP probes only, pass an explicit undici Agent({ connect: { proxy: undefined } }) dispatcher to fetch so the request bypasses env proxy routing.
    • Preserve existing behavior for non-loopback/remote CDP URLs.
  • In src/browser/chrome.test.ts:
    • Added tests that assert loopback probes receive a dispatcher (proxy bypass path).
    • Added tests that assert remote probes do not force this dispatcher.

Validation

  • pnpm exec vitest run --config vitest.unit.config.ts src/browser/chrome.test.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2f96611632

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/browser/chrome.ts Outdated
if (!shouldBypassProxyForCdp(cdpUrl)) {
return undefined;
}
return new Agent({ connect: { proxy: undefined } });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reuse or close loopback CDP agents

Creating a new Agent for every loopback probe without ever closing it introduces avoidable connection-pool churn and lingering sockets during repeated health checks (for example the startup and shutdown polling loops that call isChromeReachable many times). This means loopback profiles can accumulate transient undici pools/file descriptors under frequent probes, which is a regression from the previous single global dispatcher path; please either reuse a shared dispatcher for loopback probes or close the per-request agent in finally.

Useful? React with 👍 / 👎.

@greptile-apps

greptile-apps Bot commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes browser startup failures when HTTP proxy environment variables are configured. The root cause was that CDP health checks to loopback addresses (127.0.0.1) were incorrectly routing through proxy infrastructure, causing timeouts even when Chrome was running locally.

Key changes:

  • Added shouldBypassProxyForCdp() to detect loopback CDP URLs using the existing isLoopbackHost utility
  • Added createLocalCdpDispatcher() to create an undici Agent with explicit proxy bypass for loopback hosts
  • Modified fetchChromeVersion() to conditionally apply the custom dispatcher only for loopback CDP probes
  • Added comprehensive test coverage for both loopback and remote CDP URL scenarios

Implementation quality:

  • Clean separation of concerns with helper functions
  • Proper error handling with try-catch for URL parsing
  • Preserves existing behavior for remote CDP URLs
  • Tests verify the dispatcher is correctly applied/omitted based on URL type

The fix is targeted, well-implemented, and directly addresses the reported issue without introducing side effects.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The implementation correctly solves the reported problem with clean, well-tested code. The fix uses existing utilities (isLoopbackHost), includes proper error handling, and has comprehensive test coverage for both code paths. No logical errors, security vulnerabilities, or breaking changes detected.
  • No files require special attention

Last reviewed commit: 2f96611

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Browser control fails when HTTP_PROXY / HTTPS_PROXY / ALL_PROXY is set (CDP probes routed through proxy)

3 participants