Playwright Residential Proxy Rotation: Rotating vs Sticky Sessions

Playwright supports per-browser and per-context proxy authentication over HTTP/HTTPS and SOCKS5. To rotate IPs cleanly without relaunching Chromium on every task, launch one browser instance with a dummy proxy server and override proxy credentials per `BrowserContext`, passing distinct sticky session IDs in the proxy username.

1. Per-context proxy credentials (fastest architecture)

Launching a brand new Chromium process for every job costs 400-900 ms of CPU and RAM. Instead, pass a placeholder proxy at `chromium.launch()` (required on Windows/Linux so Chromium enables proxy routing) and set the real country and sticky session per `browser.newContext()`.

import { chromium } from "playwright";

const browser = await chromium.launch({
  proxy: { server: "http://gw.resi.fast:8080" },
});

async function runJob(jobId: string, country: string) {
  const context = await browser.newContext({
    proxy: {
      server: "http://gw.resi.fast:8080",
      username: `rf_yourkey__pool-resi_cr-${country}_sess-job${jobId}_ttl-10m`,
      password: process.env.RESI_PROXY_PASS!,
    },
  });
  const page = await context.newPage();
  await page.route("**/*", (route) => {
    const type = route.request().resourceType();
    if (["image", "font", "media"].includes(type)) return route.abort();
    return route.continue();
  });
  await page.goto("https://ipinfo.io/json");
  const text = await page.textContent("body");
  await context.close();
  return text;
}

2. Controlling bandwidth leaks in headless browsers

A single modern e-commerce page loads 3-6 MB of images, tracking pixels, and third-party ad scripts. Blocking `image`, `media`, `font`, and third-party analytics domains drops average page weight from ~4 MB to ~250 KB — extending 1 GB of residential proxy traffic from 250 pages to over 4,000 pages.

3. Isolating scrapers with sub-users and per-domain logs

Create one sub-user credential per Playwright worker pool with a hard GB cap so a runaway retry loop cannot drain your main wallet. On resi.fast, Console -> Usage breaks down exact bandwidth spent by target domain and sub-user.

FAQ

Does Playwright support SOCKS5 with username and password?

Chromium's built-in SOCKS5 stack does not support RFC 1929 username/password auth natively. Use HTTP/HTTPS CONNECT (port 8080) with Playwright, which supports full authenticated TLS tunneling cleanly.

How do I keep the same IP across 5 pages in Playwright?

Pass a sticky session flag such as `_sess-job01_ttl-15m` in the proxy username of your BrowserContext. Every request in that context exits through the same residential IP for 15 minutes.