net::ERR_TUNNEL_CONNECTION_FAILED
In Chromium this usually means the proxy answered 407. Check the username and token, and make sure credentials are in the username and password fields, not inside the server URL.
Playwright drives Chromium, Firefox and WebKit from Python, Node.js, Java and .NET, and it is the common choice for scraping pages that need JavaScript. It has a proxy option with separate server, username and password fields, so authentication works without browser prompts or extensions.
You can set the proxy when launching the browser or per browser context. Per-context proxies are the most useful pattern: each context gets its own sticky session, cookies and IP, all inside one browser process.
Updated 23 November 2026
Use the HTTP port 8000. Playwright accepts socks5:// servers, but browsers do not reliably support a username and password on SOCKS5, so authenticated SOCKS5 is not recommended here. Your username and token appear on the Proxy setup page of your dashboard after your first order.
Follow the steps in order. Replace YOUR_TOKEN with the token from your dashboard and change the country, city or session in the username to suit the job.
Install the library, then download the browser build Playwright is tested against.
python -m pip install playwright
python -m playwright install chromiumPass server without credentials and give username and password separately. Playwright answers the proxy authentication challenge for every page in that browser.
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch(proxy={
"server": "http://gate.firstproxy.shop:8000",
"username": "user-country-us",
"password": "YOUR_TOKEN",
})
page = browser.new_page()
page.goto("https://ipinfo.io/json")
print(page.inner_text("body"))
browser.close()Set the proxy on new_context instead of launch. Use a different session name per context and a ttl long enough for the whole flow. Each context then keeps its own IP, cookies and storage, which is how you run several accounts or regions in parallel.
with sync_playwright() as p:
browser = p.chromium.launch()
for n, country in enumerate(["us", "gb", "de"]):
ctx = browser.new_context(proxy={
"server": "http://gate.firstproxy.shop:8000",
"username": f"user-country-{country}-session-ctx{n}-ttl-30m",
"password": "YOUR_TOKEN",
})
page = ctx.new_page()
page.goto("https://ipinfo.io/json")
print(country, page.inner_text("body"))
ctx.close()
browser.close()A US IP with a browser that reports a European timezone is an easy signal for anti-bot checks. Set locale and timezone_id (Python) or timezoneId (Node.js) on the context to match the country and city in the username.
ctx = browser.new_context(
proxy={
"server": "http://gate.firstproxy.shop:8000",
"username": "user-country-us-city-new-york-session-nyc1-ttl-20m",
"password": "YOUR_TOKEN",
},
locale="en-US",
timezone_id="America/New_York",
)Residential proxies are billed per GB, and images, fonts and video are usually most of a page. Abort them with a route when you only need text and data.
BLOCK = {"image", "media", "font"}
def block_heavy(route):
if route.request.resource_type in BLOCK:
route.abort()
else:
route.continue_()
page.route("**/*", block_heavy)Open ipinfo.io/json in the proxied page and print the body. For a per-context setup, run the check once per context: each should show its own country and IP.
A working proxy returns a response like the one shown, trimmed to the main fields. The IP belongs to the exit, the city and country follow your username, and the time zone is where that IP is located, here United States.
page.goto("https://ipinfo.io/json")
print(page.inner_text("body")){
"ip": "203.0.113.24",
"city": "New York",
"country": "US",
"timezone": "America/New_York"
}203.0.113.24 is a documentation address. Your result shows a real exit IP.
All targeting is written into the username, so Playwright needs no extra settings to change location. Parts are joined with hyphens in this order after your proxy user. The password is always your token.
| Part | Format | Example | Rule |
|---|---|---|---|
| Country | -country-{cc} | -country-us | Required. Two-letter country code in lowercase. 64 countries are available. |
| City | -city-{city} | -city-new-york | Optional. City name in lowercase, spaces become hyphens. 172 cities are available. |
| Session | -session-{id} | -session-a1b2c3 | Optional. Any letters and digits you choose. The same id keeps the same IP, a new id gets a new IP. |
| Session length | -ttl-{minutes}m | -ttl-30m | Used with a session. Residential 1 to 120 minutes, mobile 1 to 60, long-acting ISP up to 720 (12 hours). |
user-country-us-city-new-york-session-a1b2c3-ttl-30mFind country codes and city values on the proxy locations page.
The problems people run into most often with Playwright, with the message you are likely to see and how to solve it.
In Chromium this usually means the proxy answered 407. Check the username and token, and make sure credentials are in the username and password fields, not inside the server URL.
The browser cannot reach the gateway. Check the host spelling and port 8000, and that a firewall or corporate network allows outbound connections to it.
Proxied pages with many assets can take longer. Use wait_until="domcontentloaded", raise the timeout with page.set_default_navigation_timeout(60000), and block heavy resources.
Without a session part, new connections get new IPs, and a browser opens many connections. Add -session-{name}-ttl-{minutes}m to the username for any flow that must stay on one IP.
WebRTC and the reported timezone can contradict the IP. Match timezone_id and locale, and for Chromium add --force-webrtc-ip-handling-policy=disable_non_proxied_udp to the launch args so WebRTC cannot use UDP outside the proxy. Then test the context on a WebRTC leak page.
All products share one account, one prepaid balance and the same gateway, so you can switch type by changing the product, not the code.
From $0.23 per GB
Per-context sticky sessions up to 120 minutes with city targeting for realistic browser sessions.
View residential proxiesFrom $0.78 per GB
Carrier IPs for mobile-first sites and pages that treat phones differently, sticky up to 60 minutes.
View mobile proxiesFrom $0.72 per 1,000 requests
Rendered HTML from our side when running browsers yourself costs too much time or traffic.
View web scraper apiBuilding a scraper? The web scraping use case covers request rates, retries and product choice in more depth.
Short answers to what people ask most about using a proxy with Playwright.
Pass proxy={"server": "http://gate.firstproxy.shop:8000", "username": "...", "password": "YOUR_TOKEN"} to launch or new_context. Playwright handles the authentication challenge, so no extension or prompt is needed.
Yes. Set the proxy option on new_context. Each context can have its own username, which means its own country, session and IP, while sharing one browser process.
Playwright accepts socks5:// servers, but username and password on SOCKS5 are not reliably supported by the browsers it drives. With credentials, use the HTTP port, which tunnels HTTPS pages as well.
Full page loads include images, fonts, video and tracking scripts. Block those resource types with page.route and reuse a context for several pages of the same site to keep traffic low.
Yes. The option has the same three fields in every language. Only the method names differ, such as new_context in Python and newContext in Node.js.
--proxy-server plus page.authenticate, per-context proxies and SOCKS5 through a local bridge.
Scraping and automation librariesSelenium proxy setupAuthenticated proxies with selenium-wire, or an IP allowlist with --proxy-server.
Scraping and automation librariesPython requests proxy setupThe proxies dict, sessions with sticky IPs, SOCKS5 with socks5h and async options.
Programming languagesNode.js proxy setupfetch with undici ProxyAgent, axios with https-proxy-agent, and SOCKS5 agents.
Web browsersGoogle Chrome proxy setupSystem proxy on Windows and macOS, a separate proxied profile, and WebRTC protection.
Get your token and run the first Playwright request
Create an account, top up from $40 with crypto, and copy the gateway, username and token from the dashboard.