Skip to content

How to use a proxy with Puppeteer

Puppeteer sets the proxy with Chrome's --proxy-server flag, or per browser context, and supplies credentials with page.authenticate(). This guide covers both, plus sticky sessions, country targeting, concurrency and what proxy errors look like in Chrome.

Updated 9 November 2026

Prerequisites

  • Node.js 22 or newer and npm i puppeteer (current releases are 25.x and download a matching Chrome for Testing).
  • A proxy login from the dashboard under Logins, written as USER and PASS.

Use it for testing from other locations, monitoring localized pages, and gathering public data that needs JavaScript to render.

Basic HTTP proxy

Pass --proxy-server at launch with the gateway address and no credentials, then call page.authenticate() before the first navigation.

javascript
import puppeteer from "puppeteer";

const browser = await puppeteer.launch({
  args: ["--proxy-server=http://gw.hyperproxy.io:8888"],
});
const page = await browser.newPage();
await page.authenticate({ username: "USER-cc-us", password: "PASS" });

await page.goto("https://api.ipify.org");
console.log(await page.evaluate(() => document.body.innerText));
await browser.close();

Authentication

Chrome ignores user:pass@ in --proxy-server, so credentials must come from page.authenticate(). It answers the proxy's 407 challenge for that page. Puppeteer turns on request interception behind the scenes to do this, which costs a little performance. Call it on every new page, including pages opened by window.open or links with target="_blank".

Chrome caches proxy credentials per browser context. Use one username per context; if pages in the same context authenticate with different usernames, you can't be sure which one a connection uses.

Rotating vs sticky sessions

The gateway gives each new connection a new exit, and Chrome opens several connections per page. Without a session, one page load can therefore come from several IPs. For browsers, put a session id in the username so the whole context shares one exit: 5 minutes by default, up to 120 with ttl.

browser.createBrowserContext({ proxyServer }) gives each context its own proxy, so one browser can run several sessions side by side. Use letters and digits only in session ids. To rotate, close the context and create a new one with a new id.

import { randomUUID } from "node:crypto";
import puppeteer from "puppeteer";

const browser = await puppeteer.launch();

async function newSession(country) {
  const session = randomUUID().replaceAll("-", "").slice(0, 12);
  const context = await browser.createBrowserContext({
    proxyServer: "http://gw.hyperproxy.io:8888",
  });
  const page = await context.newPage();
  await page.authenticate({
    username: `USER-cc-${country}-session-${session}-ttl-30`,
    password: "PASS",
  });
  return { context, page };
}

for (const country of ["us", "de", "jp"]) {
  const { context, page } = await newSession(country);
  await page.goto("https://api.ipify.org");
  console.log(country, await page.evaluate(() => document.body.innerText));
  await context.close();
}
await browser.close();

Country and city targeting

Targeting options go in the username passed to page.authenticate(). See Targeting for the full list.

UsernameExit
USER-cc-frFrance
USER-cc-us-city-new_yorkNew York
USER-cc-us-region-californiaCalifornia
USER-cc-de-os-windowsA Windows device in Germany
USER-cont-asAnywhere in Asia
USER-cc-us-city-houston-strict-falseHouston, or elsewhere in the US

If your test depends on language or time zone, set them too with page.emulateTimezone() and an Accept-Language header; the proxy only changes the IP.

SOCKS5

Chrome accepts --proxy-server=socks5://host:port but doesn't support username and password authentication for SOCKS5, and page.authenticate() only answers HTTP proxy challenges. Use the HTTP endpoint for Puppeteer. HTTPS pages are tunneled with CONNECT, so they stay encrypted end to end.

Concurrency

Run a fixed number of contexts at a time in one browser, each with its own session, and close each context when it's done. Blocking images, fonts and media saves bandwidth, which matters because all proxied traffic is metered.

javascript
const urls = Array.from({ length: 20 }, (_, i) => `https://example.com/page/${i}`);

