BlogGuide9 min read

Using a proxy with Selenium and Playwright

Both Selenium and Playwright accept a proxy, but the setting lives in different places and is easy to leak past. Set it for the scope you browse in, use the endpoint that matches the protocol, and verify the exit IP.

A browser window with a network panel open over a dark interface
Set the proxy for the scope you browse in, then check for leaks.

Both tools take a proxy, but in different places: Selenium through browser options, Playwright through the launch or context options. Set it for the scope you actually browse in, then confirm the exit IP, because a missed setting silently leaks your real address.

One rule covers most mistakes: the proxy must be set before the page loads, not after.

Selenium: set it in the options

For Chrome, the proxy goes in the browser options before the driver starts. Set the proxy type and the host and port, or pass a full proxy string. If you launch several drivers for several accounts, build the options fresh for each.

Selenium does not handle an authenticated HTTP proxy cleanly on its own. The common workaround is a small local relay that adds the credentials, or a browser extension that fills them in.

Playwright: set it per context

Playwright takes a proxy object with server, username, and password, either at launch or when you create a browser context. Setting it per context is the useful part: one context equals one identity equals one proxy.

That maps cleanly onto account work, where each profile should sit behind its own IP. See proxies and anti-detect browsers.

Match the protocol to the tool

Browsers want the HTTP endpoint. If a tool offers a SOCKS5 field, use the SOCKS5 endpoint instead. Crossing the two produces an instant, confusing failure. The host and ports are in the documentation.

Check for leaks

Run these after any change. A proxy that is set can still leak over a second path.

  1. Load an IP-check page and confirm the address matches your dashboard.
  2. Run a WebRTC leak test; a browser can expose the real IP over WebRTC even when the proxy is set.
  3. Confirm DNS resolves through the proxy when you need it to.
  4. Recheck after any options change, because a default launch resets the proxy.

Keep one context per identity

Playwright contexts share nothing by default: separate cookies, storage, and cache. Pair one context with one proxy per account, and you isolate both the network and the session. Other automation stacks, described in dedicated 4G proxy for browser automation, follow the same pattern.

Does Selenium support proxy authentication?

Not cleanly for HTTP proxies. Most teams use a local relay that adds credentials, or a browser extension. Playwright handles username and password directly.

Why does my real IP still show?

A missed proxy setting, or a WebRTC leak. Set the proxy for the scope you browse in and run a WebRTC leak test after every change.

Should I use HTTP or SOCKS5 for browsers?

Use the HTTP endpoint for browsers. SOCKS5 is for apps and tools that ask for it.

Can I run one proxy per browser context?

Yes in Playwright, which is why it suits multi-account work. Set the proxy when you create each context.