How to Set Up a Proxy in Playwright for Website Testing
Learn where Playwright accepts proxy settings, how to pass credentials safely, how to exclude hosts, and how to confirm a test really runs through the proxy.
9 min readUpdated Nov 13, 2026By XPASS Editorial Team

Playwright is a popular tool for automated browser testing, and website teams often need it to answer a practical question: how does this page look and behave for a visitor connecting from somewhere else? Routing a test browser through a proxy is one way to find out. Playwright makes the configuration simple, but a few choices, such as whether to set the proxy for the whole browser or for one context, how to handle credentials and which hosts to exclude, determine whether your tests are reliable and safe to share.
This guide covers those choices step by step using the Node.js flavour of Playwright, with notes where the Python and other bindings differ only in syntax. As always, use proxies for lawful purposes such as QA, regional page checks and monitoring your own sites, and follow the terms and robots rules of any site you test.
Where Playwright accepts a proxy
There are three places to configure a proxy, and each has a different scope.
- At browser launch. Every page and context started from that browser instance uses the proxy. This is the simplest option for a short script.
- At browser context creation. Each context, which behaves like a separate incognito profile, can have its own proxy. This is useful when one test run needs to compare how a page looks through two different endpoints.
- In the test runner configuration. If you use the Playwright test runner, you can set the proxy in the configuration file under
use, so every test inherits it, and override it for specific projects or files.
For Chromium, the context-level option has historically come with a caveat: some Chromium setups require a launch-level proxy to be present before context-level proxies are honoured. Documentation changes between releases, so read the page for the version you installed rather than trusting memory or an old forum post.

