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:
| Field | What it does |
|---|---|
server | The proxy, as http://host:port. Without a scheme, http:// is assumed. socks5:// only works without a password (see the SOCKS5 section). |
username | Proxy username, including any targeting, such as USERNAME-country-us |
password | Proxy password |
bypass | Optional 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,gotojust 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
proxyexplicitly.
Playwright proxy in Python
pip install playwright
playwright install chromiumfrom 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:
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
npm i playwright
npx playwright install chromiumimport { 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 pass | Chromium 156 | Firefox 157 | WebKit 27.2 |
|---|---|---|---|
socks5:// server with username and password | Refused by Playwright | Refused by Playwright | Refused by Playwright |
socks5://user:pass@host:port as the server | ERR_SOCKS_CONNECTION_FAILED | NS_ERROR_CONNECTION_REFUSED | proxy handshake error |
socks5h:// server with username and password | ERR_NO_SUPPORTED_PROXIES | NS_ERROR_NET_RESET | proxy handshake error |
http:// port with username and password | Works | Works | Works |
What's going on:
- With the
usernameandpasswordfields, Playwright refuses before any browser starts:Browser does not support socks5 proxy authentication, fromlaunch()ornew_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:portinargsgivesERR_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:
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()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:
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:
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:
// 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:
# 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:
# 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:
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:
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:
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
| Symptom | Fix |
|---|---|
Browser does not support socks5 proxy authentication | Authenticated 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:// server | The 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 peer | An http:// server pointed at a SOCKS5 port |
| Pages show your real IP | The proxy isn't applied: pass proxy explicitly, and see the per-context note above |
TimeoutError on navigation | Raise the timeout and retry; try a broader location |
| Blocks and CAPTCHAs | See 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.



