Tutorials9 min readOct 11, 2026

Playwright proxy settings: Python, Node.js and SOCKS5

Playwright proxy settings for Python and Node.js: username and password, one IP per context, and why authenticated SOCKS5 fails in every browser.

By crawlproxies
Playwright proxy settings: Python, Node.js and SOCKS5

Playwright has proxy support built in, including the username and password that most proxy services need. This guide covers the proxy settings in Python and Node.js, one IP per browser context, why authenticated SOCKS5 doesn't work in any Playwright browser (and what to use instead), proxies in the test runners, and how to stop a headless browser from burning through your bandwidth.

Use the HTTP gateway for browsers: prem.crawlproxies.com:3621 on Residential Premium. Your credentials are in the generator. Everything here was tested with Playwright 1.64 and its Chromium 156, Firefox 157 and WebKit 27.2.

Playwright proxy settings

The proxy option is the same object in Python and Node.js:

FieldWhat it does
serverThe proxy, as http://host:port. Without a scheme, http:// is assumed. socks5:// only works without a password (see the SOCKS5 section).
usernameProxy username, including any targeting, such as USERNAME-country-us
passwordProxy password
bypassOptional comma-separated hosts that skip the proxy, such as .example.com, localhost

It goes in one of three places:

  • launch(proxy=...) applies to every page in that browser.
  • new_context(proxy=...) applies to one context and overrides the launch proxy. This is how you run several IPs in one browser.
  • launch_persistent_context(user_data_dir, proxy=...) is for a browser with a saved profile.

In Node.js the same options go to launch, newContext and launchPersistentContext.

Two gotchas:

  • Credentials go in username and password, never in the server URL. Playwright drops anything before the @ without a warning. The proxy then answers 407 and the page doesn't load; in Chromium, goto just hangs until it times out.
  • HTTPS_PROXY and other environment variables don't reach the browser. With only the variable set, our test pages loaded from the machine's own IP. Pass proxy explicitly.

Playwright proxy in Python

bash
pip install playwright
playwright install chromium
python
from playwright.sync_api import sync_playwright

PROXY = {
    "server": "http://prem.crawlproxies.com:3621",
    "username": "USERNAME-country-us",
    "password": "PASSWORD",
}

with sync_playwright() as p:
    browser = p.chromium.launch(proxy=PROXY)
    page = browser.new_page()
    page.goto("https://ipinfo.io/json")
    print(page.inner_text("body"))
    browser.close()

The same proxy works with p.firefox and p.webkit. With asyncio, use the async API:

python
import asyncio

from playwright.async_api import async_playwright

PROXY = {
    "server": "http://prem.crawlproxies.com:3621",
    "username": "USERNAME-country-us",
    "password": "PASSWORD",
}

async def main():
    async with async_playwright() as p:
        browser = await p.chromium.launch(proxy=PROXY)
        page = await browser.new_page()
        await page.goto("https://ipinfo.io/json")
        print(await page.inner_text("body"))
        await browser.close()

asyncio.run(main())

Playwright proxy in Node.js

bash
npm i playwright
npx playwright install chromium
js
import { chromium } from "playwright";

const browser = await chromium.launch({
  proxy: {
    server: "http://prem.crawlproxies.com:3621",
    username: "USERNAME-country-us",
    password: "PASSWORD",
  },
});
const page = await browser.newPage();
await page.goto("https://ipinfo.io/json");
console.log(await page.innerText("body"));
await browser.close();

Playwright with a SOCKS5 proxy

Short version: authenticated SOCKS5 doesn't work in any Playwright browser. We tested Playwright 1.64.1 against a local SOCKS5 server that asks for a username and password:

What you passChromium 156Firefox 157WebKit 27.2
socks5:// server with username and passwordRefused by PlaywrightRefused by PlaywrightRefused by Playwright
socks5://user:pass@host:port as the serverERR_SOCKS_CONNECTION_FAILEDNS_ERROR_CONNECTION_REFUSEDproxy handshake error
socks5h:// server with username and passwordERR_NO_SUPPORTED_PROXIESNS_ERROR_NET_RESETproxy handshake error
http:// port with username and passwordWorksWorksWorks

