Playwright proxy: set up an authenticated proxy in Python and Node.js
In this article
- 01 How do you set a proxy in Playwright?
- 02 Python example
- 03 Node.js example
- 04 A different proxy per context
- 05 SOCKS5 in Playwright
- 06 Match the time zone and language to the IP
- 07 Rotating the IP between sessions
- 08 Common errors
- 09 Playwright with 65Proxy's Singapore 4G proxies
- 10 Frequently asked questions
Playwright takes a proxy through its proxy option: a server address plus a username and password for a proxy with a login. You can set it once for the whole browser in launch(), or per session in new_context(). One limit matters before you start: Playwright refuses SOCKS5 proxies with a password, so use the proxy's HTTP port. Every example below was tested on 18 November 2026 with Playwright 1.65 driving Chrome 157.
How do you set a proxy in Playwright?
The proxy option has four fields, the same in Python and Node.js:
| Field | What it holds | Example |
|---|---|---|
server |
The proxy's address and port (required) | http://HOST:PORT |
username |
The proxy's username | USER |
password |
The proxy's password | PASS |
bypass |
Sites that skip the proxy, comma-separated | .example.com, localhost |
Put the username and password in their own fields, not inside the server URL. A server written without http:// is treated as an HTTP proxy.
You can pass proxy in three places:
launch(): every page in the browser uses the same proxy.new_context()(newContext()in Node.js): each context, a separate session with its own cookies, gets its own proxy.launch_persistent_context(): for a browser profile saved on disk.
Python example
Install Playwright and its Chromium with pip install playwright, then playwright install chromium. Keep the login in environment variables (PROXY_USER, PROXY_PASS) rather than in the code:
import os
from playwright.sync_api import sync_playwright
PROXY = {
"server": "http://HOST:PORT",
"username": os.environ["PROXY_USER"],
"password": os.environ["PROXY_PASS"],
}
with sync_playwright() as p:
browser = p.chromium.launch(proxy=PROXY)
page = browser.new_page()
page.goto("https://65proxy.com/ip.json")
print(page.inner_text("body"))
browser.close()The page prints the IP the site sees and its country. With a Singapore proxy, country should be SG. The async API takes exactly the same proxy dictionary.
Node.js example
Install with npm install playwright, then npx playwright install chromium. Save the file as proxy.mjs and run node proxy.mjs:
import { chromium } from "playwright";
const browser = await chromium.launch({
proxy: {
server: "http://HOST:PORT",
username: process.env.PROXY_USER,
password: process.env.PROXY_PASS,
},
});
const page = await browser.newPage();
await page.goto("https://65proxy.com/ip.json");
console.log(await page.innerText("body"));
await browser.close();A different proxy per context
A context is a separate browser session with its own cookies and storage. Giving each context its own proxy lets one browser run several accounts or jobs, each on its own IP:
import os
from playwright.sync_api import sync_playwright
PROXIES = [
{"server": "http://HOST1:PORT1", "username": os.environ["USER1"], "password": os.environ["PASS1"]},
{"server": "http://HOST2:PORT2", "username": os.environ["USER2"], "password": os.environ["PASS2"]},
]
with sync_playwright() as p:
browser = p.chromium.launch()
for proxy in PROXIES:
context = browser.new_context(proxy=proxy)
page = context.new_page()
page.goto("https://65proxy.com/ip.json")
print(page.inner_text("body"))
context.close()
browser.close()The browser itself doesn't need a proxy for this. Old guides tell Windows users to launch with a placeholder such as http://per-context; that has not been needed since Playwright 1.47. browser.new_page(proxy=...) also works: it creates a page in its own context.
How many proxies a job needs, one per parallel session or fewer, is covered in how many proxies do you need.
SOCKS5 in Playwright
Playwright accepts a SOCKS5 proxy without a password, such as socks5://HOST:PORT. With a username and password, launch() stops straight away with:
Browser does not support socks5 proxy authenticationThis applies to Chromium, Firefox and WebKit alike. Since paid proxies always have a login, use the HTTP port in Playwright. You lose nothing: both ports reach the same IP, and Playwright opens HTTPS sites through the HTTP port in an encrypted tunnel. The differences between the two protocols are in SOCKS5 vs HTTP proxies.
Match the time zone and language to the IP
A Singapore IP with a browser set to Vietnam's time zone is an obvious mismatch. Set the context's time zone and language to match the proxy:
context = browser.new_context(
proxy=PROXY,
timezone_id="Asia/Singapore",
locale="en-SG",
)In Node.js the options are timezoneId and locale. Then open our IP checker in that context: it compares the browser's time zone and language with the IP's country. What else to check is in how to check a proxy.
A proxy changes the IP, not the fact that a script is driving the browser. Keep a reasonable pace and follow each site's terms; proxies for bots and automation explains where the line is.
Rotating the IP between sessions
A browser keeps its connections to the proxy open, so rotating the IP while pages are loading breaks them. The safe order:
- Close the context (or the browser).
- Call the rotation link and wait until the IP has changed.
- Open a new context with the same proxy settings.
The code that calls the link and waits for the new IP is in rotating the IP with an API. Each 65Proxy proxy can rotate at most once every 5 minutes.
Common errors
| Error | Cause | Fix |
|---|---|---|
Browser does not support socks5 proxy authentication |
SOCKS5 port with a password | Use the HTTP port |
net::ERR_HTTP_RESPONSE_CODE_FAILURE on every page |
Wrong username or password (the proxy answers 407) | Copy the login again; see 407 errors |
net::ERR_TUNNEL_CONNECTION_FAILED on one site |
The proxy can't reach that site, for example an IPv6-only address | See tunnel errors |
Timeout 30000ms exceeded now and then |
A slow moment or short drop on the 4G line | Raise the timeout and retry; see proxy keeps disconnecting |
| A site's own login popup isn't filled in | Since Playwright 1.65 the proxy login is sent only to the proxy | Use the separate http_credentials option for the site |
When a page fails, run the same proxy through curl first: if curl works, the problem is in the Playwright settings.
Playwright with 65Proxy's Singapore 4G proxies
Every 65Proxy proxy has an HTTP port (the one to use in Playwright) and a SOCKS5 port, with one username and password, a rotation link, and a Singapore IP from the Singtel or M1 4G network. The proxy is not shared with other customers.
- Plans: 1 day $4, 7 days $13, 1 month $32, plus monthly plans with more bandwidth (500GB $40, 1TB $65).
- Test your script first on the free 1-hour trial.
- Buy: get a Singapore 4G proxy for Playwright; it is delivered automatically once paid.
Browsers download images, fonts and scripts, so they use far more bandwidth than plain HTTP requests. Ways to keep that down are in scraping JavaScript sites.
Frequently asked questions
Does Playwright support SOCKS5 with authentication?
No. Playwright stops with "Browser does not support socks5 proxy authentication" in every browser. Use the HTTP port of the same proxy instead.
Can each page have a different proxy?
Yes, through contexts: browser.new_context(proxy=...) for each session, or browser.new_page(proxy=...), which creates its own context. Pages inside one context share its proxy.
Do API requests use the proxy too?
page.request and context.request use the context's proxy. A standalone playwright.request.new_context() takes its own proxy option with the same fields.
Is Puppeteer different?
Yes: Puppeteer takes the proxy address as a Chrome launch flag and the login through page.authenticate(). See Puppeteer proxy setup.