How to Use Authenticated Proxies with Puppeteer
Chrome takes the proxy host and port as a launch flag, and Puppeteer answers the login prompt with page.authenticate.
Steps
- Launch Chrome with --proxy-server=host:port
- Call page.authenticate with your proxy username and password
- Turn on request interception to block images and fonts
- Open one browser per session id for sticky IPs
Example code
import puppeteer from "puppeteer";
const browser = await puppeteer.launch({ args: ["--proxy-server=gw.gbproxies.cc:10000"] });
const page = await browser.newPage();
await page.authenticate({ username: "USERNAME-cc-fr-sid-shop1-ttl-30", password: "PASSWORD" });
await page.setRequestInterception(true);
page.on("request", (r) => (["image", "font", "media"].includes(r.resourceType()) ? r.abort() : r.continue()));
await page.goto("https://api.ipify.org");
console.log(await page.content());
await browser.close();Replace USERNAME and PASSWORD with the proxy login from the Proxies page of the console. Port 10000 is residential HTTP; see the ports of every product below.
Tips
- Blocking images often cuts traffic per page by more than half
- A sticky session id keeps the same IP for a whole browsing flow
Common questions
Why does Chrome still show a login popup?
page.authenticate must run before the first navigation of that page.