How to set up a Playwright proxy with a login
Playwright has a proxy option built in, with fields for the username and password, so an authenticated proxy needs no extension or helper server. This guide shows the option in Node.js and Python, explains when to set it on the browser and when on each context, and covers what a rotation means for a long test or crawl.
The placeholders HOST, PORT, USERNAME and PASSWORD stand for the values from your dashboard. See pricing for plans.
AtlasProxies Team · Updated · 5 min read
- 1Server, Username, PasswordPlaywright takes the login as separate fields next to server, not inside the address.
- 2Contexts Carry Their Own ProxyOne browser can run several contexts, each with its own proxy, cookies and storage.
- 3Use HTTP When a Login Is NeededPlaywright documents the username and password for HTTP proxies, so set the proxy to HTTP in the dashboard.
On This Page
What the proxy option takes
In every Playwright language the proxy is an object with up to four keys. server is the proxy address, written as http://HOST:PORT. username and password hold the login. bypass is an optional comma-separated list of domains that should skip the proxy.
Playwright's docs accept SOCKS5 addresses in server, and describe username and password as the login for an HTTP proxy that requires authentication. Because your proxy uses a login, set it to HTTP in the dashboard before using it from Playwright, and copy the HTTP port. HTTP vs SOCKS5 explains how the two protocols differ.
Node.js: proxy at launch
Set the proxy when you start the browser, and every page it opens uses it:
const browser = await chromium.launch({
proxy: { server: 'http://HOST:PORT', username: 'USERNAME', password: 'PASSWORD' },
});Then open a page with browser.newPage() and load https://api.ipify.org to confirm the exit IP.
In Playwright Test, the same object goes under use.proxy in playwright.config.ts, which applies it to every test in the project. Read the values from environment variables there, so the login stays out of the repository.
Python: proxy at launch
The Python API takes a dictionary with the same keys:
with sync_playwright() as p:
browser = p.chromium.launch(proxy={'server': 'http://HOST:PORT', 'username': 'USERNAME', 'password': 'PASSWORD'})The async API is identical apart from await in front of the launch call.
Method names follow Python style, so new_context and new_page replace newContext and newPage. Everything else in this guide applies to both languages.
One proxy per browser context
A context is an isolated session inside one browser, with its own cookies, local storage and cache. Playwright lets each context carry its own proxy, which makes the context the natural unit when one script handles several accounts or locations: one proxy, one context, one set of cookies.
In Node.js, create it with:
const context = await browser.newContext({
proxy: { server: 'http://HOST:PORT', username: 'USERNAME', password: 'PASSWORD' },
});In Python, the call is:
context = browser.new_context(proxy={'server': 'http://HOST:PORT', 'username': 'USERNAME', 'password': 'PASSWORD'})Pages opened from that context go through its proxy, while a second context can point at a different proxy at the same time.
Playwright's docs describe contexts as fast and cheap to create, so a script that manages ten accounts can keep one browser running with ten contexts. Close each context when its work ends, which also closes its connections to the proxy.
Check the exit IP in each context
Open https://api.ipify.org in a page from each context and read the body text. Each context should print the IP of its own proxy, matching Current Public IP in that proxy's IP Rotation panel. A context that shows your own IP has no proxy of its own, usually because the proxy was set on a different context or on a browser the script did not use.
If page.goto fails with a proxy or authentication error, recopy USERNAME and PASSWORD from My Proxies and check that the proxy is still set to HTTP. 407 Proxy Authentication Required covers the remaining causes.
Long runs and the rotation timer
Each proxy changes IP on the timer you picked, from every 5 to every 120 minutes. Playwright needs no change when that happens, because server, username and password stay the same. A request in flight at the moment of the switch can fail, and a page.goto that was still loading may throw a network error such as net::ERR_CONNECTION_RESET.
Nothing in Playwright or in the dashboard rotates the IP before the timer, so build the run around it.
- Wrap navigation in a retry that catches the error, waits a few seconds and loads the page again. Reloading a page is safe, while resubmitting a form may not be.
- Make steps idempotent. Check whether an action already happened, such as a saved draft, before repeating it after an error.
- In Playwright Test, the retries setting in the config reruns failed tests, which absorbs an occasional rotation error in a long suite.
- Log the exit IP at the start of each test or job, so a failure can be matched to a rotation.
Timeouts, speed and data use
Mobile proxies run at 10–100 Mbps by plan, and pages heavy with media take longer through any proxy than on a local connection. If tests time out during navigation, raise the limit with page.setDefaultNavigationTimeout (set_default_navigation_timeout in Python) before suspecting the proxy itself.
Skipping images and fonts with page.route trims what each test downloads. That matters on Eco and Pro, which have unlimited bandwidth with 15 GB/day of fair use. A proxy that reaches 15 GB in a day stops until the limit resets the next day, while Ultra is truly unlimited. A longer rotation interval keeps a whole run on one IP, as rotating mobile proxies explains, and automation proxies covers scheduled jobs.
Good to Know. Automate only what each website's terms allow, and follow our Acceptable Use Policy.
Frequently Asked Questions
Does Playwright support proxies with a username and password?
Yes. The proxy option has username and password fields next to server, both at launch and on each new context.
Can each Playwright context use a different proxy?
Yes. Pass a proxy to browser.newContext (new_context in Python), and pages in that context use it while other contexts keep their own.
Can I put the login inside the server address?
Use the separate username and password fields instead. They are the form Playwright documents, and they keep server to a plain http://HOST:PORT.
Why use HTTP rather than SOCKS5 in Playwright?
Playwright's docs describe username and password as the login for an HTTP proxy. Switch the proxy to HTTP in the dashboard when you use it from Playwright with a login.
What happens to an open page when the IP rotates?
The context and its cookies stay. A request that was in flight can fail, so reload the page or retry the step.