Launch with a proxy and authenticate#
import puppeteer from "puppeteer";
const browser = await puppeteer.launch({
headless: true,
args: ["--proxy-server=http://res.proxy-cyber.com:9000", "--no-first-run"],
});
const page = await browser.newPage();
await page.authenticate({ username: "USER-cc-us-sid-run1-ttl-30m", password: "PASS" });
await page.goto("https://api.ipify.org", { waitUntil: "domcontentloaded", timeout: 45000 });
console.log(await page.evaluate(() => document.body.innerText));
await browser.close();Use a distinct session identifier for each independent workflow, where the assigned gateway supports it. Confirm the permitted duration and location parameters in your connection details. A residential device can disconnect before the requested duration; a sticky session is not a guarantee of the same IP for days. For a fixed address, compare a dedicated static product.
One proxy per browser#
The launch-level --proxy-server setting applies to that browser’s default routing. Current Puppeteer also supports proxyServer in browser.createBrowserContext(), with credentials supplied through page.authenticate(). Use separate contexts for different proxy settings and separate user-data directories for persistent profiles; verify the exit inside each context.
Block images, fonts and media#
await page.setRequestInterception(true);
page.on("request", (req) => {
const t = req.resourceType();
if (["image", "media", "font", "stylesheet"].includes(t)) return req.abort();
req.continue();
});Consistency#
- Set
Accept-Languageand the time zone to the exit's country:page.setExtraHTTPHeaders({\"Accept-Language\": \"de-DE,de;q=0.9\"})andpage.emulateTimezone(\"Europe/Berlin\"). - Disable WebRTC leaks with
--force-webrtc-ip-handling-policy=disable_non_proxied_udpin the launch args. - Keep one browser per account; reuse its user data directory if the account should look like a returning device.
Errors you will meet#
| Symptom | Cause | Fix |
|---|---|---|
| net::ERR_TUNNEL_CONNECTION_FAILED | Gateway refused the CONNECT: credentials, parameter or no exit | Reproduce with cURL -v to read the gateway code |
| net::ERR_PROXY_AUTH_UNSUPPORTED / prompts | authenticate() called after navigation | Call page.authenticate before goto |
| Same IP in every browser | Same session id reused | Use a distinct -sid- per browser or omit it |
| Very slow first load | Household exit plus heavy page | Block resources; raise timeout to 45 s |
Questions people ask#
Can Puppeteer use SOCKS5 with a password?
Chrome does not support SOCKS5 authentication. Use the HTTP proxy on port 9000 with page.authenticate, or whitelist your server IP and pass --proxy-server=socks5://res.proxy-cyber.com:9001.