返回博客
网络

BotBrowser 代理配置

BotBrowser 中 SOCKS5、HTTP 和 HTTPS 代理配置的完整指南,包含地理位置匹配和 Playwright 集成。

为什么代理配置很重要

仅有指纹配置不足以构成一致的浏览器身份。您的网络身份必须与指纹配置的地理设置对齐。BotBrowser 提供增强的代理支持,支持嵌入凭据,使通过 SOCKS5、HTTP 或 HTTPS 代理连接变得简单。

支持的代理类型

BotBrowser 通过 --proxy-server 标志支持三种代理协议:

  • SOCKS5: socks5://user:pass@host:port - 最适合通用场景。支持 UDP 和 DNS 代理。
  • HTTP: http://user:pass@host:port - 广泛可用。适用于大多数 Web 流量。
  • HTTPS: https://user:pass@host:port - 到代理服务器本身的加密连接。

三种格式都直接在 URL 中接受嵌入凭据。

基本代理设置

const { chromium } = require('playwright-core');

(async () => {
  const browser = await chromium.launch({
    executablePath: '/path/to/botbrowser/chrome',
    args: [
      '--bot-profile=/path/to/profile.enc',
      '--proxy-server=socks5://user:pass@proxy-host:1080',
    ],
    headless: true,
  });

  const context = await browser.newContext();
  const page = await context.newPage();
  await page.goto('https://example.com');
  await browser.close();
})();

地理位置匹配

BotBrowser 提供多个标志来使浏览器环境与代理位置对齐。

匹配时区、区域和语言

const browser = await chromium.launch({
  executablePath: '/path/to/botbrowser/chrome',
  args: [
    '--bot-profile=/path/to/profile.enc',
    '--proxy-server=socks5://user:pass@de-proxy:1080',
    '--bot-config-timezone=Europe/Berlin',
    '--bot-config-locale=de-DE',
    '--bot-config-languages=de-DE,de,en',
  ],
  headless: true,
});

浏览器的 Intl API、navigator.languageAccept-Language 头都会反映这些设置。

常用区域配置

区域时区区域设置语言
美国东部America/New_Yorken-USen-US,en
美国西部America/Los_Angelesen-USen-US,en
英国Europe/Londonen-GBen-GB,en
德国Europe/Berlinde-DEde-DE,de,en
日本Asia/Tokyoja-JPja,en
巴西America/Sao_Paulopt-BRpt-BR,pt,en

自定义 IP 检测服务

如果您运行自己的 IP 检测端点,使用 --bot-ip-service 标志:

args: [
  '--proxy-server=socks5://user:pass@proxy:1080',
  '--bot-ip-service=https://your-service.example.com/ip',
],

该服务应以纯文本返回公共 IP 地址。

验证代理配置

const page = await context.newPage();

// 检查公共 IP
await page.goto('https://httpbin.org/ip');
const ipData = await page.textContent('body');
console.log('Public IP:', ipData);

// 检查时区
const tz = await page.evaluate(() => Intl.DateTimeFormat().resolvedOptions().timeZone);
console.log('Timezone:', tz);

// 检查语言
const lang = await page.evaluate(() => navigator.language);
console.log('Language:', lang);

故障排除

代理连接超时:验证代理主机和端口是否可达。先用 curl --proxy socks5://user:pass@host:port https://httpbin.org/ip 测试。

认证失败:确保密码中的特殊字符已 URL 编码。例如,p@ss 变成 p%40ss

时区不匹配:使用完整的 IANA 格式如 America/New_York,而非缩写如 EST

DNS 泄漏:SOCKS5 代理默认处理 DNS。对于 HTTP 代理,如果关注 DNS 隐私,考虑使用 --bot-local-dns

后续步骤

#proxy#socks5#http#network#configuration