Playwright proxy setup
Playwright takes a proxy as three fields: a server, a username and a password. This guide shows where each value from your dashboard goes, how to give every browser context its own sticky IP, and how to read the errors a proxy can cause.
Last updated:
Connection fields
Your dashboard lists four values for every plan. Playwright needs all four, split over its proxy option.
A proxy line has the form HOST:PORT:USERNAME:PASSWORD. Playwright does not read that line as a whole. The host and port go into server together with the scheme, and the other two fields have their own keys:
- server: scheme, host and port, for example
http://HOST:PORT. - username: the proxy username, including any session or country suffix such as
USERNAME-session-482913-ttl-600. - password: the proxy password, written as it appears in the dashboard. No URL encoding is needed because it is not part of a URL.
The option exists in two places. Passed to launch() it applies to the whole browser. Passed to newContext() (new_context() in Python) it applies to one context, which is how you run several identities in a single browser process.
| Product | Host and port | Protocols | Authentication |
|---|---|---|---|
| Residential and Unlimited Residential | shown in your dashboard | HTTP, HTTPS and SOCKS5 on the same port | username:password |
| Rotating Mobile | shown in your dashboard | HTTP(S) and SOCKS5 on the same port | username:password |
| Mobile Proxy (Reset Link) | shown in your dashboard | HTTP(S) and SOCKS5 on the same port | username:password |
| Datacenter, ISP and IPv6 | shown with your order in the dashboard | HTTP(S) and SOCKS5 on separate ports | username:password |
HOST, PORT, USERNAME and PASSWORD in the examples are placeholders. Your dashboard shows the host, port, username and password for each plan: copy them from the Proxy generator.
HTTP(S) or SOCKS5
Both protocols reach the same pool. In Playwright the choice is decided by authentication.
| Protocol | Residential and mobile plans | Datacenter, ISP and IPv6 | In Playwright |
|---|---|---|---|
| HTTP(S) | host and port from your dashboard | HTTP(S) port shown with your order | Works with username and password. Use this by default. |
| SOCKS5 | same host and port | SOCKS5 port shown with your order | No login in Chromium, so it cannot be used with a username and password. |
Chromium has no support for SOCKS5 authentication, so a SOCKS5 server combined with a username and password does not work in a Playwright browser. Use the HTTP(S) port whenever you log in with credentials. The HTTP(S) port still carries HTTPS pages: the browser opens a CONNECT tunnel through the proxy and the TLS session stays between the browser and the site.
Authentication example
A complete script that starts Chromium behind the proxy and prints the exit IP.
import { chromium } from "playwright";
// Copy HOST, PORT, USERNAME and PASSWORD from your dashboard (Proxy generator).
const browser = await chromium.launch({
proxy: {
server: "http://HOST:PORT",
username: "USERNAME",
password: "PASSWORD",
},
});
const page = await browser.newPage();
await page.goto("https://api.ipify.org?format=json");
console.log(await page.textContent("body"));
await browser.close();from playwright.sync_api import sync_playwright
# Copy HOST, PORT, USERNAME and PASSWORD from your dashboard (Proxy generator).
with sync_playwright() as p:
browser = p.chromium.launch(
proxy={
"server": "http://HOST:PORT",
"username": "USERNAME",
"password": "PASSWORD",
}
)
page = browser.new_page()
page.goto("https://api.ipify.org?format=json")
print(page.text_content("body"))
browser.close()Replace HOST, PORT, USERNAME and PASSWORD with the values from your dashboard; copy them from the Proxy generator. Playwright answers the proxy's authentication challenge for you, in headless and headed mode alike, so there is no dialog to handle. firefox.launch() and webkit.launch() accept the same proxy option.
The script is the same for every plan; only these four values change.
Rotation and sticky sessions
The username decides whether the IP changes. Nothing else in the Playwright configuration has to move.
On a Residential plan the plain USERNAME rotates: every new connection gets a new IP. A browser keeps connections open and reuses them, so requests on one connection share an address while a new connection can leave from another. That suits stateless collection. Anything with a login, a cart or a multi-step form should hold one address, which is what a sticky session does.
A browser context is the natural unit for a sticky session: it already isolates cookies and storage, and Playwright lets each context carry its own proxy credentials. Give every context a different session number and each one keeps its own IP.
import { chromium } from "playwright";
// Residential plan: copy HOST, PORT, USERNAME and PASSWORD from your dashboard (Proxy generator).
const SERVER = "http://HOST:PORT";
const PASSWORD = "PASSWORD";
// One sticky session per browser context: each context keeps its own IP for 600 seconds.
const sessionIds = ["482913", "615027"];
const browser = await chromium.launch();
for (const id of sessionIds) {
const context = await browser.newContext({
proxy: {
server: SERVER,
username: `USERNAME-session-${id}-ttl-600`,
password: PASSWORD,
},
});
const page = await context.newPage();
await page.goto("https://api.ipify.org?format=json");
console.log(id, await page.textContent("body"));
await context.close();
}
await browser.close();from playwright.sync_api import sync_playwright
# Residential plan: copy HOST, PORT, USERNAME and PASSWORD from your dashboard (Proxy generator).
SERVER = "http://HOST:PORT"
PASSWORD = "PASSWORD"
# One sticky session per browser context: each context keeps its own IP for 600 seconds.
session_ids = ["482913", "615027"]
with sync_playwright() as p:
browser = p.chromium.launch()
for session_id in session_ids:
context = browser.new_context(
proxy={
"server": SERVER,
"username": f"USERNAME-session-{session_id}-ttl-600",
"password": PASSWORD,
}
)
page = context.new_page()
page.goto("https://api.ipify.org?format=json")
print(session_id, page.text_content("body"))
context.close()
browser.close()If an older Playwright release ignores the context proxy in Chromium, pass a placeholder to the launch call, proxy: { server: "http://per-context" }, and keep the real values on the context.
| Product | New IP | Same IP | Location |
|---|---|---|---|
| Residential and Unlimited Residential | USERNAME (every new connection) | USERNAME-session-482913-ttl-600 | USERNAME-country-de |
| Rotating Mobile | USERNAME (every new connection) | USERNAME-session-482913-ttl-600 | chosen in your dashboard |
| Mobile Proxy (Reset Link) | Change IP button or reset link | USERNAME keeps one IP for up to 24 hours | chosen in your dashboard |
| Datacenter, ISP and IPv6 | set in the Proxy generator | set in the Proxy generator | set in the Proxy generator |
On Residential and Unlimited Residential the username on its own rotates, so every new connection gets a new IP. For a sticky session add -session- with a number and -ttl- with the time in seconds. Sticky sessions last up to 24 hours; the dashboard offers 1 minute, 10 minutes, 30 minutes, 1 hour, 6 hours and 24 hours, or a custom time. Use a different session number for each account or task; a new number gives you a new IP. On Datacenter, ISP and IPv6, the Proxy generator of your order builds the username for you: copy the generated lines from there. Details are in the rotating proxies guide.
For IPs from one country on Residential or Unlimited Residential, add -country- and a two-letter country code to the username, for example USERNAME-country-de. State and city are chosen in the Proxy generator, which adds them to the username for you. Location and session combine as USERNAME-country-de-session-482913-ttl-600:
import { chromium } from "playwright";
// Residential and Unlimited Residential: copy HOST, PORT, USERNAME and PASSWORD
// from your dashboard (Proxy generator).
const browser = await chromium.launch({
proxy: {
server: "http://HOST:PORT",
// IPs from Germany, one IP held for 600 seconds.
username: "USERNAME-country-de-session-482913-ttl-600",
password: "PASSWORD",
},
});
const page = await browser.newPage();
await page.goto("https://api.ipify.org?format=json");
console.log(await page.textContent("body"));
await browser.close();On Rotating Mobile you choose All countries or a single country in your dashboard, and the carrier inside that country is picked automatically. The username carries only the session: without one, every new connection gets a new carrier IP.
On Rotating Mobile the session ID must be numbers only (digits 0–9); an ID with letters is ignored and the IP keeps rotating. The number is only an example: pick your own, such as a random 6-digit number, and use a different one for each account or task. The ttl value is how long you want to keep the IP, in seconds. Mobile networks can still change an IP on their own, so plan for an occasional change.
Mobile Proxy (Reset Link) keeps one carrier IP for up to 24 hours. Change it with the Change IP button or your reset link, once every 30 seconds; changing the location in your dashboard also gives you a new IP.
Test the connection
Confirm that traffic leaves through the proxy before you point the script at a real target.
The scripts above load https://api.ipify.org?format=json, which returns the address the request came from. It should differ from your own. To see both sides, open the My IP tool in your normal browser for your own address, then load the same page through the proxy in a headed Playwright browser (headless: false) and compare.
The version below adds a timeout and prints the reason when the request fails:
import { chromium } from "playwright";
// Copy HOST, PORT, USERNAME and PASSWORD from your dashboard (Proxy generator).
const browser = await chromium.launch({
proxy: {
server: "http://HOST:PORT",
username: "USERNAME",
password: "PASSWORD",
},
});
const page = await browser.newPage();
try {
const response = await page.goto("https://api.ipify.org?format=json", { timeout: 30000 });
console.log("status:", response.status());
console.log("exit IP:", await page.textContent("body"));
} catch (error) {
// Proxy problems surface here as net::ERR_... messages or as a timeout.
console.error("request failed:", error.message);
} finally {
await browser.close();
}Troubleshooting
Most failures come down to credentials, the port or the target.
407 Proxy Authentication Required
The proxy did not accept the login. Check the username and any session or country suffix on it, that the password has no trailing space, and that the credentials belong to the plan whose host you are using; copying the line again from the Proxy generator rules out a typo. A SOCKS5 server combined with a username and password fails earlier, at launch, with a "does not support socks5 proxy authentication" error; switch to the HTTP(S) port.
Timeouts and net::ERR_ errors
Chromium reports proxy trouble as net::ERR_ codes in the error message. ERR_PROXY_CONNECTION_FAILED means the browser could not reach the proxy at all: check the host, the port and any outbound firewall rule for the proxy port. ERR_TUNNEL_CONNECTION_FAILED means the proxy answered but did not open the tunnel, which usually points back to the login or to a blocked target port. A plain navigation timeout with a working IP check is normally the target being slow; raise timeout or wait for domcontentloaded instead of the full load.
Target ports by plan
On Residential and Unlimited Residential plans, residential IPs connect to websites on ports 80 and 443 only: a URL that names another port, such as :8443, fails even when the proxy login is correct.
All target ports are open on Rotating Mobile and Mobile Proxy (Reset Link) plans.
Playwright proxy setup: frequently asked questions
Can I set a different proxy for each Playwright context?
Yes. Pass the proxy option to newContext() (new_context() in Python) instead of launch(). Each context can use its own username, so each one can hold its own sticky session.
Does Playwright support SOCKS5 proxies with a password?
Not in Chromium, which has no SOCKS5 authentication. Use the HTTP(S) port with a username and password; on Residential and mobile plans it is the same host and port as SOCKS5.
How do I rotate the IP in Playwright?
On Residential, the plain username gives a new IP for every new connection. To change the IP of a sticky session, open a new context with a different session number. On Datacenter, ISP and IPv6, copy the rotating lines from the Proxy generator.
Do I need to URL-encode the proxy password in Playwright?
No. The username and password are separate fields of the proxy option, not part of a URL, so write them exactly as they appear in your dashboard.
Which Core Proxies product should I use with Playwright?
Start with Datacenter for speed and cost, and move to ISP or Residential when a target requires it. The Playwright code is the same; only the server, the username and the password change.
Run Playwright through Core Proxies
Create an account, choose your proxy type and plan, and copy the host, port, username and password from your dashboard. Activation is automatic after payment.
- Rotating and sticky sessions
- HTTP(S) and SOCKS5
- 24/7 support by email
Prices exclude VAT