Setting Up Proxies in Playwright in 2026

On This Page What Is a Proxy and Why Use One in Playwright?

February 10, 2026 · 9 min read · Tool Comparison

Setting Up Proxies in Playwright in 2026

Ever deploy a lineament that act dead locally, entirely to observe users in specific countries couldn & # 8217; t access it?

Or received complaint about geo-restricted content seem where it shouldn & # 8217; t?

I & # 8217; ve been there. Tests passed on my machine, but production users in Europe and Asia hit blocked check flows. The problem? I never tested from different geographic locations.

The resolution?

A proxy server acts as an go-between between the browser and the internet, masking the original IP reference and routing requests through a different web path.

Overview

A proxy is delimitate inside the launch options and can include certification if required.

const {chromium} = require (& # 8216; playwright & # 8217;);

(async () = & gt; {
const browser = await chromium.launch ({
proxy: {
server: & # 8216; http: //proxy-ip: port & # 8217;, // Example: & # 8216; http: //pr.oxylabs.io:7777 & # 8217;
username: & # 8216; proxy_user & # 8217;, // Optional for authenticated proxies
password: & # 8216; proxy_pass & # 8217; // Optional for authenticated proxies
}
});

const context = await browser.newContext ();
const page = await context.newPage ();
await page.goto (& # 8216; https: //example.com & # 8217;); // Routed through placeholder

await browser.close ();
})();

server: The placeholder server address in http: //ip: port or https: //ip: port formatusername and watchword: Optional. Only used when the proxy requires authentication

What Is a Proxy and Why Use One in Playwright?

A proxy server sits between your Playwright scripts and target websites. Instead of link immediately, your requests route through the procurator first, which then forward them to the goal.

Why Do Testers Use Proxies?

  • : Test how your app behaves for users in different commonwealth. Verify geo-restricted content, localized pricing, and regional compliance without traveling.
  • Avoid Rate Limits: Distribute requests across multiple IP addresses to foreclose blocking or throttling during large-scale automation.

Read More:

  • Privacy and Security: Mask your existent IP speech when examine sensible applications or conduct competitive analysis.
  • Corporate Requirements: Many enterprises require all traffic to route through corporate procurator for protection auditing and compliance.
  • Internal Testing: Access and test applications behind firewalls or simulate specific network environments.

While realise proxy use example is crucial, setting up and managing proxy infrastructure for comprehensive testing can be time-consuming. BrowserStack simplify proxy testing with cloud-based substructure, letting you validate contour across different environments without the setup overhead.

How to Configure a Proxy in Playwright (Global Scope)

The simplest way to configure a proxy is at browser launch. This applies to all Page and contexts from that browser representative.

1. Basic HTTP Proxy

const {chromium} = require (& # 8216; playwright & # 8217;);
(async () = & gt; {
const browser = await chromium.launch ({
proxy: {
server: & # 8216; http: //proxy.example.com:8080 & # 8217;
}
});

const page = await browser.newPage ();
await page.goto (& # 8216; https: //example.com & # 8217;);

await browser.close ();
})();

Read More:

2. HTTPS and SOCKS Proxies

Playwright supports HTTP, HTTPS, and SOCKS5:

// HTTPS proxyconst browser = await chromium.launch ({
proxy: {
waiter: & # 8216; https: //secure-proxy.example.com:8443 & # 8217;
}
});

// SOCKS5 placeholder
const browser = await chromium.launch ({
proxy: {
server: & # 8216; socks5: //socks-proxy.example.com:1080 & # 8217;
}
});

How to Configure a Proxy at Context or Page Level

Context-level placeholder configuration offer more flexibleness, allow different browser contexts use different proxy within the like browser instance. Perfect for simulating multiple users or localisation simultaneously.

1. Context-Level Configuration

const {chromium} = require (& # 8216; playwright & # 8217;);
(async () = & gt; {
const browser = await chromium.launch ();

// Context 1: US proxy
const context1 = await browser.newContext ({
proxy: {host: & # 8216; http: //us-proxy.example.com:8080 & # 8217;}
});
const page1 = await context1.newPage ();
await page1.goto (& # 8216; https: //example.com & # 8217;);

// Context 2: UK proxy
const context2 = await browser.newContext ({
placeholder: {server: & # 8216; http: //uk-proxy.example.com:8080 & # 8217;}
});
const page2 = await context2.newPage ();
await page2.goto (& # 8216; https: //example.com & # 8217;);

await browser.close ();
})();

2. Combining Geolocation with Proxies

For naturalistic geo-testing, combine procurator configuration with geolocation and locale:

const context = await browser.newContext ({proxy: {server: & # 8216; http: //japan-proxy.example.com:8080 & # 8217;},
geolocation: {longitude: 139.6917, latitude: 35.6895},
locale: & # 8216; ja-JP & # 8217;,
timezoneId: & # 8216; Asia/Tokyo & # 8217;
});

ReadMore:

Authenticating, Bypassing and Advanced Proxy Options

Many proxy servers require authentication, and certain traffic needs to short-circuit procurator entirely. Here & # 8217; s how to handle these scenario.

1. Proxy Authentication

const browser = await chromium.launch ({proxy: {
server: & # 8216; http: //proxy.example.com:8080 & # 8217;,
username: & # 8216; proxy_user & # 8217;,
watchword: & # 8216; secure_password & # 8217;
}
});

For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users.

Read More:

2. Environment Variable Credentials

For best protection, fund credentials in:

const browser = await chromium.launch ({proxy: {
waiter: process.env.PROXY_SERVER,
username: process.env.PROXY_USERNAME,
parole: process.env.PROXY_PASSWORD
}
});

3. Bypassing Specific Domains

Use the bypass choice to exclude domains from proxy routing:

const browser = await chromium.launch ({proxy: {
server: & # 8216; http: //proxy.example.com:8080 & # 8217;,
bypass: & # 8216; localhost,127.0.0.1, * .internal.company.com,192.168. * & # 8217;
}
});

Read More:

4. Handling Connection Failures

Implement error handle for proxy connectivity issues:

try {const browser = await chromium.launch ({
procurator: {server: & # 8216; http: //proxy.example.com:8080 & # 8217;}
});
const page = await browser.newPage ();
await page.goto (& # 8216; https: //example.com & # 8217;, {timeout: 30000});
} catch (erroneousness) {
if (error.message.includes (& # 8216; net: :ERR_PROXY_CONNECTION_FAILED & # 8217;)) {
console.error (& # 8216; Proxy connection failed, employ fallback & # 8217;);
// Fallback logic
}
}

Also Read:

Proxy Rotation and Dynamic Routing Strategies with Playwright

For large-scale mechanisation, rotate proxies prevents detection and distributes load across multiple IP addresses.

1. Elementary Round-Robin Rotation

const proxies = [& # 8216; http: //proxy1.example.com:8080 & # 8217;,
& # 8216; http: //proxy2.example.com:8080 & # 8217;,
& # 8216; http: //proxy3.example.com:8080 & # 8217;
];

let currentProxyIndex = 0;

async function createContextWithRotatedProxy (browser) {
const proxy = proxies [currentProxyIndex];
currentProxyIndex = (currentProxyIndex + 1) % proxies.length;

return await browser.newContext ({
proxy: {server: proxy}
});
}

const browser = await chromium.launch ();
const context1 = await createContextWithRotatedProxy (browser);
const context2 = await createContextWithRotatedProxy (browser);

2. Random Proxy Selection

function getRandomProxy () {
const proxies = [
{server: & # 8216; http: //proxy1.example.com:8080 & # 8217;, weight: 3},
{server: & # 8216; http: //proxy2.example.com:8080 & # 8217;, weight: 2},
{server: & # 8216; http: //proxy3.example.com:8080 & # 8217;, weight: 1}
];

const totalWeight = proxies.reduce ((sum, p) = & gt; sum + p.weight, 0);
let random = Math.random () * totalWeight;

for (const placeholder of procurator) {
if (random & lt; proxy.weight) return proxy.server;
random -= proxy.weight;
}
}

const context = await browser.newContext ({
proxy: {server: getRandomProxy ()}
});

3. Geographic Routing Strategy

const proxyPool = {
& # 8216; US & # 8217;: [& # 8216; http: //us-east.proxy.com:8080 & # 8217;, & # 8216; http: //us-west.proxy.com:8080 & # 8217;],
& # 8216; EU & # 8217;: [& # 8216; http: //eu-west.proxy.com:8080 & # 8217;, & # 8216; http: //eu-central.proxy.com:8080 & # 8217;],
& # 8216; ASIA & # 8217;: [& # 8216; http: //asia-pacific.proxy.com:8080 & # 8217;, & # 8216; http: //asia-east.proxy.com:8080 & # 8217;]
};

function getProxyForRegion (part) {
const proxies = proxyPool [part];
return proxy [Math.floor (Math.random () * proxies.length)];
}

const usContext = await browser.newContext ({
procurator: {server: getProxyForRegion (& # 8216; US & # 8217;)}
});

const euContext = await browser.newContext ({
proxy: {server: getProxyForRegion (& # 8216; EU & # 8217;)}
});

4. Time-Based Rotation

class ProxyRotator {
constructor (proxies, rotationIntervalMs = 300000) {
this.proxies = placeholder;
this.currentIndex = 0;
this.rotationInterval = rotationIntervalMs;
this.lastRotation = Date.now ();
}

getProxy () {
const now = Date.now ();
if (now & # 8211; this.lastRotation & gt; this.rotationInterval) {
this.currentIndex = (this.currentIndex + 1) % this.proxies.length;
this.lastRotation = now;
}
return this.proxies [this.currentIndex];
}
}

const rotator = new ProxyRotator ([
& # 8216; http: //proxy1.example.com:8080 & # 8217;,
& # 8216; http: //proxy2.example.com:8080 & # 8217;
], 300000);

const context = await browser.newContext ({
proxy: {server: rotator.getProxy ()}
});

Handling Corporate / Internal Network Proxies and Firewalls

Enterprise environments require especial proxy handling for security auditing, content filtering, and compliance. Corporate proxies often want domain authentication (like NTLM), use self-signed SSL certificates for traffic inspection, and require specific area to bypass the placeholder entirely.

1. Collective Proxy with Authentication

const {Cr} = require (& # 8216; playwright & # 8217;);
const browser = await chromium.launch ({
proxy: {
server: & # 8216; http: //corporate-proxy.company.com:8080 & # 8217;,
username: process.env.CORP_PROXY_USER,
password: process.env.CORP_PROXY_PASS,
bypass: & # 8216; localhost,127.0.0.1, * .company.com,10. * & # 8217;
},
ignoreHTTPSErrors: true
});

This authenticates with your corporate placeholder while bypassing it for internal company domain and local addresses. The ignoreHTTPSErrors flag handles self-signed certificates used by corporate SSL review.

AlsoRead:

2. System Proxy Detection

const browser = await chromium.launch ({procurator: {
server: process.env.HTTPS_PROXY || process.env.HTTP_PROXY
}
});

This automatically detects and uses your system & # 8217; s configure proxy without hardcoding server addresses-perfect for CI/CD environments where proxy background deviate.

3. NTLM Authentication for Windows

const context = await browser.newContext ({procurator: {
server: & # 8216; http: //corporate-proxy.company.com:8080 & # 8217;,
username: & # 8216; DOMAIN\username & # 8217;,
password: process.env.NTLM_PASSWORD
}
});

Windows Active Directory environments use NTLM hallmark. The DOMAIN\username formatting is required for domain-authenticated proxies.

Also Read:

4. Bypassing Proxy for Internal Resources

const circumstance = await browser.newContext ({proxy: {
server: & # 8216; http: //internal-proxy.company.com:8080 & # 8217;,
bypass: & # 8216; * .internal.company.com,192.168. * & # 8217;
},
baseURL: & # 8216; https: //app.internal.company.com & # 8217;
});

Internal companionship sites and local development host should connect directly without proxy routing. This prevents unneeded latency and authentication loop for resources already inside your net.

Managing enterprisingness proxy constellation across different environments and hallmark methods can become complex apace. BrowserStack & # 8217; s local testing capabilities let you examine corporate procurator setups seamlessly, unite your cloud tryout to internal network while handling authentication transparently.

How to Test Proxy-Dependent Websites Across Browsers and Devices at Scale

Testing proxy configurations across multiple browser, device, and real meshwork conditions quick becomes complex. Managing local infrastructure for this is resource-intensive and time-consuming.

Testing proxy configuration across multiple browsers, devices, and existent network conditions quickly becomes complex. Managing local base for this is resource-intensive and time-consuming.

That & # 8217; s where comes in. BrowserStack provides clamant access to 3,500+ real browsers and devices with built-in proxy support, eliminate infrastructure management.

Here are core features of BrowserStack that can assist you test proxy-dependent websites:

  • : Test US, EU, and ASIA proxy configurations in parallel across different gimmick character without managing complex infrastructure.
  • : Test your procurator setups with topically host covering before deployment.
  • : Track proxy test resultant with elaborate logs, screenshots, and video recordings of every session.
  • :Measure how proxy routing impacts your coating & # 8217; s load time and performance prosody.

Talk to an Expert

Conclusion

Configuring proxies in Playwright is essential for catch geo-blocking bug and location-specific failures before product. Master the appropriate configuration level, implement proper certification, and plan rotation strategies that match your quiz figure to ensure your covering work globally.

BrowserStack eliminates the complexity of care proxy infrastructure across browsers and devices. With instant access to real devices, parallel testing, and comprehensive analytics, you can focus on building robust tests instead of maintaining substructure.

Useful Resources for Playwright

Tool Comparisons:

Tags
7,000+ Views

# Ask-and-Contributeabout this theme with our Discord community.

Related Guides

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free