Skip to content

Conversation

@nmwcode
Copy link
Contributor

@nmwcode nmwcode commented Jan 12, 2026

Summary

Adds a --proxy flag to route all browser traffic through a proxy server.

Changes

  • Add --proxy flag parsing in CLI (Rust)
  • Parse proxy URLs with credentials (http://user:pass@host:port)
  • Pass proxy config to Playwright's newContext()
  • Add Zod validation for proxy schema

Usage

# Simple proxy
agent-browser --proxy http://proxy.com:8080 open example.com

# With authentication
agent-browser --proxy http://user:pass@proxy.com:8080 open example.com

Supports HTTP, HTTPS, and SOCKS5 protocols.

Background

Playwright requires proxy configuration at context creation time and does not respect HTTP_PROXY/HTTPS_PROXY environment variables.

Testing

Tested with authenticated and unauthenticated proxies. Verified IP changes using httpbin.org/ip.

Add CLI flag to configure HTTP/SOCKS proxy for Playwright browser context.
Supports URL format with optional credentials: http://user:pass@host:port
@vercel
Copy link
Contributor

vercel bot commented Jan 12, 2026

@nmwcode is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

- Handle malformed credentials (@ without :) by ignoring incomplete creds
- Replace unwrap() with expect() for better error messages
- Addresses Vercel bot code review suggestions
@ctate
Copy link
Collaborator

ctate commented Jan 13, 2026

Thanks for adding proxy support - this is a useful feature!

A few things to address:

  1. Proxy parsing edge case

As the bot mentioned, username-only proxies silently drop the username:

let Some(colon_pos) = creds.find(':') else {
  // Found @ but no : in credentials - return server without credentials
  let server_part = &rest[at_pos + 1..];
  return json!({ "server": format!("{}{}", protocol, server_part) });
};

For http://username@host:port, this returns just {"server": "http://host:port"} - the username is lost. Either preserve it or return an error explaining that password is required.

  1. Missing tests

The parse_proxy() function should have unit tests covering:

  1. Missing help output

Add --proxy to the help text in cli/src/output.rs so users can discover it.

Copy link
Contributor

@vercel vercel bot left a comment

Choose a reason for hiding this comment

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

Additional Suggestions:

  1. The --proxy flag is not documented in the help output, preventing users from discovering this feature
  1. The default_flags() test helper function is missing the proxy field, causing compilation errors when tests are run because the Flags struct now requires this field to be initialized
Fix on Vercel

Integra 16 commits del repo oficial upstream incluyendo:
- Nuevas features: soporte CDP, headers custom, extensions, screencast
- Mejoras: mejor manejo de errores, documentación
- Fixes: builds, issues varios

Resuelve conflictos manteniendo compatibilidad con cambios locales.
- Agrega soporte para variable de entorno AGENT_BROWSER_HOME en connection.rs
- Aumenta timeout por defecto de 10s a 60s para conexiones más lentas
Implements proxy support based on PR vercel-labs#16 with reviewer feedback:

Features:
- Parse proxy URLs: http://[user:pass@]host:port
- Support for HTTP, HTTPS, and SOCKS5 protocols
- Handle username-only auth (preserves username with empty password)
- Apply proxy to both standard and persistent contexts

Changes:
- cli/src/flags.rs: Add proxy flag parsing
- cli/src/main.rs: Add parse_proxy() with comprehensive tests
- cli/src/output.rs: Add --proxy to help output
- cli/src/commands.rs: Fix test helper to include proxy field
- src/types.ts: Add proxy to LaunchCommand interface
- src/protocol.ts: Add proxy validation schema
- src/browser.ts: Apply proxy to context creation

Tests:
- 7 unit tests for parse_proxy() covering all edge cases
- All Rust tests passing (69 tests)
- All TypeScript tests passing (168 tests)
- TypeScript typecheck passing

Resolves feedback from PR vercel-labs#16:
- Fixed username-only proxy handling (issue #2681046975)
- Added comprehensive unit tests
- Added --proxy to help documentation
- Used expect() instead of unwrap() for better error messages
- Remove redundant comments
- Extract server variable to reduce duplication
- Inline trivial username/password variables

All 7 proxy tests still passing.
@nmwcode
Copy link
Contributor Author

nmwcode commented Jan 14, 2026

@ctate done!

@ctate
Copy link
Collaborator

ctate commented Jan 16, 2026

Pulled this down, proxy flag works as expected. Nice addition.

@ctate ctate merged commit 3675e6b into vercel-labs:main Jan 16, 2026
1 of 2 checks passed
WatermelonPan added a commit to WatermelonPan/agent-browser that referenced this pull request Jan 18, 2026
Merged upstream features:
- Video recording with Playwright native video (vercel-labs#116)
- Proxy support with --proxy flag (vercel-labs#16)
- --version flag (vercel-labs#94)
- v0.5.0 updates

Preserved our customizations:
- patchright-core via browser-engine.js abstraction
- Persistent context with launchPersistentContext
- System Chrome profile support (AGENT_BROWSER_USER_DATA_DIR)
- Navigation delay for rate limiting
- Stealth scripts
- Force headed mode for OAuth
- --channel and --bundled flags

Co-Authored-By: Claude Opus 4.5 <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.

2 participants