Playwright proxy setup
Playwright takes the proxy, username and password in one setting, for the whole browser or for each context. This guide shows both, in Python and Node.js.
- Python and Node.js
- Login built in
- A proxy per context
Proxies for Playwright
Lowest rate for each. Every tier is on the pricing page.
Before you start
Three things to have ready.
Playwright
pip install playwright and playwright install, or npm install playwright.
Your proxy line
Copy the host, port, username and password from the generator in your dashboard. The examples use Eternal Residential: et.vantixproxy.com, port 1000.
A test address
https://api.ipify.org returns the IP a request came from.
Step 1: A proxy for the whole browser
Pass server, username and password when you launch the browser. Targeting goes at the end of the password. With a whitelisted IP, leave the username and password out.
- server http://host:port
- username From the generator
- password Plus targeting
- Browsers Chromium, Firefox and WebKit
Python
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch(proxy={
"server": "http://et.vantixproxy.com:1000",
"username": "USERNAME",
"password": "PASSWORD_country-US",
})
page = browser.new_page()
page.goto("https://api.ipify.org")
print(page.inner_text("body"))
browser.close()
Node.js
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch({
proxy: { server: 'http://et.vantixproxy.com:1000', username: 'USERNAME', password: 'PASSWORD_country-US' },
});
const page = await browser.newPage();
await page.goto('https://api.ipify.org');
console.log(await page.innerText('body'));
await browser.close();
})();
Step 2: A different IP per context
Each browser context can have its own proxy, so one browser can run several IPs side by side. Give each context its own session ID, and even its own country.
Python: two contexts, two IPs
browser = p.chromium.launch()
server = "http://et.vantixproxy.com:1000"
us = browser.new_context(proxy={"server": server, "username": "USERNAME",
"password": "PASSWORD_country-US_session-a1_lifetime-30"})
uk = browser.new_context(proxy={"server": server, "username": "USERNAME",
"password": "PASSWORD_country-GB_session-b1_lifetime-30"})
Step 3: Save bandwidth
Block images, fonts and video, which are most of a page’s weight, and each page costs far fewer GB.
Python: block heavy resources
HEAVY = {"image", "font", "media"}
page.route("**/*", lambda route: route.abort()
if route.request.resource_type in HEAVY else route.continue_())
Troubleshooting and questions
Why is the proxy ignored in new contexts on Windows?
Older Playwright versions need a proxy at launch before contexts can set their own. Launch with proxy={“server”: “http:/
Can I use SOCKS5 with a login?
Not in Chromium, which cannot log in to a SOCKS5 proxy. Use HTTP with a username and password, or SOCKS5 with a whitelisted IP.
What does ERR_TUNNEL_CONNECTION_FAILED mean?
Usually a rejected login. Check the username and password, or whitelist your IP. If the host or port is wrong, you will see ERR_
How do I get a new IP mid-run?
Close the context and open a new one with a new session ID. A context keeps its connections, and with them its IP.
Do Firefox and WebKit work too?
Yes. The same proxy option works for all three browsers Playwright ships.
Which proxy is best for Playwright?
Budget Residential for scraping at volume. Eternal Residential for occasional runs. Premium Residential for sites that challenge ordinary residential IPs.
Related guides and tools
More setup guides, and tools to test your proxies.
Get proxies for Playwright
Budget Residential from $0.49/GB, or Eternal Residential from $0.75/GB that never expires. No KYC, crypto or card.