Skip to content

fix: handle proxy authentication via CDP Fetch.authRequired#1000

Merged
ctate merged 2 commits into
mainfrom
fix/proxy-auth-credentials
Mar 24, 2026
Merged

fix: handle proxy authentication via CDP Fetch.authRequired#1000
ctate merged 2 commits into
mainfrom
fix/proxy-auth-credentials

Conversation

@ctate

@ctate ctate commented Mar 24, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes #990net::ERR_INVALID_AUTH_CREDENTIALS when using an authenticated proxy.

  • Chrome's --proxy-server flag doesn't support credentials in the URL. When a proxy returns 407, Chrome had no way to respond with credentials.
  • Credentials are now extracted from the proxy URL and used to respond to CDP Fetch.authRequired events via Fetch.continueWithAuth.
  • Standard proxy env vars (HTTP_PROXY, HTTPS_PROXY, ALL_PROXY, NO_PROXY) are now recognized as fallbacks when AGENT_BROWSER_PROXY is not set.

Changes

  • flags.rs — Fall back to HTTP_PROXY/HTTPS_PROXY/ALL_PROXY/NO_PROXY env vars
  • chrome.rs — Add proxy_username/proxy_password fields to LaunchOptions
  • actions.rs — Store proxy credentials in DaemonState, handle Fetch.authRequired events in the background fetch handler, enable handleAuthRequests on all Fetch.enable calls when proxy auth is active
  • network.rs — Propagate handleAuthRequests flag through domain filter setup
  • connection.rs — Forward proxy credentials to daemon via AGENT_BROWSER_PROXY_USERNAME/AGENT_BROWSER_PROXY_PASSWORD env vars
  • main.rs — Parse proxy URL to separate server from credentials before passing to daemon
  • output.rs — Document standard proxy env var support in --help

Test plan

  • cargo fmt -- --check passes
  • cargo clippy passes (no warnings)
  • cargo test — 527 passed (2 pre-existing env-dependent failures)
  • E2E: reproduced ERR_INVALID_AUTH_CREDENTIALS with pre-fix binary using local authenticated proxy
  • E2E: verified fix resolves the issue — HTTPS navigation through authenticated proxy succeeds
  • E2E: verified HTTP_PROXY env var is now recognized
  • E2E: verified wrong credentials fail appropriately (ERR_TOO_MANY_RETRIES)
  • E2E: verified --proxy direct:// bypass still works

Chrome's --proxy-server flag does not support credentials embedded in
the URL. When a proxy requires authentication, Chrome receives a 407
from the proxy but has no way to respond with credentials, resulting
in net::ERR_INVALID_AUTH_CREDENTIALS.

Fix by:
1. Parsing credentials from the proxy URL (already done by parse_proxy)
2. Storing them in DaemonState.proxy_credentials
3. Enabling Fetch.enable with handleAuthRequests: true
4. Responding to Fetch.authRequired events with Fetch.continueWithAuth
5. Passing only the server URL (without credentials) to --proxy-server
6. Forwarding credentials to the daemon via dedicated env vars

Also adds fallback to standard proxy env vars (HTTP_PROXY, HTTPS_PROXY,
ALL_PROXY, NO_PROXY) when AGENT_BROWSER_PROXY is not set.

Fixes #990
@vercel

vercel Bot commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agent-browser Ready Ready Preview, Comment Mar 24, 2026 4:35pm
agent-browser-env-demo Ready Ready Preview, Comment Mar 24, 2026 4:35pm

…nd username-only auth

- Replace serde_json::Value return from parse_proxy with a typed ParsedProxy struct
- Fix double Fetch.enable call when both proxy auth and domain filter are active
  (the second call could overwrite handleAuthRequests from the first)
- Allow username-only proxy auth (some proxies don't require a password)
- Handle empty username/password in parse_proxy as None instead of Some("")
- Use install_domain_filter_fetch in auto_launch for consistency
- Update unit tests to use typed struct fields

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

Additional Suggestion:

Proxy authentication silently fails for CDP and auto-connect browser connections because Fetch.enable with handleAuthRequests is never called in those code paths.

Fix on Vercel

@ctate ctate merged commit cd1f255 into main Mar 24, 2026
12 checks passed
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.

Proxy error. Navigation failed: net::ERR_INVALID_AUTH_CREDENTIALS

1 participant