What's going on:

  • With the username and password fields, Playwright refuses before any browser starts: Browser does not support socks5 proxy authentication, from launch() or new_context(), in Python and Node.js alike.
  • With the credentials inside the URL, Playwright drops them without a warning. The browser connects without logging in, and the proxy turns it away.
  • socks5h:// isn't a way around it. Chromium rejects the scheme, Firefox talks HTTP to the SOCKS port, and WebKit still doesn't log in.
  • Chromium itself can't do SOCKS5 with a password either: passing --proxy-server=socks5://user:pass@host:port in args gives ERR_NO_SUPPORTED_PROXIES.

SOCKS5 without a password does work in all three browsers, but crawlproxies gateways log you in with a username and password, so it doesn't help here.

The fix: use the plan's HTTP port

Every crawlproxies plan with a SOCKS5 port also has an HTTP port, with the same username, password and IP pool. Point the browser at that. On Residential Private, for example, SOCKS5 is port 11000 and HTTP is port 10000:

python
from playwright.sync_api import sync_playwright

PROXY = {
    "server": "http://priv.crawlproxies.com:10000",   # Residential Private, HTTP port
    "username": "USERNAME-country-us",
    "password": "PASSWORD",
}

with sync_playwright() as p:
    browser = p.firefox.launch(proxy=PROXY)              # chromium and webkit work too
    page = browser.new_page()
    page.goto("https://ipinfo.io/json")
    print(page.inner_text("body"))
    browser.close()
js
import { webkit } from "playwright";

const browser = await webkit.launch({
  proxy: {
    server: "http://priv.crawlproxies.com:10000",
    username: "USERNAME-country-us",
    password: "PASSWORD",
  },
});
const page = await browser.newPage();
await page.goto("https://ipinfo.io/json");
console.log(await page.innerText("body"));
await browser.close();

You lose nothing by switching. The browser sends the site's hostname in its CONNECT request (we saw example.com, never an IP, from all three browsers), so DNS is resolved at the proxy end as with socks5h. HTTPS pages stay encrypted end to end.

Residential Private writes targeting its own way: a country and no city, and sticky sessions as -session-<id>-time-<seconds>, up to 2 hours. For example, USERNAME-country-us-session-acct7-time-3600.

One IP per browser context

A browser context is an isolated session: its own cookies, storage and cache. Give each context its own proxy username and you get several independent identities from one browser process:

python
from playwright.sync_api import sync_playwright

def new_identity(browser, name, country="us"):
    return browser.new_context(proxy={
        "server": "http://prem.crawlproxies.com:3621",
        "username": f"USERNAME-country-{country}-ssid-{name}-sst-3600",
        "password": "PASSWORD",
    })

with sync_playwright() as p:
    browser = p.chromium.launch()
    for name in ("alice1", "bob2", "carol3"):
        ctx = new_identity(browser, name)
        page = ctx.new_page()
        page.goto("https://ipinfo.io/ip")
        print(name, page.inner_text("body").strip())
        ctx.close()
    browser.close()

The same in Node.js:

js
import { chromium } from "playwright";

const browser = await chromium.launch();
for (const name of ["alice1", "bob2", "carol3"]) {
  const context = await browser.newContext({
    proxy: {
      server: "http://prem.crawlproxies.com:3621",
      username: `USERNAME-country-us-ssid-${name}-sst-3600`,
      password: "PASSWORD",
    },
  });
  const page = await context.newPage();
  await page.goto("https://ipinfo.io/ip");
  console.log(name, (await page.innerText("body")).trim());
  await context.close();
}
await browser.close();

Each name gets its own sticky IP for up to an hour (-sst-3600, the longest Residential Premium allows), and reusing the same name later brings that session back while it's still alive. Use letters and numbers for session ids.

On older Playwright versions Chromium ignored per-context proxies unless the browser was also launched with one. If your contexts all show your own IP, launch with a placeholder: p.chromium.launch(proxy={"server": "http://per-context"}). Every context then overrides it. On 1.64, per-context proxies worked in all three browsers without it.

