T-3: M0.4 Purge hardcoded proxy credential + fix IB collection typo

This commit is contained in:
Studio 2026-11-27 10:55:00 -05:00
parent 36489a1e91
commit 316607b3c2
4 changed files with 159 additions and 16 deletions

View file

@ -173,22 +173,40 @@ export class Browser {
};
if (proxy) {
const [protocol, rest] = proxy.split('://');
if (!rest) {
let parsed: URL;
try {
parsed = new URL(proxy);
} catch {
throw new Error(
'Invalid proxy format. Expected protocol://host:port or protocol://user:pass@host:port'
'Invalid proxy format. Expected protocol://host[:port] or protocol://user:pass@host[:port]'
);
}
const [auth, hostPort] = rest.includes('@') ? rest.split('@') : [null, rest];
const finalHostPort = hostPort || rest;
const [host, port] = finalHostPort.split(':');
if (!parsed.hostname) {
throw new Error(
'Invalid proxy format. Expected protocol://host[:port] or protocol://user:pass@host[:port]'
);
}
contextOptions['proxy'] = {
server: `${protocol}://${host}:${port}`,
username: auth?.split(':')[0] || '',
password: auth?.split(':')[1] || '',
const decodeCredential = (value: string): string => {
try {
return decodeURIComponent(value);
} catch {
return value;
}
};
const proxyConfig: { server: string; username?: string; password?: string } = {
server: parsed.origin === 'null' ? `${parsed.protocol}//${parsed.host}` : parsed.origin,
};
if (parsed.username) {
proxyConfig.username = decodeCredential(parsed.username);
}
if (parsed.password) {
proxyConfig.password = decodeCredential(parsed.password);
}
contextOptions['proxy'] = proxyConfig;
}
const context = await this.browser.newContext(contextOptions);