.bp-clean-small-figure{max-width:540px!important;width:100%!important;margin:22px auto!important;padding:10px!important;border-radius:20px!important;background:#fff!important;box-shadow:0 10px 28px rgba(7,18,5,.10)!important}.bp-clean-small-figure img,.bp-clean-small-image{display:block!important;width:100%!important;height:auto!important;border-radius:16px!important}.bp-clean-small-figure figcaption{font-size:14px!important;line-height:1.45!important;color:#4b5563!important;margin-top:10px!important;text-align:center!important}
Browser automation guide
How to Use Proxies with Playwright
Configure global and per-context proxies in Playwright Test, JavaScript and Python with secure authentication, stable sessions, exit verification and practical debugging.
Short answer: how to use a proxy with Playwright
Playwright supports HTTP, HTTPS and SOCKS5 proxy configuration at browser launch or for an individual browser context. Provide the proxy server and, when required, username and password in the Playwright proxy options. Keep credentials in environment variables, create a clean context, open a harmless IP-check endpoint, and verify that the reported exit matches the expected proxy before running the real test.
The official Playwright network documentation shows global and per-context proxy configuration, optional authentication and bypass hosts. Context-level routing is especially useful when one test worker needs isolated cookies and a stable proxy identity without launching a separate browser for every case.
Configure a global proxy in Playwright Test
For a suite where every page uses the same endpoint, place the proxy under use in playwright.config.ts. Read secrets from the environment so the config can be committed without publishing credentials.
import { defineConfig } from '@playwright/test';
export default defineConfig({
workers: 2,
use: {
proxy: {
server: process.env.PROXY_SERVER!,
username: process.env.PROXY_USERNAME,
password: process.env.PROXY_PASSWORD,
bypass: 'localhost,127.0.0.1'
},
trace: 'retain-on-failure'
}
});
Start the test process with the values supplied by your local secret store or CI platform. A typical server value is http://proxy.example:8080 or socks5://proxy.example:1080. Do not paste a production password into the repository, test name, screenshot filename or console output.
Use bypass only for hosts that must connect directly, such as a local application under test. Review this list carefully: a broad suffix can send more traffic outside the proxy than intended.
Verify the exit inside the test
import { test, expect } from '@playwright/test';
test('uses the expected proxy country', async ({ page }) => {
await page.goto('https://api.ipify.org?format=json');
const result = JSON.parse(await page.textContent('body') || '{}');
expect(result.ip).toMatch(/^d{1,3}(.d{1,3}){3}$/);
});
An IP format assertion proves only that an address was returned. For production QA, compare it with the expected assigned exit and use the IP location checker or a controlled service that returns the evidence your test needs.
Use a different proxy for each browser context
Playwright browser contexts are isolated, incognito-like sessions. The official test isolation guide explains that cookies, local storage and session storage are separated between contexts. Proxy assignment should follow the same boundary: one context, one stable endpoint, one documented test scenario.
import { chromium } from 'playwright';
const browser = await chromium.launch();
const context = await browser.newContext({
proxy: {
server: process.env.PROXY_SERVER!,
username: process.env.PROXY_USERNAME,
password: process.env.PROXY_PASSWORD
},
locale: 'en-GB',
timezoneId: 'Europe/London'
});
const page = await context.newPage();
await page.goto('https://example.com');
await context.close();
await browser.close();
Location-sensitive QA often controls locale and time zone as well as network exit. Keep those values explicit, but do not claim the proxy changes every browser signal. The website localization testing guide explains how cookies, account state, language and delivery settings can alter the page independently.

Playwright proxy example in Python
The same configuration is available in the Python binding. The synchronous example below launches Chromium through an authenticated proxy, verifies the public IP response and closes the browser in a finally block.
import json
import os
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch(
proxy={
"server": os.environ["PROXY_SERVER"],
"username": os.getenv("PROXY_USERNAME"),
"password": os.getenv("PROXY_PASSWORD"),
}
)
try:
page = browser.new_page()
page.goto("https://api.ipify.org?format=json")
result = json.loads(page.text_content("body") or "{}")
print("Proxy exit:", result.get("ip"))
finally:
browser.close()
Mask the printed address if test reports are public. Never print the proxy URL when it contains embedded credentials. If you already use Python for HTTP requests, link this browser test to the broader Python proxy guide rather than maintaining unrelated credential formats.
Install Playwright browsers behind a proxy
Downloading the browser binaries is a separate network operation from page traffic. Playwright documents HTTPS_PROXY for browser downloads, NODE_EXTRA_CA_CERTS for an authorized internal certificate authority, and a download connection timeout for slow networks in its browser installation guide.
# PowerShell
$Env:HTTPS_PROXY = "http://proxy.example:8080"
npx playwright install
# Linux or macOS
HTTPS_PROXY="http://proxy.example:8080" npx playwright install
This installation proxy does not automatically configure later test pages. Set page traffic through the Playwright proxy option as shown above. Do not disable TLS verification to silence a certificate problem; install the approved CA correctly or ask the network owner to fix the trust chain.
Parallel workers, sessions and proxy rotation
Do not pick a random proxy for every navigation. A login or multi-page journey normally needs one stable exit for the life of its context. Assign a proxy at worker or test boundary, record the masked proxy ID, and release it only after the context closes.
- Limit workers to the tested concurrent capacity of the proxy plan.
- Use one proxy for a complete stateful test journey.
- Allocate different accounts to tests that modify server-side state.
- Quarantine an endpoint after repeated transport or location failures.
- Keep retries bounded and preserve the original failure evidence.
- Close pages, contexts and browsers even when an assertion fails.
The static versus rotating proxy guide helps choose between stable sessions and independent jobs. For capacity planning, use How Many Proxies Do You Need? rather than equating worker count with a safe request rate.
Debug common Playwright proxy failures
| Symptom | Likely layer | First check |
|---|---|---|
| Browser fails before navigation | Launch option, browser binary or proxy URL | Validate protocol, host and port; run one direct baseline |
| 407 response | Proxy authentication | Check username, password, allowlist and credential source |
| Timeout on every target | Proxy reachability or DNS | Test the endpoint with the proxy tester |
| Only one website fails | Destination response or policy | Capture status, final URL and page content before rotating |
| Wrong country | Pool assignment or geolocation data | Record the observed exit and compare independent databases |
| Flaky parallel tests | Shared state, overload or aggressive retries | Reduce workers and isolate contexts, accounts and proxy assignments |
Enable a Playwright trace for failures and listen to request and response events when the application path is unclear. Do not log authorization headers or proxy passwords. The proxy error code guide provides a layer-by-layer path for 407, 403, 429, 502 and timeouts.

Production-ready Playwright proxy checklist
- Use a supported Playwright version and official proxy options.
- Load proxy credentials from environment or a secret manager.
- Verify the public exit before the main test.
- Keep one stable proxy per stateful browser context.
- Record locale, time zone, device and account state beside the exit.
- Bound worker concurrency, timeouts and retries.
- Retain traces on failure with sensitive values redacted.
- Close every context and browser in cleanup code.
For framework comparisons, see the Selenium proxy guide and Puppeteer proxy guide. Playwright is often the most direct choice when per-context proxy settings and cross-browser projects are central to the test design.
Run Playwright proxy tests reliably in CI
A proxy test that works on a laptop can still fail in CI because the runner has a different network path, DNS resolver, certificate store or secret-loading mechanism. Treat the proxy as an explicit test dependency. Store the endpoint and credentials in the CI secret manager, inject them at runtime and fail early when a required value is missing. Do not print a fully assembled proxy URL in logs: it can expose the username and password even when individual environment variables are masked.
Before starting a long browser suite, run one small health check that opens an IP endpoint and one HTTPS page that represents the target class. Record the exit IP, response time and proxy assignment identifier. That gives you evidence to separate a proxy outage from a browser launch problem. It also prevents twenty parallel workers from repeating the same predictable failure.
Choose retry boundaries deliberately
Retry a new context only when the failure is plausibly tied to the route, such as a connect timeout, proxy handshake failure or unhealthy exit. A selector timeout after the application rendered should remain an application-test failure. Keep the same proxy for all steps that belong to one user journey; changing IP halfway through login, checkout or account setup can invalidate the session and create misleading results.
For scheduled regional tests, retain a small report with the requested market, observed exit country, worker ID and final status. This makes Playwright proxy runs auditable without storing sensitive page content. When the suite grows, use the proxy tester before assignment and keep a short quarantine period for endpoints that repeatedly fail.
Playwright proxy FAQ
Does Playwright support authenticated proxies?
Yes. Its proxy options accept a server plus optional username and password for supported HTTP or HTTPS proxy authentication.
Can each Playwright context use a different proxy?
Yes. The official network documentation supports configuring a proxy when creating a browser context, which is useful for isolated test scenarios.
Does HTTPS_PROXY configure browser page traffic?
Not by itself. It can configure browser binary downloads. Use the Playwright proxy option for pages opened by the automated browser.
Should a proxy rotate during a login test?
Usually no. Keep one stable exit for the complete stateful journey and rotate only when starting a new independent scenario.
How do I confirm Playwright uses the proxy?
Open a controlled IP endpoint, compare the observed exit with the assigned proxy, then test the real authorized target and record both results.
Why does the proxy work in cURL but fail in Playwright?
Check protocol syntax, browser proxy support, authentication, DNS behavior, target differences and whether cURL used a different credential or bypass rule.
Use tested proxies in reproducible developer workflows
Use private authenticated proxies for authorized browser tests, align one stable endpoint with each stateful context, and measure valid test outcomes instead of raw navigation volume.
Playwright proxy setup steps
- Decide whether the proxy should apply to the browser launch or a specific context.
- Add the proxy server and credentials to the Playwright configuration.
- Launch a small test context before running the full script.
- Verify the exit IP and expected country from inside the browser context.
- Reuse the tested configuration in the real automation workflow.
Proxies for Playwright: practical buying notes
This page is strongest when it connects setup details to a buying decision. Use stable private proxies when you need repeatable tests, account-safe sessions, reproducible reports or clean troubleshooting. Use cheaper semi-dedicated proxies for early testing and move important workflows to dedicated IPs once the process is proven.
| Need | Recommended proxy behavior | Related guide |
|---|---|---|
| Stable sessions | Use static or sticky private proxies. | Static vs rotating proxies |
| Troubleshooting | Test format, authentication and exit IP before scaling. | Proxy tester |
| Location-sensitive checks | Choose proxy country close to the target audience. | Choose proxy location |
What proxy type should I start with?
Start with static private proxies when accuracy and troubleshooting matter. Use rotation only when the workflow can tolerate IP changes.
Should I test proxies before using them?
Yes. Test one proxy outside the application first, then import the same working format into the real tool.
Related BuyProxies guides
These related pages help connect the setup, troubleshooting and buying decisions instead of treating each proxy problem in isolation.
Proxy authentication failed
Use this guide as the next step when you need a more specific proxy workflow.
HTTP 407 proxy authentication required
Use this guide as the next step when you need a more specific proxy workflow.
Proxy timeout errors
Use this guide as the next step when you need a more specific proxy workflow.
Best proxies for scraping
Use this guide as the next step when you need a more specific proxy workflow.
How many proxies for scraping
Use this guide as the next step when you need a more specific proxy workflow.
How many proxies for multiple accounts
Use this guide as the next step when you need a more specific proxy workflow.
