Skip to content

Browser automation behind a proxy: Selenium, Playwright and Puppeteer

By the ProxyOnly team · 16 Nov 2026 · 5 min read

How to run Playwright, Puppeteer and Selenium behind proxies: logins, one context per proxy, matching the browser's language and time zone to the exit, and blocking images to cut proxy traffic.

Driving a browser through a proxy takes more than one setting. The proxy needs a login that browsers handle awkwardly. Each proxy needs its own browser session so that cookies do not link them. The browser's language and time zone should match the country of the exit address. And a browser downloads far more than a script, which matters when proxy traffic costs money.

This guide covers those four things with tested code. We ran it on 16 November 2026 with Playwright 1.65 for Python and Node.js and Puppeteer 25.17, driving Chrome 157 through test proxies on our own machine. To decide which tool to use in the first place, read Playwright vs Selenium vs Puppeteer.

Rule one: one session per proxy

A static proxy gives you one address for the whole rental period. To work through several addresses, give each its own browser context, which is Playwright's name for an isolated session with its own cookies, storage and proxy. In Puppeteer the proxy belongs to the whole browser, so each proxy needs its own browser launch.

This Python script opens one context per proxy, the first with a login and the second without, and loads a page through each.

from playwright.sync_api import sync_playwright
CHROME = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
PROXIES = [
    {"server": "http://127.0.0.1:8101", "username": "demo", "password": "s3cret"},
    {"server": "http://127.0.0.1:8104"},
]
with sync_playwright() as p:
    browser = p.chromium.launch(executable_path=CHROME)
    for number, proxy in enumerate(PROXIES, start=1):
        context = browser.new_context(proxy=proxy, locale="en-GB", timezone_id="Europe/London")
        page = context.new_page()
        page.goto("https://quotes.toscrape.com/")
        print(number, proxy["server"], page.locator(".quote").count(), "quotes")
        context.close()
    browser.close()
1 http://127.0.0.1:8101 10 quotes
2 http://127.0.0.1:8104 10 quotes

Each test proxy logged its own tunnel to quotes.toscrape.com, so each context used its own. With your proxies, put the host and port from your order page in server and the login in username and password. We pointed executable_path at an installed Chrome. Without it, Playwright uses the browsers it installs with playwright install.

Rule two: give the browser a login it can use

Chrome will not take a username and password inside its proxy setting. In our tests a proxy address with the login in it failed with net::ERR_NO_SUPPORTED_PROXIES. The tools handle it differently.

  • Playwright: pass username and password in the proxy option, as above. It worked for HTTP proxies. For SOCKS5 with a login, Playwright refused at launch with Browser does not support socks5 proxy authentication.
  • Puppeteer: pass the proxy address with --proxy-server and call page.authenticate({ username, password }) on each page. Our comparison has the tested script.
  • Selenium: Chrome's --proxy-server argument works for proxies without a login. With a login, the usual routes are an IP allowlist with your provider, a small local proxy that adds the login before forwarding, or a browser extension that answers the login prompt. We did not run Selenium for this guide.

Rule three: match the browser to the exit

A German address with a browser that says it is in New York and prefers English is an odd combination, and sites that adapt to location may show inconsistent results. Playwright sets the language and time zone per context. We created a context with a proxy, locale: "de-DE" and timezoneId: "Europe/Berlin", and read what a site would see.

const de = await browser.newContext({
  proxy: { server: "http://127.0.0.1:8101", username: "demo", password: "s3cret" },
  locale: "de-DE",
  timezoneId: "Europe/Berlin",
});
de context: { acceptLanguage: 'de-DE', timeZone: 'Europe/Berlin', navigatorLanguage: 'de-DE' }

The Accept-Language header, the JavaScript time zone and navigator.language all followed the settings. Pick values that match the country you ordered. Choosing a proxy location explains why the rest of the picture matters, and IP geolocation explains how sites decide where you are.

Rule four: do not pay to download images you do not need

A browser fetches every image, font and video on a page. Through a proxy billed by traffic, that is money spent on bytes you throw away. Playwright can refuse those requests before they leave the browser.

await page.route("**/*", (route) =>
  ["image", "font", "media"].includes(route.request().resourceType()) ? route.abort() : route.continue(),
);

We loaded the front page of books.toscrape.com through a test proxy with and without this rule, and counted the finished requests and their size.

books.toscrape.com, everything:      { requests: 30, kilobytes: 329 }
books.toscrape.com, no images/fonts: { requests: 9, kilobytes: 109 }

Blocking cut the requests from 30 to 9 and the data by about two thirds, and the text and links on the page were all still there. Leave images on when the job needs them, such as checking how ads or product photos render. Puppeteer can do the same with page.setRequestInterception(true).

Check the exit before you trust it

Before a long run, open an IP echo page in each context, such as httpbin.org/ip or our what is my IP address tool, and compare the address and country with what you ordered. Also check that WebRTC does not reveal your own address, as DNS and WebRTC leaks explains. A browser can leak in ways a script cannot.

What a proxy does not hide

A proxy changes the address. It does not hide that a browser is automated. In our tests both Playwright and Puppeteer reported navigator.webdriver as true and sent HeadlessChrome in the user agent. Browser fingerprinting covers the other signals. If a site does not want automated visitors, the right answer is its API or its permission, not disguise.

Questions people ask

Can Playwright change the proxy for each request?

Not within one context. The proxy belongs to the browser or to a context, so to change it you open a new context with a different proxy, as the first script does. Contexts are cheap, so one per proxy is the normal pattern.

How many contexts can one browser run?

It depends on memory more than on the tool. Each context with an open page holds its own copy of the page in memory. Start with a few, watch memory, and close contexts when their work is done.

Should the browser run headless?

Headless is faster and uses less memory, and it is fine for most data collection. It is also easier for a site to recognise, as the user agent test showed, so a site that blocks automation will usually notice either way.

If something fails

  • net::ERR_PROXY_CONNECTION_FAILED: the browser could not reach the proxy. Check the host and port.
  • net::ERR_TUNNEL_CONNECTION_FAILED: the proxy refused the tunnel.
  • net::ERR_INVALID_AUTH_CREDENTIALS: the login was missing or rejected.

Every common proxy error lists what each tool prints for each failure, and our setup guides for Playwright with Python, Playwright with Node.js, Puppeteer and Selenium cover the settings in short form.

Try it yourself

Create an account, add funds from US$1 and order a proxy in the country you need.

Keep reading