async function worker() {
  for (let url = urls.shift(); url; url = urls.shift()) {
    const { context, page } = await newSession("us"); // from the example above
    try {
      await page.setRequestInterception(true);
      page.on("request", (req) =>
        ["image", "font", "media"].includes(req.resourceType()) ? req.abort() : req.continue(),
      );
      const res = await page.goto(url, { timeout: 60_000, waitUntil: "domcontentloaded" });
      console.log(url, res?.status());
    } finally {
      await context.close();
    }
  }
}

await Promise.all(Array.from({ length: 4 }, worker));

Error handling and retries

Chrome doesn't pass the gateway's CONNECT status to your code. page.goto() throws a net:: error instead, for example ERR_TUNNEL_CONNECTION_FAILED or ERR_INVALID_AUTH_CREDENTIALS. To see the real status, run the same username through curl with -v, then check Errors:

  • 407: wrong login, an invalid or repeated option, or no balance. Don't retry.
  • 404: no exit matches; widen the targeting or add strict-false.
  • 403: the target is not allowed.
  • 502 / 504: retry with backoff. A sticky session keeps the same exit unless it went offline.
javascript
async function gotoWithRetry(page, url, attempts = 3) {
  for (let i = 1; ; i++) {
    try {
      return await page.goto(url, { timeout: 60_000 });
    } catch (err) {
      const msg = String(err);
      if (msg.includes("ERR_INVALID_AUTH_CREDENTIALS") || i >= attempts) throw err;
      await new Promise((r) => setTimeout(r, 1000 * 2 ** i)); // 502/504-type failures
    }
  }
}

Verify the exit IP

Navigate to https://api.ipify.org and read document.body.innerText. In the sticky example both requests print the same address; contexts with different session ids print different ones.

Troubleshooting

  • ERR_INVALID_AUTH_CREDENTIALS: page.authenticate() wasn't called before goto(), or the login, password or an option is wrong.
  • ERR_NO_SUPPORTED_PROXIES: Chrome couldn't parse --proxy-server. Use the plain form http://gw.hyperproxy.io:8888, without credentials.
  • A popup or new tab isn't proxied correctly: listen for targetcreated and authenticate the new page.
  • Mixed IPs within one page: add a session option.
  • Works locally, fails in Docker: check that the container can reach gw.hyperproxy.io:8888 on TCP and that no corporate proxy is in between.

FAQ

Can I use a different proxy for each page?

Per browser context, yes, with createBrowserContext({ proxyServer }). Pages in the same context share the proxy and the cached credentials.

Do I need puppeteer-extra or a proxy-chain package?

Not for authentication. page.authenticate() handles the HTTP endpoint directly.

Is Playwright easier?

Playwright takes username and password in its proxy option, so there is no per-page call. See the Playwright guide; for HTTP-only work, an HTTP client such as axios or fetch is lighter.

Where are more examples?

See Examples.

Try it on your own workload

Sign up with GitHub or Google, create a proxy login and send your first request in a minute.

More proxy integration guides

  • Python requests — Rotating and sticky residential proxies with Python requests, including SOCKS5 and retries.
  • Python httpx — Sync and async httpx through a residential proxy with the proxy= argument and SOCKS5.
  • Python aiohttp — High-concurrency aiohttp requests through rotating or sticky residential IPs.
  • Scrapy — Route Scrapy spiders through residential proxies with request.meta and a middleware.
  • Playwright — Run Playwright through residential proxies, per browser or per context, with sticky sessions.
  • Crawlee — Map Crawlee sessions to sticky residential IPs and target countries per request.
  • Node.js axios — Send axios requests through HTTP and SOCKS5 residential proxies with proxy agents.
  • Node.js fetch & undici — Use Node's built-in fetch with undici ProxyAgent or NODE_USE_ENV_PROXY.
  • Go net/http — Configure Go's http.Transport for HTTP and SOCKS5 residential proxies.
  • curl & SOCKS5 — Use curl with HTTP and SOCKS5 proxies, and test targeting from the command line.