Step 1: a minimal script with a launch-level proxy
import { chromium } from 'playwright';
const browser = await chromium.launch({
proxy: {
server: 'http://proxy.example.net:8080',
username: process.env.PROXY_USER,
password: process.env.PROXY_PASS,
},
});
const page = await browser.newPage();
await page.goto('https://example.com/');
console.log(await page.title());
await browser.close();
The server field holds the scheme, host and port. Credentials go in separate fields, which avoids the encoding problems that come with putting a password inside a URL. If your provider offers SOCKS, use a socks5:// address in server. Be aware that browsers have limits with SOCKS authentication, so confirm in the current documentation whether username and password are supported for your browser and protocol combination.
The environment variables here keep secrets out of the file. The guide on storing proxy credentials securely is worth a look if your team shares test repositories, and you can compare this approach with the library-level setup described in using a proxy with Python Requests.
Step 2: set the proxy per context
When you want two contexts in one run, give each its own settings.
const contextA = await browser.newContext({
proxy: { server: 'http://endpoint-a.example.net:8080', username: process.env.A_USER, password: process.env.A_PASS },
locale: 'en-GB',
timezoneId: 'Europe/London',
});
const contextB = await browser.newContext({
proxy: { server: 'http://endpoint-b.example.net:8080', username: process.env.B_USER, password: process.env.B_PASS },
locale: 'de-DE',
timezoneId: 'Europe/Berlin',
});
Notice that the locale and timezoneId options are set alongside the proxy. A proxy changes the IP address a site sees, but it does not change the language headers and time zone your browser reports. A realistic regional check aligns those with the region you are simulating, or else the page may respond to conflicting signals. Treat the result as an approximation: a site's behaviour depends on many inputs, and a proxy covers only one of them.
Step 3: configure it once in the test runner
For a test suite, use the configuration file so that individual tests stay clean.
// playwright.config.js
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
proxy: {
server: process.env.PROXY_SERVER,
username: process.env.PROXY_USER,
password: process.env.PROXY_PASS,
bypass: 'localhost,127.0.0.1,.internal.example',
},
},
});
The bypass string is a comma-separated list of hosts that should connect directly. It matters whenever your tests also talk to a local dev server, a staging database console or an internal API. Without it, those requests would try to reach your private addresses from the proxy's network and fail, or worse, leak internal host names to a third party.
You can then create separate projects for different endpoints and select them from the command line. This keeps one test file reusable across several regions without edits.
Step 4: verify the proxy is really in use
Never assume that a configured proxy is active. Add a tiny check at the start of the run.
await page.goto('https://api.ipify.org/');
const ip = (await page.textContent('body')).trim();
console.log('Public IP seen by sites:', ip);
Run the same script once without the proxy setting and once with it. The two addresses should differ. For a fixed address, repeated runs should print the same value; for a rotating endpoint, expect variation as your provider describes. Treat the echo page as a diagnostic, not as part of every test, and avoid calling it in a tight loop.
Because a browser also performs DNS lookups, it is worth reading about DNS leaks in proxy setups if the name-resolution path matters for your test. Browser proxy behaviour is different from a plain HTTP client, so do not assume the results from a script transfer to a browser.
Step 5: handle certificates carefully
Playwright has an option to ignore HTTPS errors. It is tempting when a test fails with a certificate message, but it should not be your default. If a failure appears only with the proxy enabled, the reasons are usually the ones described in the article about certificate cautions when using a proxy with HTTPS: an inspection layer on the network, an outdated browser build, or a wrong system clock.
There are two legitimate uses for relaxed checks. The first is a staging site you operate with a self-signed certificate; even then, importing that certificate authority is cleaner than ignoring errors everywhere. The second is a short, deliberate experiment where you know exactly what you are connecting to. Keep such options out of shared configuration, and never carry them into tests against public sites.
Step 6: write a regional check that is honest
A typical test compares what two contexts see. Keep the assertions focused on things you control or are entitled to verify.
- Assert the document title or a heading appears, rather than matching an entire page.
- Check that a language switcher or currency label matches the region you expect.
- Capture a screenshot for each context and attach it to the report for human review.
- Record the public IP and the time of the run so that findings can be reproduced.
Avoid tests that try to defeat a site's protective measures, such as solving challenges automatically or hammering a page repeatedly. Those are outside lawful testing, they often violate the terms of the site, and they are not what proxies are for in a QA workflow. When a site presents a challenge or blocks the test, treat that as information and contact the site owner if it is yours to fix.
Common problems and quick fixes
| Symptom | Likely cause | What to try |
|---|---|---|
| Net error: proxy connection failed | Wrong host, port or scheme | Re-check the details on the plan page |
| 407 or authentication prompt | Credentials missing or wrong | Pass username and password as separate fields |
| Local dev server not reachable | Requests sent through the proxy | Add the host to the bypass list |
| Context-level proxy ignored | Browser-specific restriction | Read the current docs; set a launch-level proxy as well |
| Certificate errors only with proxy | Inspection layer or old browser | Inspect the issuer; update the browser build |
| Tests fail intermittently | Timeouts too short for the route | Raise the navigation timeout, keep retries modest |
Limits and what to watch for
- A proxy changes the IP address, not the whole visitor profile. Language, time zone, cookies, device characteristics and the site's own logic all influence what you see.
- Keep secrets out of reports. Trace files, logs and screenshots can capture URLs and headers. Review them before sharing, and avoid putting credentials in page URLs.
- Respect the target. Follow the site's terms, robots rules and published rate limits, and test only what you are allowed to test.
- Browser versions matter. Proxy handling can differ across browser engines and releases. Pin versions in CI and re-check after upgrades.
- Parallel tests share network capacity. Running many workers through one endpoint can slow things down or trigger limits at the provider. Check the plan page for what is included.
- Another tool, similar ideas. If your team uses Node.js with a different automation library, the guide to using a proxy with Puppeteer in Node.js covers the same concepts with different syntax.
Running it in CI without surprises
Tests that pass on your laptop and fail in a pipeline are often a configuration issue rather than a proxy issue. A few habits reduce the guesswork.
First, supply proxy details to the pipeline through its secret store and expose them to the job as environment variables. Do not commit them in the configuration file, and make sure the job output does not echo them. Many CI systems mask known secret values in logs, but masking only works for exact matches, so avoid transforming a secret before printing it.
Second, keep one project per endpoint in the configuration and give each a clear name, such as the region it represents. When a run fails, the report then tells you immediately which route was in use. Pair each project with its own locale and time zone so that the combination is repeatable instead of depending on whoever last edited the file.
Third, make the verification step part of the setup rather than a manual chore. A short global setup script can request the IP echo page once per project and stop the run with a clear message if the proxy cannot be reached. That is far easier to diagnose than fifty identical timeouts from the actual tests. Save the observed address in the report metadata so that someone reading it later knows what the run looked like from the outside.
Fourth, watch the cost of parallelism. Many workers using one endpoint multiply the load on it. If a provider limits concurrent connections or ports, the plan page will say so; check it before you raise the worker count, and prefer a modest number of workers with sensible timeouts over a large number that produce flaky results.
Finally, schedule such checks sensibly. A regional page check that runs once a day is usually enough to catch a broken template or a missing translation. Running the same check every minute adds load to the site you are testing and to your provider without telling you anything new.
Summary
Playwright lets you set a proxy at the browser, context or test-runner level. Use the separate server, username and password fields, load secrets from environment variables, and add a bypass list for local and internal hosts. Align locale and time zone with the region you want to simulate, verify the public IP at the start of a run, and keep certificate checks on unless you control the test site. Remember that a proxy is only one input into what a site shows you, and keep every test lawful, polite and within the target site's terms.
If you need an endpoint to try these steps against, the options are described on the proxy page.
Frequently asked questions
Where do I set a proxy in Playwright?
You can set it when launching the browser, when creating a browser context, or globally in the test runner configuration. A context-level setting lets different tests use different proxies in the same browser process, although some browsers have restrictions, so check the current documentation for yours.
How do I pass a proxy username and password?
The proxy option accepts separate server, username and password fields. Read the values from environment variables rather than typing them into the test file.
How can I keep some hosts off the proxy?
Use the bypass option with a comma-separated list of hosts or domains, for example your local development server or an internal API, so those requests connect directly.
How do I confirm a test went through the proxy?
Open a simple page that shows your public IP address inside the same context and compare it with the address seen without the proxy. Add this as a small check at the start of the run.
Should I ignore HTTPS errors in tests?
Only for a controlled test site that you operate and only when you understand why the certificate is not trusted. For public sites, investigate the cause instead of turning verification off.
References
About the author

Bob Kanokphon Thongdee
- Founder of XPASS VPN
- Co-founder of eSIMonline.asia
- More than 7 years in online marketing
- Founder of Cojourney Visa and Cojourney Travel
Need a proxy for this?
XPASS Proxy sells residential proxy traffic by the gigabyte, with the price shown before you pay.
See proxy plansKeep reading

Proxy Guides
How to Use a Proxy with Python Requests, Step by Step
A practical walk-through of configuring a proxy in Python Requests, from a single call to a reusable session, plus how to verify it works and debug common errors.
9 min read

Proxy Guides
How to Use a Proxy with Puppeteer in Node.js
A step-by-step guide to routing Puppeteer through a proxy in Node.js, including authentication, excluding hosts, verifying the IP and avoiding common mistakes.
9 min read

Proxy Guides
Using a Proxy with HTTPS: Certificate Cautions to Know
A proxy can carry HTTPS traffic without reading it, but certificate warnings deserve attention. Learn what is normal, what is suspicious, and what never to switch off.
9 min read