Setting Up Proxies in Playwright in 2026
On This Page What Is a Proxy and Why Use One in Playwright?
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. A proxy is delimitate inside the launch options and can include certification if required. (async () = & gt; { const context = await browser.newContext (); 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 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? Read More: 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. The simplest way to configure a proxy is at browser launch. This applies to all Page and contexts from that browser representative. const page = await browser.newPage (); await browser.close (); Read More: Playwright supports HTTP, HTTPS, and SOCKS5: // SOCKS5 placeholder 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 // Context 1: US proxy // Context 2: UK proxy await browser.close (); 2. Combining Geolocation with Proxies For naturalistic geo-testing, combine procurator configuration with geolocation and locale: ReadMore: 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 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: 3. Bypassing Specific Domains Use the bypass choice to exclude domains from proxy routing: Read More: 4. Handling Connection Failures Implement error handle for proxy connectivity issues: Also Read: For large-scale mechanisation, rotate proxies prevents detection and distributes load across multiple IP addresses. 1. Elementary Round-Robin Rotation let currentProxyIndex = 0; async function createContextWithRotatedProxy (browser) { return await browser.newContext ({ const browser = await chromium.launch (); 2. Random Proxy Selection const totalWeight = proxies.reduce ((sum, p) = & gt; sum + p.weight, 0); for (const placeholder of procurator) { const context = await browser.newContext ({ 3. Geographic Routing Strategy function getProxyForRegion (part) { const usContext = await browser.newContext ({ const euContext = await browser.newContext ({ 4. Time-Based Rotation getProxy () { const rotator = new ProxyRotator ([ const context = await browser.newContext ({ 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 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 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 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 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. 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: 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. Tool Comparisons: On This Page # Ask-and-Contributeabout this theme with our Discord community. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.Setting Up Proxies in Playwright in 2026
Overview
const {chromium} = require (& # 8216; playwright & # 8217;);
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 page = await context.newPage ();
await page.goto (& # 8216; https: //example.com & # 8217;); // Routed through placeholder
})();What Is a Proxy and Why Use One in Playwright?
How to Configure a Proxy in Playwright (Global Scope)
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;
}
});
await page.goto (& # 8216; https: //example.com & # 8217;);
})();2. HTTPS and SOCKS Proxies
// HTTPS proxyconst browser = await chromium.launch ({
proxy: {
waiter: & # 8216; https: //secure-proxy.example.com:8443 & # 8217;
}
});
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
const {chromium} = require (& # 8216; playwright & # 8217;);
(async () = & gt; {
const browser = await chromium.launch ();
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;);
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;);
})();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;
});Authenticating, Bypassing and Advanced Proxy Options
const browser = await chromium.launch ({proxy: {
server: & # 8216; http: //proxy.example.com:8080 & # 8217;,
username: & # 8216; proxy_user & # 8217;,
watchword: & # 8216; secure_password & # 8217;
}
});const browser = await chromium.launch ({proxy: {
waiter: process.env.PROXY_SERVER,
username: process.env.PROXY_USERNAME,
parole: process.env.PROXY_PASSWORD
}
});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;
}
});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
}
}Proxy Rotation and Dynamic Routing Strategies with Playwright
const proxies = [& # 8216; http: //proxy1.example.com:8080 & # 8217;,
& # 8216; http: //proxy2.example.com:8080 & # 8217;,
& # 8216; http: //proxy3.example.com:8080 & # 8217;
];
const proxy = proxies [currentProxyIndex];
currentProxyIndex = (currentProxyIndex + 1) % proxies.length;
proxy: {server: proxy}
});
}
const context1 = await createContextWithRotatedProxy (browser);
const context2 = await createContextWithRotatedProxy (browser);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}
];
let random = Math.random () * totalWeight;
if (random & lt; proxy.weight) return proxy.server;
random -= proxy.weight;
}
}
proxy: {server: getRandomProxy ()}
});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;]
};
const proxies = proxyPool [part];
return proxy [Math.floor (Math.random () * proxies.length)];
}
procurator: {server: getProxyForRegion (& # 8216; US & # 8217;)}
});
proxy: {server: getProxyForRegion (& # 8216; EU & # 8217;)}
});class ProxyRotator {
constructor (proxies, rotationIntervalMs = 300000) {
this.proxies = placeholder;
this.currentIndex = 0;
this.rotationInterval = rotationIntervalMs;
this.lastRotation = Date.now ();
}
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];
}
}
& # 8216; http: //proxy1.example.com:8080 & # 8217;,
& # 8216; http: //proxy2.example.com:8080 & # 8217;
], 300000);
proxy: {server: rotator.getProxy ()}
});Handling Corporate / Internal Network Proxies and Firewalls
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
});const browser = await chromium.launch ({procurator: {
server: process.env.HTTPS_PROXY || process.env.HTTP_PROXY
}
});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
}
});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;
});How to Test Proxy-Dependent Websites Across Browsers and Devices at Scale
Conclusion
Useful Resources for Playwright
Related Guides
Automate This With SUSA
Test Your App Autonomously