Proxies That Work logo
Back to GuidesSetting up proxy rotation with Puppeteer and Playwright

Setting up proxy rotation with Puppeteer and Playwright

If you're automating browser tasks like scraping, testing, or monitoring, tools like Puppeteer and Playwright are some of the most powerful options available. But if you don't rotate proxies, you risk IP bans, rate-limiting, or incorrect results.

This guide walks you through how to set up proxy rotation in both Puppeteer (Node.js) and Playwright (Node.js and Python).

Why Rotate Proxies?

Websites often detect and block repeated requests from the same IP address. Rotating your proxies helps:

  • Avoid CAPTCHAs and bans
  • Mimic real user traffic
  • Improve the reliability of large-scale scraping or testing

1. Proxy Rotation with Puppeteer (Node.js)

Install Puppeteer

npm install puppeteer

Example: Launching with a Single Proxy

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch({
    args: ['--proxy-server=http://proxy_ip:port']
  });
  const page = await browser.newPage();
  await page.goto('https://api.ipify.org');
  console.log(await page.content());
  await browser.close();
})();

Rotate Proxies from a List

const proxyList = [
  'http://proxy1:port',
  'http://proxy2:port',
  'http://proxy3:port'
];

const getRandomProxy = () => proxyList[Math.floor(Math.random() * proxyList.length)];

(async () => {
  const proxy = getRandomProxy();
  const browser = await puppeteer.launch({
    args: [`--proxy-server=${proxy}`]
  });
  const page = await browser.newPage();
  await page.goto('https://httpbin.org/ip');
  const body = await page.content();
  console.log(body);
  await browser.close();
})();

2. Proxy Rotation with Playwright (Node.js)

Install Playwright

npm install @playwright/test

Rotate Proxies

const { chromium } = require('playwright');


const proxyList = [
  'http://proxy1:port',
  'http://proxy2:port',
  'http://proxy3:port'
];

const getRandomProxy = () => proxyList[Math.floor(Math.random() * proxyList.length)];

(async () => {
  const proxy = getRandomProxy();
  const browser = await chromium.launch({
    proxy: {
      server: proxy
    }
  });
  const context = await browser.newContext();
  const page = await context.newPage();
  await page.goto('https://api.ipify.org');
  console.log(await page.textContent('body'));
  await browser.close();
})();

3. Proxy Rotation with Playwright (Python)

Install Playwright

pip install playwright
playwright install

Rotate Proxies

import random
from playwright.sync_api import sync_playwright

proxy_list = [
    'http://proxy1:port',
    'http://proxy2:port',
    'http://proxy3:port'
]

proxy = random.choice(proxy_list)

with sync_playwright() as p:
    browser = p.chromium.launch(proxy={"server": proxy})
    context = browser.new_context()
    page = context.new_page()
    page.goto("https://api.ipify.org")
    print(page.text_content("body"))
    browser.close()

Best Practices

  1. Rotate on each session: Create a new browser instance with a different proxy per task.
  2. Limit parallel sessions per IP: Avoid overusing a single proxy to prevent bans.
  3. Monitor for bans: Check responses for anomalies and rotate if needed.
  4. Keep timeouts and delays realistic: Use setTimeout or time.sleep() to avoid detection.

Final Thoughts

Rotating proxies in Puppeteer and Playwright is straightforward but powerful. With the right setup, you can scale browser automation tasks while staying under the radar.

Always ensure your IP is whitelisted in your ProxiesThatWork dashboard before you begin. And if you run into issues, check out our troubleshooting guide or reach out to support for assistance.

ProxiesThatWork Team

ProxiesThatWork Team

Proxies That Work logo
© 2025 ProxiesThatWork LLC. All Rights Reserved.