Puppeteer 使用需要身份验证的代理

import proxyChain from "proxy-chain";
(async () => {
  const proxyServer = await proxyChain.anonymizeProxy({
    url: `http://用户名:密码@example.com`,
    port: 50505,
  });

  const browser = await puppeteer.launch({
    executablePath: "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe",
    args: [
      "--disable-setuid-sandbox",
      "--no-sandbox",
      `--proxy-server=${proxyServer}`,
      "--ignore-certificate-errors",
      "--window-size=1024,768",
    ],
    ignoreHTTPSErrors: true,
    headless: true,
  });

  const page = await browser.newPage();
  await proxyChain.closeAnonymizedProxy(proxyServer, true);
})();

主要是借助 proxy-chian​ 这个 npm 包,将代理服务器重新包装一下。