Playwright proxy configuration with authentication
Configure a proxy for Chromium or an isolated browser context. Keep credentials in environment variables, verify the route and troubleshoot connection errors.
Pass the proxy server, username and password in Playwright's proxy configuration. Use a separate browser context for an independent session, and verify the exit IP from that same context before testing your application.
Configure an explicit browser connection
Use the endpoint and protocol issued for your rental. The example below uses an authenticated HTTP proxy with Chromium. Set the environment variables in your local secret configuration rather than committing their values.
Proxy settings can apply at browser launch or to an individual browser context. Use context-level configuration when tests need separate proxy settings; keep those contexts isolated so cookies and local storage do not cross between scenarios.
import { chromium } from "playwright";
for (const key of ["MP_PROXY_SERVER", "MP_PROXY_USERNAME", "MP_PROXY_PASSWORD"]) {
if (!process.env[key]) throw new Error(`Missing ${key}`);
}
const browser = await chromium.launch();
try {
const context = await browser.newContext({
proxy: {
server: process.env.MP_PROXY_SERVER!,
username: process.env.MP_PROXY_USERNAME!,
password: process.env.MP_PROXY_PASSWORD!,
},
});
const page = await context.newPage();
await page.goto("https://api.ipify.org?format=json", {
waitUntil: "domcontentloaded", timeout: 30_000,
});
// Inspect the observed IP locally. Do not log proxy credentials.
const observed = JSON.parse(await page.locator("body").innerText());
if (typeof observed.ip !== "string") throw new Error("Missing observed IP");
await context.close();
} finally {
await browser.close();
}Check the network scope of the test
A proxy setting on one context does not configure unrelated clients in your process. A Node.js fetch call, a separate API client or another browser context may still use a direct connection. Run the IP check from the same context or request client whose traffic you are evaluating.
For regional QA, set browser locale and timezone separately. A proxy does not automatically change navigator language, geolocation permission or an account's saved country. Record those inputs so a test failure is reproducible.
Diagnose failures before changing browser settings
Do not suppress TLS validation as a general fix. Inspect the certificate or network error and correct the trust or endpoint configuration. Keep traces and screenshots private when they contain tokens, customer data or authenticated page content.
| Observation | Next check |
|---|---|
| Proxy authentication failure | Issued username, password, protocol and active rental. |
| Connection timeout | Endpoint reachability, request deadline and reconnect state. |
| IP echo works; destination fails | Destination response, URL, method and application state. |
| Unexpected country | Same-context exit IP, location databases and saved preferences. |
Keep rotation outside an active test
Use the dashboard or rotation interface issued for the rental. Finish or cancel the current test before reconnecting, then verify the resulting exit IP. Recreate a browser context when your scenario requires fresh state.
A new carrier address does not guarantee that a destination will accept the next request. Keep the test's expected behavior explicit and stop after bounded retries so repeated failures remain visible.