Skip to content
Browser automation

How to use proxies with Playwright

Playwright accepts a proxy option when launching a browser or creating a context, with server, username and password fields. Setting it per context lets you run several identities with different exit IPs inside one browser process.

Recommended for Playwright

Residential proxies Playwright is normally reached for when a target has defences that break simple HTTP clients, and those same defences are the ones that reject datacenter IPs.

See residential proxies

Setup

  1. 1

    Install Playwright

    Install the package and download the browser binaries.

    # Node.js
    npm i playwright && npx playwright install
    
    # Python
    pip install playwright && playwright install
  2. 2

    Launch with a proxy

    Pass the proxy object at launch to route the whole browser through it. Replace PROXY_HOST, PROXY_PORT, USERNAME and PASSWORD with the endpoint and credentials shown in your seamless dashboard.

    const { chromium } = require("playwright");
    
    const browser = await chromium.launch({
      proxy: {
        server: "http://PROXY_HOST:PROXY_PORT",
        username: "USERNAME",
        password: "PASSWORD",
      },
    });
    
    const page = await browser.newPage();
    await page.goto("https://example.com");
  3. 3

    Use a different IP per context

    Browser contexts are isolated, so giving each one its own session identifier runs several independent identities in one browser — far cheaper than launching a browser per profile.

    const context = await browser.newContext({
      proxy: {
        server: "http://PROXY_HOST:PROXY_PORT",
        username: "USERNAME-session-a1b2c3d4",
        password: "PASSWORD",
      },
      locale: "en-GB",
      timezoneId: "Europe/London",
    });
  4. 4

    Match the fingerprint to the exit IP

    A context claiming a London timezone while exiting through a Brazilian IP is more suspicious than either signal on its own. Set locale, timezone and geolocation to match the proxy's country.

    context = browser.new_context(
        proxy={"server": "http://PROXY_HOST:PROXY_PORT",
               "username": "USERNAME", "password": "PASSWORD"},
        locale="de-DE",
        timezone_id="Europe/Berlin",
    )

Playwright proxy FAQ

How do I authenticate a proxy in Playwright?

Use the username and password fields of the proxy option rather than embedding credentials in the server URL. Playwright handles the proxy authentication challenge internally, so no dialog appears.

Can I use a different proxy per page in Playwright?

Not per page, but per context. Create a browser context for each identity with its own proxy settings; pages inside a context share that context's proxy.

Should I use headless mode with proxies?

Headless Chromium is detectable on its own, independently of the proxy. If a target blocks you in headless but not headed mode, the fingerprint is the problem rather than the IP.