DEV Community

Cover image for Playwright proxy setup: scopes, auth, SOCKS5, rotation and timezone
Andrew
Andrew

Posted on Originally published at proxymint.com

Playwright proxy setup: scopes, auth, SOCKS5, rotation and timezone

Originally published on proxymint.

Set a Playwright proxy per browser, per context or in playwright.config. Fix 407 and SOCKS5 auth errors, rotate by context, and set timezone for geo-QA.

TL;DR

  • Playwright takes a proxy per browser, per context or per page. launch() covers every context in the browser, newContext() gives one isolated identity its own exit, and browser.newPage() with a proxy works because it creates a one-page context.
  • Credentials inside the server URL are dropped. Playwright cuts the server down to scheme, host and port, so user:pass@ never reaches the proxy. Plain HTTP pages get a 407 and HTTPS pages fail the tunnel.
  • SOCKS with credentials never launches. A socks5 server with a username throws 'Browser does not support socks5 proxy authentication', and socks4 throws its own error, in Chromium and Firefox alike.
  • The browser keeps the host's clock, locale and WebRTC path. timezoneId, locale and geolocation have to be set per context, and WebRTC can send UDP around an HTTP proxy unless Chromium is told not to.
  • Chromium allows 32 simultaneous connections through an HTTP/1.1 proxy. Heavy parallel work can queue inside the browser before the proxy ever sees it.

Key takeaways

  • Give each identity its own context. Rotate by closing the context and opening a new one on a fresh sticky session, so the IP, cookies and cache change together.
  • Load credentials from the environment. Keep username and password in their own fields, read them from process.env or os.environ, and never commit them in playwright.config.
  • Probe the exit before building the context. Look up the exit through the same sticky session, set timezoneId and geolocation from the answer, pick locale for the market, and assert the match before real work.
  • Add the WebRTC policy flag when pages can open peer connections. Launching Chromium with disable_non_proxied_udp keeps UDP from leaving outside the proxy.
  • Block heavy assets before picking a tier. Aborting images, fonts and video with context.route cuts the bytes a per-GB tier bills for.

Read the full guide on proxymint, with the commands, tables and sources.

Top comments (0)