Playwright Node.js Proxy Setup for Rotating Proxies
You configure a proxy in Playwright Node.js through the launch or context options, using the gateway host and port with your proxy user's username and password. This guide covers HTTP and SOCKS5 setup, geo-targeting, session management, and troubleshooting for reliable browser automation.
- Set proxy via `launch` or `context` options with host, port, username, and password.
- Use port 7070 for HTTP/HTTPS and 7071 for SOCKS5 connections.
- Target countries, US states, and cities by adding options to the username.
- Keep the same IP with a session ID and TTL for multi-page workflows.
Playwright Node.js Proxy Settings Location
Playwright for Node.js accepts proxy configuration in two places: globally when launching a browser instance, or locally when creating a new browser context. The global method applies the proxy to all pages in that browser, while the per-context method allows different proxies for different tasks within the same browser process. For most web scraping and price monitoring workflows, setting the proxy at the context level offers better isolation and flexibility.
HTTP Proxy Setup on Port 7070
To route traffic through the HTTP proxy gateway, use port 7070 and specify the server, username, and password in the launch or context options. The following example creates a Chromium browser with a proxy applied to its default context. Remember to swap USERNAME and PASSWORD with your real proxy user details, which can contain targeting options.
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch({
proxy: {
server: 'http://gw.rotatingproxy.cc:7070',
username: 'USERNAME_net.res_cc.us',
password: 'PASSWORD'
}
});
const context = await browser.newContext();
const page = await context.newPage();
await page.goto('https://example.com');
// Your interaction code here
await browser.close();
})();
This configuration sends all HTTP and HTTPS traffic from this browser through the gateway. The username USERNAME_net.res_cc.us tells the gateway to use the rotating residential network and exit in the United States. You can target a city like Chicago by using USERNAME_net.res_cc.us_city.chicago. For a detailed explanation of all username options, see the username options documentation.
SOCKS5 Proxy Setup on Port 7071
Playwright also supports SOCKS5 proxies, which you can use by connecting to port 7071 on the same gateway. The setup is identical to the HTTP proxy, only the port in the server string changes. This is useful if your network environment or target site interacts better with SOCKS5.
const { firefox } = require('playwright');
(async () => {
const browser = await firefox.launch({
proxy: {
server: 'socks5://gw.rotatingproxy.cc:7071',
username: 'USERNAME_net.mob_cc.de',
password: 'PASSWORD'
}
});
const context = await browser.newContext();
const page = await context.newPage();
await page.goto('https://example.com');
await browser.close();
})();
In this example, we use the Firefox browser with a SOCKS5 proxy to get a rotating mobile IP from Germany. For a comparison of when to use each port, read our guide on HTTP vs SOCKS5 ports.
Per-Context Proxy Configuration
Creating a proxy for each browser context, rather than at launch, allows you to run multiple parallel sessions with different IPs or locations. This is essential for tasks like SEO rank tracking across regions or social media management. You create a context with its own proxy settings using browser.newContext(options).
const { chromium } = require('playwright');
(async () => {
// Launch browser without a global proxy
const browser = await chromium.launch();
// Context 1: Residential proxy in France
const context1 = await browser.newContext({
proxy: {
server: 'http://gw.rotatingproxy.cc:7070',
username: 'USERNAME_net.res_cc.fr',
password: 'PASSWORD'
}
});
const page1 = await context1.newPage();
// Context 2: Mobile proxy in Japan
const context2 = await browser.newContext({
proxy: {
server: 'http://gw.rotatingproxy.cc:7070',
username: 'USERNAME_net.mob_cc.jp',
password: 'PASSWORD'
}
});
const page2 = await context2.newPage();
// Use pages concurrently
await Promise.all([
page1.goto('https://httpbin.org/ip'),
page2.goto('https://httpbin.org/ip')
]);
await browser.close();
})();
Each context maintains its own cookie jar, local storage, and proxy connection. When the context is closed, its proxy session ends. For managing state across multiple pages, you should use sticky sessions.
Targeting Countries, States, and Cities
Geo-targeting is controlled entirely through the username string. Append options like cc.us for the United States, st.ca for California, and city.los-angeles for Los Angeles. The gateway interprets these options and picks an IP from the chosen location. Available cities are listed in the dashboard's location tool; if your desired city isn't listed, see what if my city is not listed.
For example, to scrape Zillow proxies with a residential IP from Seattle, your username would look like yourlogin_net.res_cc.us_city.seattle. To monitor Booking.com proxies with a mobile IP in London, use yourlogin_net.mob_cc.gb_city.london. You can combine a network, country, and city, but you cannot target a specific carrier or ASN.
Using Sticky Sessions for Multi-Page Workflows
A sticky session keeps the same exit IP for a defined period, which is crucial for workflows that span multiple pages or require logged-in state. You create a sticky session by adding a sid (session ID) and an optional ttl (time-to-live in minutes) to the username. The same IP will be reused for any connection using that session ID within the TTL window.
const username = 'USERNAME_net.res_cc.us_sid.abc123_ttl.30';
const proxyConfig = {
server: 'http://gw.rotatingproxy.cc:7070',
username: username,
password: 'PASSWORD'
};
const browser = await chromium.launch({ proxy: proxyConfig });
const context = await browser.newContext();
const page1 = await context.newPage();
await page1.goto('https://example.com/login');
// ... perform login
// Opening a new page in the same context will use the same proxy connection and IP.
const page2 = await context.newPage();
await page2.goto('https://example.com/dashboard');
If you need to maintain the same IP across different browser instances or processes, use the exact same session ID in the username for each.
Verifying the Exit IP and Location
After setting up the proxy, verify that your traffic is exiting from the expected IP and location. You can do this by navigating to a service that returns your IP address. A simple way is to evaluate JavaScript on the page that fetches from an IP API.
const page = await context.newPage();
await page.goto('https://api.ipify.org?format=json');
const ipText = await page.textContent('body');
console.log('Exit IP:', ipText);
// For more details like location, use ipinfo.io
await page.goto('https://ipinfo.io/json');
const geoInfo = await page.textContent('body');
console.log('Geo info:', geoInfo);
If the IP does not match your targeted country, double-check the country code in the username and ensure your proxy user is allowed to use the chosen network. For a list of tools to check your IP, visit IP check tools.
Common Proxy Errors and Fixes
Playwright may throw errors or pages may fail to load when the proxy configuration is incorrect. Here are the most common issues and their solutions.
Error 407 (Proxy Authentication Required)
This error means your username or password was not accepted by the gateway. Check that the username string is correctly formatted with underscores between options, and that the password is exact. Ensure your account has a positive balance; traffic stops if the balance reaches zero. For more, see proxy error 407.
Timeouts or Slow Page Loads
Timeouts can happen because of network lag, a slow exit IP, or an unresponsive target site. Increase Playwright's timeout settings for navigation and actions. You can also add a retry routine to your own code. If timeouts are persistent, try switching to a different proxy network (e.g., from residential to ISP for faster speeds) or a different location. Our guide on retry strategies offers practical patterns.
TLS/SSL Certificate Errors
Playwright browsers are configured to trust the gateway's TLS certificates. If you encounter a certificate error, it is likely not related to the proxy but to the target site. You can bypass certificate errors for testing by setting ignoreHTTPSErrors: true in the browser launch or context options, but this reduces security.
Tips for Running Playwright at Scale
When automating many browsers or pages concurrently, manage your resources and proxy usage carefully to stay within limits and control costs.
- Concurrency Limits: Your account supports up to 1,000 concurrent connections across all proxy users. Distribute sessions across multiple proxy users to organize traffic, and consider using a connection pool pattern. Read about concurrency limits.
- Proxy User Management: Create separate proxy users for different tasks or teams. You can set a monthly GB cap on each user to prevent unexpected usage. Learn how in setting a monthly GB cap.
- Traffic Estimation: Browser automation consumes more bandwidth than simple HTTP requests due to images, CSS, and JavaScript. Use Playwright's ability to block unnecessary resources (like images and fonts) to reduce traffic.
- Session Lifecycle: Always close browsers and contexts when done to free up connections. For long-running tasks, monitor your balance via the API to avoid interruptions.
- Location Strategy: For global geo-content testing, cycle through a list of country codes in your usernames. Use the dashboard's location list to get available codes.
For large-scale market research or AI training data collection, consider splitting workloads across multiple machines, each with its own set of proxy users and browser instances. Always follow the target site's robots.txt and add polite pauses between requests.
Integrating with Other Tools
Your Playwright scripts can be part of a larger system. You might use the RotatingProxy REST API to check your balance before starting a job, or to programmatically create new proxy users for a distributed crawler. The authentication for the API is a separate Bearer token, not your proxy password. For other integration methods, see our guides for Puppeteer proxy and Selenium proxy with authentication.
Questions
Can I use a different proxy for each tab in Playwright?
No, Playwright's proxy setting is bound to a browser context, not individual tabs. All pages within a context share the same proxy connection. To use different proxies concurrently, create separate browser contexts, each with its own proxy configuration.
Does Playwright support proxy rotation on every request?
Playwright itself does not rotate proxies per request. To get a new IP on each page or request, you must create a new browser context without a session ID (sid) in the username. Each new context will receive a fresh IP from the gateway's pool for the targeted location.
Why is my Playwright script not using the proxy I set?
First, verify the proxy is correctly set in the launch or context options. Second, ensure you are not setting a system-level proxy that might interfere. Third, test with a simple IP check page to confirm the exit IP. If it still shows your local IP, the proxy configuration was not applied.
How do I handle CAPTCHAs when using proxies with Playwright?
Proxies can increase the likelihood of encountering CAPTCHAs. While RotatingProxy provides clean IPs, you should implement best practices: mimic human behavior with realistic delays, use persistent sessions (sticky IPs) where appropriate, and rotate user agents. For insights, read our guide on why CAPTCHAs appear.
Can I use the SOCKS5 proxy for WebSocket connections in Playwright?
Yes, when you configure a SOCKS5 proxy at the browser launch or context level, it applies to all traffic from that instance, including WebSocket connections used for DevTools protocol or live web applications. Use port 7071 and the socks5:// scheme in the server string.
My script works without a proxy but times out with the proxy. What should I do?
Increase the default timeout settings in Playwright (e.g., `navigationTimeout`, `actionTimeout`). If timeouts persist, the issue may be network latency to the chosen proxy location. Try targeting a location geographically closer to your server, or switch to a faster network like datacenter or ISP proxies for that task.
Start with one top-up, use any network
Create an account in a minute, add $40 or more, and the same balance pays for residential, mobile, datacenter and ISP traffic.