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
| Aspect | Playwright | Puppeteer |
|---|---|---|
| Proxy config | launch({ proxy: {...} }) | --proxy-server flag |
| Auth | Built into proxy param | page.authenticate() |
| 407 handling | Automatic | Via authenticate() |
| Extra flags | None 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
| Scenario | Puppeteer | Notes |
|---|---|---|
| A: Force new IP | Restart browser | High overhead |
| B: Keep IP | Reuse browser/page | Default |
| C-HTTP: Tunnel | Request interception | Via request.continue |
| C-HTTPS: Tunnel | ❌ Not supported | Browser limitation |
Need an enterprise proxy plan?
We can tailor architecture to your target domains, concurrency, and reliability goals.