In plain English: Playwright is a tool for controlling browsers from code. One set of commands drives Chromium (the engine behind Chrome and Edge), Firefox and WebKit (the engine behind Safari), and you can write your scripts in Python or Node.js. Its proxy support is refreshingly simple: the server, username and password are ordinary settings, so there's no extension to build and no login pop-up to fight.
Quick start in 3 steps
- Install Playwright and its browsers: one command for the package, one for the browsers.
- Check your proxy details with a one-line cURL test.
- Paste the launch example for your language, fill in your details and run it; the output shows the address the site saw.
Getting Playwright installed
Using Python:
pip install playwright
playwright installUsing Node.js:
npm install playwright
npx playwright installThe second command in each pair downloads the browsers that Playwright drives, so give it a minute. Wherever the code shows HOST, PORT, USER or PASS, put your own details. Test them before any browser code gets involved:
curl --proxy http://USER:PASS@HOST:PORT https://api.ipify.orgOne proxy for the whole browser (Python)
Hand a proxy dictionary, a small set of labelled values, to launch(). The server, username and password each get a field of their own:
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch(
headless=True,
proxy={
"server": "http://HOST:PORT",
"username": "USER",
"password": "PASS",
},
)
page = browser.new_page()
page.goto("https://api.ipify.org")
print(page.content())
browser.close()Playwright answers the proxy's login request by itself, so the page simply loads.
The same thing in Node.js
The JavaScript version reads almost the same:
const { chromium } = require("playwright");
(async () => {
const browser = await chromium.launch({
headless: true,
proxy: {
server: "http://HOST:PORT",
username: "USER",
password: "PASS"
}
});
const page = await browser.newPage();
await page.goto("https://api.ipify.org");
console.log(await page.content());
await browser.close();
})();A different proxy for each session
Playwright can also give each browser context its own proxy. A context is like a fresh private window with its own cookies and storage, so several can run inside one browser without mixing up their logins. Here, each context leaves through a different endpoint:
from playwright.sync_api import sync_playwright
endpoints = [
{"server": "http://HOST:PORT1", "username": "USER", "password": "PASS"},
{"server": "http://HOST:PORT2", "username": "USER", "password": "PASS"},
]
with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
for ep in endpoints:
ctx = browser.new_context(proxy=ep)
page = ctx.new_page()
page.goto("https://api.ipify.org")
print(page.inner_text("body"))
ctx.close()
browser.close()Got one rotating gateway rather than a list? Point every context at that gateway, and each session comes out on a new IP address without any extra code.
HTTP or SOCKS5?
The server field starts with the proxy type: http://HOST:PORT for HTTP, or socks5://HOST:PORT for SOCKS5. Playwright's username and password fields are meant for HTTP proxies, and a SOCKS5 proxy that needs a login won't work that way. So if you sign in with a username and password, stay with the http:// form. It still copes with secure https sites by opening a tunnel to them (the CONNECT method).
Make your data go further
Every gigabyte you route counts towards your plan, so the less a page downloads, the further your data stretches. Playwright's routing feature can stop images, video and fonts from loading:
page.route("**/*", lambda route: (
route.abort()
if route.request.resource_type in ["image", "media", "font"]
else route.continue_()
))Check before you scale up
Each example prints what the website sees as your IP address, so make sure it's the proxy's. For extra confidence, test the same details in our proxy checker and look up your real address with the My IP tool to compare the two.
Which type should I pick?
- Learning, testing your own site, or simple public pages: datacenter proxies keep the cost down.
- Sites with strict checks on visitors: residential proxies, or residential premium when residential isn't enough, using addresses from home internet connections.
- Mobile-first sites and carrier-specific content: mobile proxies.
Read about every type on the proxies page, and see what each costs on the pricing page.
Common mistakes
- Skipping the browser download. Without the second install command, Playwright has no browser to start.
- Writing the login into the server address. Use the separate username and password fields.
- socks5:// with a username and password. Switch to http:// for proxies that need a login.
- Leaving contexts open. Close each one when it's finished, as the example does, so memory doesn't fill up.
Is this allowed?
Automated browsers can overwhelm a site if you're careless. Read the target's robots.txt, follow its terms of service, leave deliberate pauses between actions, and gather only public information you're permitted to collect. Never use Playwright to get round logins, beat anti-fraud measures or harvest personal information without a lawful basis. Polite automation protects your project and the proxy addresses you rely on.
Beginner questions
Python or Node.js: which should I use?
Whichever you already know. The proxy settings are the same in both.
Do I need all three browsers?
No. The install command fetches them all by default, but you can name a single browser to save disk space, and the examples above only use Chromium.
Does the per-context proxy work in Node.js too?
Yes. Browser contexts accept a proxy setting in both languages; the example above happens to be in Python.