Node.js Puppeteer Tunnel Proxy: Chrome Automation with Crawler Proxy

Puppeteer with 16Yun Crawler Proxy using --proxy-server launch arg and page.authenticate() for proxy auth.

16Yun Engineering TeamMay 25, 20261 min read

Puppeteer + Crawler Proxy

Puppeteer configures proxies via Chrome's --proxy-server launch argument and handles proxy authentication with page.authenticate().

Setup

export PROXY_HOST=t.16yun.cn
export PROXY_PORT=31111
export PROXY_USERNAME=your-username
export PROXY_PASSWORD=your-password

Basic Usage

const puppeteer = require('puppeteer');

const host = process.env.PROXY_HOST || 't.16yun.cn';
const port = process.env.PROXY_PORT || '31111';
const user = process.env.PROXY_USERNAME || 'user';
const pass = process.env.PROXY_PASSWORD || 'password';

(async () => {
  const browser = await puppeteer.launch({
    headless: true,
    args: [
      `--proxy-server=http://${host}:${port}`,
      '--no-sandbox',
      '--ignore-certificate-errors',
    ],
    ignoreHTTPSErrors: true,
  });

  const page = await browser.newPage();
  await page.authenticate({ username: user, password: pass });

  const resp = await page.goto('https://httpbin.org/ip', {
    waitUntil: 'domcontentloaded', timeout: 30000,
  });

  const text = await page.evaluate(() => document.body.innerText);
  console.log(resp.status(), text);

  await browser.close();
})().catch((e) => { console.error(e); process.exit(1); });

Playwright vs Puppeteer

AspectPlaywrightPuppeteer
Proxy configlaunch({ proxy: {...} })--proxy-server flag
AuthBuilt into proxy parampage.authenticate()
407 handlingAutomaticVia authenticate()
Extra flagsNone needed--ignore-certificate-errors

Request Interception for Proxy-Tunnel

await page.setRequestInterception(true);
page.on('request', (request) => {
  const headers = request.headers();
  headers['Proxy-Tunnel'] = process.env.PROXY_TUNNEL || 'puppeteer-demo';
  request.continue({ headers });
});

HTTPS Proxy-Tunnel is not supported in browser-based tools. Use HTTP clients (axios/httpx) when you need CONNECT-stage header injection.

Scenario Reference

ScenarioPuppeteerNotes
A: Force new IPRestart browserHigh overhead
B: Keep IPReuse browser/pageDefault
C-HTTP: TunnelRequest interceptionVia request.continue
C-HTTPS: Tunnel❌ Not supportedBrowser limitation

Need an enterprise proxy plan?

We can tailor architecture to your target domains, concurrency, and reliability goals.