Automation & Development

How to Use Proxies in Puppeteer: Launch Arguments, Authentication and Isolation

Puppeteer configures proxies through Chromium launch arguments and authenticates with page.authenticate. Learn the setup, per-identity isolation and how to debug connection failures.

ProxyGrove Editorial · · · 9 min read

Blue illustration of a Node.js script launching Chromium with a proxy server argument

TL;DR: Puppeteer sets a proxy through the --proxy-server Chromium argument at launch and supplies credentials with page.authenticate({ username, password }) before navigation. Because the argument is browser-wide, use separate browser launches (or a rotating gateway) for different exits. Verify the IP, then add timeouts, retries and clean shutdown.

How Puppeteer applies a proxy

Puppeteer drives Chrome or Chromium, so proxy configuration uses Chromium's own command-line switches. The key switch is --proxy-server, which you pass in args when launching. Credentials are not part of that argument; Chromium challenges the page for proxy authentication and Puppeteer answers with page.authenticate(). The official Page.authenticate reference and the main Puppeteer documentation cover the API.

ProxyGrove keeps a short Puppeteer integration page for its endpoints. The tutorial below stays provider-neutral and uses placeholders throughout.

Minimal working example

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch({
    headless: true,
    args: ['--proxy-server=http://YOUR_PROXY_HOST:YOUR_PROXY_PORT']
  });

  const page = await browser.newPage();
  await page.authenticate({
    username: process.env.PROXY_USER,     // YOUR_PROXY_USERNAME
    password: process.env.PROXY_PASSWORD  // YOUR_PROXY_PASSWORD
  });

  await page.goto('https://example.com/', { waitUntil: 'domcontentloaded', timeout: 45000 });
  console.log(await page.title());
  await browser.close();
})();

Call authenticate before the first navigation of each page. If you open additional pages, authenticate each one.

Choosing the proxy scheme

Argument valueResult
--proxy-server=http://host:portHTTP proxy for HTTP and HTTPS traffic
--proxy-server=socks5://host:portSOCKS5 proxy; Chromium does not support SOCKS5 username/password, so use IP allowlisting or an HTTP endpoint when credentials are needed
--proxy-bypass-list=localhost;*.internalHosts that should not use the proxy

This limitation on authenticated SOCKS5 in Chromium is a frequent surprise. If your provider's SOCKS5 endpoint requires a password, test it before building around it, or use the HTTP endpoint for browser automation.

Isolating identities

Because --proxy-server applies to the entire browser process, a single launch cannot serve two different proxies at once. You have three practical options:

  1. One browser per identity. Launch separate browsers with different arguments and user-data directories. This is the most robust and the most memory hungry.
  2. A rotating or session-aware gateway. Keep one browser and one gateway endpoint, and encode the session in the credentials you pass to page.authenticate. Pages that authenticate with different session credentials can then exit through different IPs, depending on how your provider implements sessions.
  3. A local forwarding layer. Run a small local proxy that routes each request to an upstream chosen by rule, which gives fine control but adds a component to maintain.

For cookie and storage isolation inside a browser, create a new browser context for each identity. The comparison article proxies with Playwright shows how that API differs, since Playwright supports a proxy per context directly.

Verify, then automate

  1. Navigate to an IP-echo page you trust and confirm the address differs from your direct address.
  2. Check a second page after a short wait to make sure the session behaves as expected (stable if sticky, different if rotating).
  3. Log the response status and the final URL after redirects.
  4. Run the same flow three times to find intermittent failures before you scale.

Set a default timeout with page.setDefaultNavigationTimeout() and use waitUntil: 'domcontentloaded' for pages with long-lived connections; networkidle can hang on pages that poll continuously.

Performance and cost control

Proxy traffic often costs per gigabyte, so reduce the bytes your browser downloads. Enable request interception and abort images, media and fonts when they are not needed. Reuse a single browser and open and close pages, rather than launching a browser per URL. Always close pages and browsers in a finally block so crashes do not leave orphan Chromium processes consuming memory.

await page.setRequestInterception(true);
page.on('request', req => {
  const type = req.resourceType();
  if (['image', 'media', 'font'].includes(type)) req.abort();
  else req.continue();
});

Troubleshooting guide

  • net::ERR_PROXY_CONNECTION_FAILED: verify host and port, then test the proxy with curl from the same machine.
  • net::ERR_NO_SUPPORTED_PROXIES: the scheme in --proxy-server is not supported or is malformed.
  • net::ERR_TUNNEL_CONNECTION_FAILED: the proxy refused the CONNECT; check credentials, plan status and the destination port.
  • 407 loop: the authenticate call was skipped or the credentials are wrong.

For HTTP semantics behind these codes, see the MDN pages on 407 Proxy Authentication Required and the CONNECT method.

Rotating exits without relaunching the browser

Relaunching Chromium for every request is slow and heavy. If your provider offers a session-aware gateway, you can often keep one browser and change identity by changing the credentials that you give to page.authenticate. Open a new page, authenticate with the new session string, run the task and close the page. Cookies still live in the browser's default context unless you create an isolated context, so create a fresh incognito-style context for each identity and open pages inside it.

Verify the approach with a quick experiment: run two pages with different session strings and compare the IP reported by an echo page. If both match, your provider ties the exit to the connection rather than to the credentials, and you should use separate browser launches instead. Documenting the result in your team's runbook saves the next engineer from rediscovering it.

Headless mode, versions and stability notes

Chromium's headless implementation has changed across releases, and behavior around extensions, certificates and proxies can differ between modes. Pin your Puppeteer version and the browser build it downloads, upgrade deliberately and rerun your proxy verification after each upgrade. Run a smoke test in the same environment as production, whether that is a container or a CI runner, because missing system libraries and different network rules explain many failures that never appear on a developer laptop.

Common mistakes

  • Putting username and password inside the --proxy-server value; Chromium ignores them there.
  • Authenticating one page but opening the target in another.
  • Expecting two simultaneous proxies in a single browser process.
  • Leaving headless browsers running after errors.
  • Logging environment variables that include credentials.

Frequently asked questions

How do I add proxy authentication in Puppeteer?

Call page.authenticate with your username and password before navigating. Do not place credentials in the --proxy-server argument.

Can Puppeteer use a different proxy for each tab?

Not through the launch argument, which is browser-wide. Use separate browsers, a session-aware gateway or a local forwarding layer.

Does Puppeteer support authenticated SOCKS5?

Chromium does not support SOCKS5 proxy credentials in the browser itself, so use an HTTP endpoint or an allowlisted SOCKS5 endpoint.

Why do I see ERR_TUNNEL_CONNECTION_FAILED?

The proxy could not establish the CONNECT tunnel. Check credentials, plan status, destination port and whether the proxy allows the target.

Is there a ProxyGrove page for Puppeteer?

Yes, the integrations directory has a Puppeteer page with endpoint notes.

Conclusion

Puppeteer proxies are three moving parts: the launch argument, the authentication call and the isolation strategy. Keep each explicit, verify the exit IP and shut browsers down cleanly. For provider-specific details see the ProxyGrove Puppeteer integration, or read about proxy authentication methods.

References

About the author

ProxyGrove Editorial

ProxyGrove Editorial publishes practical guides on proxy technology, automation, and responsible network workflows for international teams.

准备好找到适合您的代理方案了吗?

Explore ProxyGrove plans, then apply credentials in your tools with our Integrations guides.