Playwright integration

Proxies for Playwright

Playwright takes the proxy server, username and password in one option, at launch or per browser context, so there's no separate login step. Point it at gate.proxyhat.com and every page exits through a residential or mobile IP in the country you choose: a fresh IP per connection, or one sticky IP per context.

Residential proxies
Code tested on our gateway Node.js and Python Traffic never expires

What teams run Playwright through proxies for

Public data collection

Load public pages, such as prices, listings and search results, the way a visitor in that country sees them.

Localization and ad checks

Check that geo-targeted pages, translations and ads render correctly in each market, from a residential or mobile connection there.

Testing from outside your network

Run your Playwright end-to-end tests as an outside visitor in another country: geo-redirects, CDN rules, consent banners and checkout by market.

Connection details

Hostgate.proxyhat.com
SOCKS5 port1080
HTTP port8080
AuthenticationUsername and password from the Proxies page of your dashboard
Username for one browserUSERNAME-country-US-sid-a3f8c20d1e-ttl-30m

Everything after your username is a flag: -country-US picks the exit country, -type-mobile the mobile carrier pool, -sid-… keeps one IP and -ttl-30m sets for how long (up to 24 hours). Leave out -type-mobile for residential IPs.

Need another proxy format? Proxy format converter →

Playwright proxy code

Replace USERNAME and PASSWORD with the proxy credentials from the Proxies page of your dashboard. Node.js: npm install playwright, npx playwright install chromium, then save the sample as an .mjs file. Python: pip install playwright, then playwright install chromium.

import { chromium } from 'playwright';

// Playwright takes the proxy address and its login in one launch option.
// No -sid-: every new connection can exit from a new IP.
const browser = await chromium.launch({
  proxy: {
    server: 'http://gate.proxyhat.com:8080',
    username: 'USERNAME-country-US',
    password: 'PASSWORD',
  },
});
const page = await browser.newPage();
await page.goto('https://httpbin.org/ip');
console.log(await page.locator('body').innerText());
await browser.close();

The proxy option carries the address and the login together, and Playwright answers the gateway's login challenge itself. Without -sid- in the username, every new connection can get a new IP.

Tested on November 29, 2026 against gate.proxyhat.com with Playwright 1.65.1 for Node.js and 1.65.2 for Python, Chromium 159: the rotating sample printed a US IP, each sticky sample three different US IPs.

Checked against: Playwright: HTTP proxy, Playwright: Browser.newContext, Playwright for Python: HTTP proxy · checked November 29, 2026

Managing proxies from code? The ProxyHat SDK for Python, Node.js and Go creates sub-users with their own traffic limits, lists locations and reads usage; the proxy connection itself stays as above. SDK docs →

Rotating, sticky or no rotation

The session type is part of the username. Your code stays the same; only the login string changes.

Rotating

No session ID: each new connection can exit from a different IP. Good for many independent page loads.

USERNAME-country-US

Sticky

Add -sid- with 10 random hex characters and a -ttl-: the IP holds for that long (10m, 30m, 1h, up to 24h). Use it for multi-page flows that should stay on one address.

USERNAME-country-US-sid-a3f8c20d1e-ttl-30m

No rotation

Add -sid- with -norotate-true and no -ttl-: the IP doesn’t rotate on a timer and stays until you switch to a new sid.

USERNAME-country-US-sid-a3f8c20d1e-norotate-true

One sid holds one exit IP and handles about 4–5 connections at a time, so give every worker or browser its own sid. Sticky sessions last up to 24 hours. Add -type-mobile for 4G/5G carrier IPs; leave it out for residential.

Proxy errors and what they mean

407 Proxy Authentication RequiredThe gateway didn’t accept the login: the username or password is wrong, or the username format is (a typo in a flag such as -country-US). Copy both from the Proxies page of your dashboard and make sure the auth step runs before the first page load.
402 Payment RequiredThe traffic balance is used up, or the sub-user has reached its traffic limit. Top up or raise the limit in the dashboard; traffic you buy never expires.
ERR_TUNNEL_CONNECTION_FAILEDChrome’s name for a proxy that refused the connection, and it can hide a 402 or another gateway status. Send the same username and password through curl -x http://gate.proxyhat.com:8080 to see the real code.
ERR_PROXY_CONNECTION_FAILEDChrome couldn’t reach the gateway at all. Check the host and port (gate.proxyhat.com, 8080 for HTTP) and that your network allows outgoing connections to it.

All gateway errors and username flags are in the documentation: ProxyHat docs →

Price

Mobile and residential traffic share one price and one balance: from $4.00/GB for a 1 GB pack down to $1.80/GB for 1,000 GB. Traffic never expires, and all your browsers draw from the same balance. See pricing →

Playwright proxy setup: FAQ

Can Playwright use a SOCKS5 proxy with a username and password?

No. Playwright accepts a socks5:// server, but refuses a username or password with it: the browser doesn’t support SOCKS5 authentication. Use HTTP on port 8080, as in the samples; it carries HTTPS sites too.

Should I set the proxy at launch or per context?

At launch when the whole browser should use one setting, such as a rotating username. Per context, on newContext, when each worker needs its own sid and IP. A context’s proxy takes precedence over the launch one.

How do I give each worker its own IP?

Give each worker its own browser context with its own sid in the username, as in the sticky samples. One sid handles about 4–5 parallel connections, so don’t share it between workers.

How long does a sticky IP last?

As long as the -ttl- flag says, up to 24 hours: -ttl-10m, -ttl-30m, -ttl-1h, -ttl-24h. For an IP that doesn't rotate on a timer, use -sid- with -norotate-true and no -ttl-.

How do I pick a country, state or city?

Add -country- with a two-letter code (residential IPs in 195+ countries). For a state or city, add -region- and then -city- with their location codes, for example -country-US-region-new_york-city-new_york_city: the region must come before the city. -type-mobile switches to 4G/5G carrier IPs (150+ countries) at the same price.

The page shows a 407 error. What’s wrong?

The gateway didn’t accept the login. Check that the username and password in the proxy option are copied exactly from your dashboard and that every flag is spelled right (-country-US, not -country-USA). The errors table above lists the other codes.

Does this work with Playwright Test?

Yes. Put the same proxy object (server, username, password) in the use section of playwright.config, and every test runs through it.

Run Playwright through residential IPs

Create an account, buy a small pack and run the samples above before you scale out.

Pay as you go · Traffic never expires · Crypto checkout