Sticky for logins, rotating for crawling

  • Logging in, filling a cart, multi-step forms: use a session id (sticky). Changing IP in the middle of a login is one of the fastest ways to get flagged.
  • Visiting many unrelated pages: leave the session out and open a new context per page or per batch, so each one leaves from a fresh IP.

Sticky vs rotating sessions goes into more detail.

Proxy settings in Playwright Test and pytest

In Playwright Test (Node.js), put the proxy under use in the config, and every test's browser uses it:

ts
// playwright.config.ts
import { defineConfig } from "@playwright/test";

export default defineConfig({
  use: {
    proxy: {
      server: "http://prem.crawlproxies.com:3621",
      username: "USERNAME-country-us",
      password: "PASSWORD",
    },
  },
});

With pytest-playwright (pip install pytest-playwright), override the launch arguments in conftest.py:

python
# conftest.py
import pytest

@pytest.fixture(scope="session")
def browser_type_launch_args(browser_type_launch_args):
    return {
        **browser_type_launch_args,
        "proxy": {
            "server": "http://prem.crawlproxies.com:3621",
            "username": "USERNAME-country-us",
            "password": "PASSWORD",
        },
    }

The built-in page fixture then goes through the proxy:

python
# test_ip.py
def test_ip(page):
    page.goto("https://ipinfo.io/json")
    assert '"ip"' in page.inner_text("body")

Save bandwidth: block what you don't need

Proxy plans are billed by the gigabyte, and a modern web page loads several megabytes of images, video and fonts that a scraper never looks at. Blocking them often cuts traffic by more than half:

python
BLOCK = {"image", "media", "font"}

def block_heavy(route):
    if route.request.resource_type in BLOCK:
        return route.abort()
    return route.continue_()

page.route("**/*", block_heavy)
page.goto("https://example.com/")

The Node.js version:

js
await page.route("**/*", (route) =>
  ["image", "media", "font"].includes(route.request().resourceType())
    ? route.abort()
    : route.continue()
);

Keep stylesheets and scripts. Many sites need them to render the content you're after, and some detect clients that never load them.

Timeouts and retries

Residential exits are real home connections, so give navigation a little more room than the default and retry the occasional failure:

python
page.set_default_navigation_timeout(60_000)

for attempt in range(3):
    try:
        page.goto("https://example.com/", wait_until="domcontentloaded")
        break
    except Exception as e:
        print("retrying after", type(e).__name__)
else:
    raise RuntimeError("page did not load after 3 attempts")

wait_until="domcontentloaded" returns as soon as the HTML is parsed instead of waiting for every last request, which is faster and uses less bandwidth.

Troubleshooting

SymptomFix
Browser does not support socks5 proxy authenticationAuthenticated SOCKS5 isn't supported: use the plan's HTTP port
ERR_SOCKS_CONNECTION_FAILED, NS_ERROR_CONNECTION_REFUSED or proxy handshake error on a socks5:// serverThe credentials were in the URL and got dropped: use the HTTP port
goto times out (Chromium, WebKit) or NS_ERROR_PROXY_CONNECTION_REFUSED (Firefox)Usually a wrong username or password, or a targeting token the plan doesn't accept. Test the same login with curl, which shows the 407
ERR_PROXY_CONNECTION_FAILED (Chromium) or Could not connect to server (WebKit)Wrong host or port; use the HTTP port (3621 on Residential Premium)
ERR_EMPTY_RESPONSE, NS_ERROR_NET_RESET or Failure when receiving data from the peerAn http:// server pointed at a SOCKS5 port
Pages show your real IPThe proxy isn't applied: pass proxy explicitly, and see the per-context note above
TimeoutError on navigationRaise the timeout and retry; try a broader location
Blocks and CAPTCHAsSee the 403/429/CAPTCHA checklist

To check a login outside the browser, run curl -x http://USERNAME-country-us:PASSWORD@prem.crawlproxies.com:3621 https://ipinfo.io/json. A wrong login prints CONNECT tunnel failed, response 407.

Using Puppeteer instead? The setup is a little different: see Puppeteer with authenticated proxies.

Written by
crawlproxies
Create account