Configuring Proxies in Headless Browsers: Playwright, Puppeteer and Selenium
You get a headless browser script working on your laptop, then move it to a cloud server and things start going a bit strange. Prices show up in the wrong currency and some regional pages never load, so the results end up depending on where that server happens to sit.
That’s usually because every request now leaves from one data center IP, and most tutorials stop right after browser.launch() without ever mentioning proxies. Each framework handles proxy setup a little differently, and you usually only find out when something fails late at night.
So here is how Playwright, Puppeteer and Selenium each handle it, one by one.
Pick the proxy type before you write any code
A headless browser is still a full browser, so it runs JavaScript and keeps cookies, and it opens a lot of connections for every page. A typical news page can fire somewhere between 80 and 150 requests, and every one of them goes through your proxy.
The first thing to decide is the protocol. HTTP proxies are what most docs assume, and they’re fine for normal web traffic and simple scraping jobs.
SOCKS5 sits a bit lower down and can relay pretty much any TCP connection, so it tends to suit test suites that also use WebSockets or other services that aren’t plain HTTP. If you’re doing QA for specific countries, it’s common to pair it with socks5 residential proxies so the browser loads pages the same way a local visitor would see them. The protocol is pretty old by the way, and the SOCKS standard was published as RFC 1928 back in 1996, with username and password login added later in RFC 1929.
One thing catches a lot of people out here. Chromium doesn’t support username and password login for SOCKS5 proxies, so if your SOCKS endpoint needs credentials you’ll usually have to use IP allowlisting or run a small local forwarder in front of the browser. If that forwarder ends up on a Linux server, a handful of Linux command line shortcuts, like reverse history search with Ctrl+R, will save you a lot of retyping while you tweak the config.
Setting up a proxy in Playwright
Playwright is probably the easiest of the three, because the proxy is just one of the normal launch options. You pass in an object with server, username and password, and it deals with the login step for HTTP(S) proxies by itself.
You can also set the proxy on each browser context instead of the whole browser. The official Playwright network guide shows both ways of doing it, plus a bypass list for hosts that should skip the proxy.
Per-context proxies are really handy, because one Chromium process can run 10 separate contexts, each with its own exit IP and its own cookies, which uses far less memory than 10 browsers and saves you a good chunk of server cost. So if your test matrix covers Germany, Japan and Brazil, you basically need three contexts and one launch. If you run a headed Chrome session to see the difference yourself, the Shift+Esc Chrome Task Manager shortcut (Windows and Linux) shows the memory used by each process, which makes the comparison quick.
Setting up a proxy in Puppeteer
Puppeteer leans on Chrome’s command line switches. You add the proxy-server switch (with its usual double-dash prefix, set to your host and port) to the args array, and it applies to the whole browser.
Login details go in a separate page.authenticate({ username, password }) call before the first navigation. If you forget it, Chrome comes back with a 407 error, which looks a lot like a dead proxy even though it’s fine.
For different IPs per tab, recent Puppeteer versions accept a proxyServer option in createBrowserContext(), so it’s much closer to Playwright than it was in 2021.
It also helps to know which headless mode you’re running. Since Chrome 112 the new headless mode shares its code with regular Chrome, and the old one now ships separately as chrome-headless-shell, as the Chrome for Developers headless docs explain. Proxy behavior can differ a bit between the two, so it’s worth pinning one in CI.
Since you’re already working with Chrome’s switches, it also helps to know that the browser has a set of lesser-known debugging keyboard shortcuts that make troubleshooting a failing proxy session quicker.
Setting up a proxy in Selenium
Selenium lets you set a proxy through a Proxy object or by adding the same proxy-server switch to ChromeOptions. Both work across the main languages, which is partly why big QA teams still stick with it. Chrome also keeps a list of experimental options behind chrome://flags, one of the better hidden features in the browser, so check it before you depend on a switch in a test.
Proxy login is the awkward part, because WebDriver has no native way to answer that prompt. Most teams use IP allowlisting or a local proxy that adds the credentials, although the BiDi network APIs in Selenium 4 can handle it too.
Allowlisting breaks least often. It keeps passwords out of your test code and doesn’t stop working when Chrome changes how extensions load.
Wrapping up
The three tools are slowly getting more alike. Playwright’s per-context setup pushed Puppeteer to add something similar, and WebDriver BiDi should give Selenium proper network control over the next few releases.
And the day-to-day side probably won’t change much. It helps to choose the protocol first, test the proxy login early and keep the settings in a config file, because then switching frameworks later is usually a fairly small job that costs you an hour instead of a week.








