Developers

Integrating Proxies with Puppeteer & Playwright

The exact code to authenticate and route your headless Chrome instances through proxies.

Headless browsers like Puppeteer and Playwright are essential for scraping JavaScript-heavy sites and solving interactive challenges. Routing them through proxies takes a few lines — here's the exact setup for both.

Puppeteer with an authenticated proxy

Pass the proxy at launch, then authenticate before navigating:

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch({
    args: ['--proxy-server=http://gateway.trustproxy.io:8000'],
  });
  const page = await browser.newPage();
  await page.authenticate({ username: 'user', password: 'pass' });

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

Playwright with a proxy

Playwright takes the proxy directly in launch options, credentials included:

const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch({
    proxy: {
      server: 'http://gateway.trustproxy.io:8000',
      username: 'user',
      password: 'pass',
    },
  });
  const page = await browser.newPage();
  await page.goto('https://example.com');
  console.log(await page.title());
  await browser.close();
})();

Rotating IPs across sessions

With a rotating residential endpoint every new browser context can exit from a fresh IP automatically — just relaunch or create a new context per task. For per-account isolation instead, give each context its own static residential IP.

Tips for reliability

SOCKS5 or HTTP?

Both work with headless browsers. If you're unsure which to pick, read SOCKS5 vs HTTP proxies.

Power your headless browsers

Get residential proxies that plug straight into Puppeteer and Playwright with SOCKS5 and HTTP support.

View Residential Proxies

Related guides

Developers

How to Bypass Cloudflare and CAPTCHAs

Developers

How to Rotate Proxies for Python Web Scraping