feat: add --proxy flag for browser proxy configuration (#16)
* feat: add --proxy flag for browser proxy support Add CLI flag to configure HTTP/SOCKS proxy for Playwright browser context. Supports URL format with optional credentials: http://user:pass@host:port * fix: improve proxy parsing error handling - Handle malformed credentials (@ without :) by ignoring incomplete creds - Replace unwrap() with expect() for better error messages - Addresses Vercel bot code review suggestions * Restaura cambios locales: soporte AGENT_BROWSER_HOME y timeout aumentado - 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 * feat: add --proxy flag for browser proxy configuration Implements proxy support based on PR #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 #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 * refactor: simplify parse_proxy function - Remove redundant comments - Extract server variable to reduce duplication - Inline trivial username/password variables All 7 proxy tests still passing.
This commit is contained in:
+8
-3
@@ -682,6 +682,7 @@ export class BrowserManager {
|
||||
args: [`--disable-extensions-except=${extPaths}`, `--load-extension=${extPaths}`],
|
||||
viewport,
|
||||
extraHTTPHeaders: options.headers,
|
||||
...(options.proxy && { proxy: options.proxy }),
|
||||
}
|
||||
);
|
||||
this.isPersistentContext = true;
|
||||
@@ -691,10 +692,14 @@ export class BrowserManager {
|
||||
executablePath: options.executablePath,
|
||||
});
|
||||
this.cdpPort = null;
|
||||
context = await this.browser.newContext({ viewport, extraHTTPHeaders: options.headers });
|
||||
context = await this.browser.newContext({
|
||||
viewport,
|
||||
extraHTTPHeaders: options.headers,
|
||||
...(options.proxy && { proxy: options.proxy }),
|
||||
});
|
||||
}
|
||||
|
||||
context.setDefaultTimeout(10000);
|
||||
context.setDefaultTimeout(60000);
|
||||
this.contexts.push(context);
|
||||
|
||||
const page = context.pages()[0] ?? (await context.newPage());
|
||||
@@ -828,7 +833,7 @@ export class BrowserManager {
|
||||
const context = await this.browser.newContext({
|
||||
viewport: viewport ?? { width: 1280, height: 720 },
|
||||
});
|
||||
context.setDefaultTimeout(10000);
|
||||
context.setDefaultTimeout(60000);
|
||||
this.contexts.push(context);
|
||||
|
||||
const page = await context.newPage();
|
||||
|
||||
@@ -19,6 +19,17 @@ const launchSchema = baseCommandSchema.extend({
|
||||
.optional(),
|
||||
browser: z.enum(['chromium', 'firefox', 'webkit']).optional(),
|
||||
cdpPort: z.number().positive().optional(),
|
||||
executablePath: z.string().optional(),
|
||||
extensions: z.array(z.string()).optional(),
|
||||
headers: z.record(z.string()).optional(),
|
||||
proxy: z
|
||||
.object({
|
||||
server: z.string().min(1),
|
||||
bypass: z.string().optional(),
|
||||
username: z.string().optional(),
|
||||
password: z.string().optional(),
|
||||
})
|
||||
.optional(),
|
||||
});
|
||||
|
||||
const navigateSchema = baseCommandSchema.extend({
|
||||
|
||||
@@ -16,6 +16,12 @@ export interface LaunchCommand extends BaseCommand {
|
||||
executablePath?: string;
|
||||
cdpPort?: number;
|
||||
extensions?: string[];
|
||||
proxy?: {
|
||||
server: string;
|
||||
bypass?: string;
|
||||
username?: string;
|
||||
password?: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface NavigateCommand extends BaseCommand {
|
||||
|
||||
Reference in New Issue
Block a user