Socks5Proxy

Playwright proxy setup: Unique IPs per browser and context

This guide explains configuring Playwright with Socks5Proxy HTTP/SOCKS5 proxies (server/username/password) and multi-IP browsing via contexts in Node.js/Python.

What's the easiest Playwright proxy setup?

Playwright accepts proxy addresses and credentials in one proxy option, eliminating separate auth handling. Works consistently across Chromium, Firefox, and WebKit.

You can also assign different proxies per context when running multiple contexts in one browser. Contexts are isolated profiles with separate cookies/storage, enabling multiple IPs/sessions while saving memory.

The example uses IP 198.51.100.23, HTTP port 8000, SOCKS5 port 1080, username spx_user, and password spx_pass.

npm install playwright
npx playwright install chromium

How to set HTTP proxy for the entire browser?

Add server, username, and password to the proxy option in launch, and all pages in that browser will use the same proxy. HTTPS sites are passed through an encrypted CONNECT tunnel.

import { chromium } from "playwright";

const browser = await chromium.launch({
  proxy: { server: "http://198.51.100.23:8000", username: "spx_user", password: "spx_pass" },
});
const page = await browser.newPage();
await page.goto("https://api.ipify.org");
console.log(await page.textContent("body")); // proxy IP
await browser.close();

How to use different IPs per context?

Add the proxy option to newContext, and only that context will use the proxy. The code below fetches the list via API, creates three contexts with different IPs, and prints the IP visible in each context. For handling multiple accounts simultaneously, pair one account with one IP in each context.

Some Chromium versions on Windows require proxy settings in both launch and context for per-context proxies. Set the first proxy at launch, then override per context.

import { chromium } from "playwright";

const KEY = "YOUR_API_KEY";
const res = await fetch("https://socks5proxy.io/api/v1/proxies/download?format=ip:port:user:pass&protocol=http", {
  headers: { Authorization: "Bearer " + KEY },
});
const lines = (await res.text()).trim().split("\n").slice(0, 3);

const browser = await chromium.launch();
for (const line of lines) {
  const [ip, port, user, pass] = line.trim().split(":");
  const context = await browser.newContext({
    proxy: { server: "http://" + ip + ":" + port, username: user, password: pass },
    locale: "en-US",
  });
  const page = await context.newPage();
  await page.goto("https://api.ipify.org");
  console.log(ip, await page.textContent("body"));
  await context.close();
}
await browser.close();

How do I use SOCKS5 proxies?

Use socks5:// address in the server. Chromium doesn’t support SOCKS5 proxy username/password authentication, so we recommend connecting with IP authorization. Register the IPv4 of the execution server in the dashboard and use only the server without username and password.

If you need to connect with a username and password, use the HTTP port of the same IP. The IP and location seen by the target site remain the same.

import { chromium } from "playwright";

const browser = await chromium.launch({
  proxy: { server: "socks5://198.51.100.23:1080" }, // server IP is authorized in the dashboard
});
const page = await browser.newPage();
await page.goto("https://api.ipify.org");
console.log(await page.textContent("body"));
await browser.close();

How to use in Python?

Playwright for Python follows the same structure - proxy dictionary with server, username, password. Synchronous example below (async uses same option names).

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch(proxy={
        "server": "http://198.51.100.23:8000",
        "username": "spx_user",
        "password": "spx_pass",
    })
    page = browser.new_page()
    page.goto("https://api.ipify.org")
    print(page.text_content("body"))
    browser.close()

What needs to align to make results appear as if from users in that country?

Set context locale and timezoneId to render pages with local language and time for your proxy's country (e.g., de-DE locale with Europe/Berlin timezone for German IPs).

Use page.route to block unnecessary media requests and save bandwidth/time. Particularly helpful for shared plans with monthly bandwidth limits.

  • Set locale and timezoneId to match the IP country
  • One context = one account, one IP
  • Block unnecessary image/video requests with page.route
  • SOCKS5 supports IP authorization; username/password works on HTTP port

How can I automate downloading and splitting lists for different tasks?

GET /proxies returns JSON with IP, port, and country. Filter by country for targeted lists. This example creates contexts for US proxies matching job counts (field names are in API docs).

For multiple tasks, close contexts when done to free memory.

import { chromium } from "playwright";

const KEY = "YOUR_API_KEY";
const res = await fetch("https://socks5proxy.io/api/v1/proxies?country=us&protocol=http", {
  headers: { Authorization: "Bearer " + KEY },
});
const { proxies } = await res.json();

const browser = await chromium.launch();
for (const p of proxies.slice(0, 5)) {
  const context = await browser.newContext({
    proxy: { server: "http://" + p.host + ":" + p.http_port, username: p.username, password: p.password },
    locale: "en-US",
    timezoneId: "America/New_York",
  });
  const page = await context.newPage();
  await page.goto("https://api.ipify.org");
  console.log(await page.textContent("body"));
  await context.close();
}
await browser.close();

How to conserve bandwidth by blocking unneeded requests?

Blocking image, font, and video requests with page.route or context.route speeds up page loading and saves proxy bandwidth. This is especially effective for data-only collection tasks.

await context.route("**/*", (route) => {
  const type = route.request().resourceType();
  return ["image", "font", "media"].includes(type) ? route.abort() : route.continue();
});

Do Firefox and WebKit use the same proxy?

Yes. Playwright accepts the same proxy options across all three browsers. Test teams can sequentially launch Chromium/Firefox/WebKit with one proxy to verify consistent regional views.

Like Chromium, Firefox doesn't natively support SOCKS5 username/password auth - use IP authorization. HTTP ports support username/password auth in all browsers.

With Playwright Test, configure proxy in playwright.config's 'use' section for all tests, or organize projects by country with different proxies.

import { defineConfig } from "@playwright/test";

export default defineConfig({
  projects: [
    { name: "us", use: { locale: "en-US", proxy: { server: "http://198.51.100.23:8000", username: "spx_user", password: "spx_pass" } } },
    { name: "de", use: { locale: "de-DE", proxy: { server: "http://198.51.100.24:8000", username: "spx_user", password: "spx_pass" } } },
  ],
});

How do I resolve frequent errors?

net::ERR_PROXY_CONNECTION_FAILED occurs when the server address or port is incorrect. For 407 or authentication errors, check username and password values. 'Browser does not support socks5 proxy authentication' error appears when using SOCKS5 with username and password. Switch to IP authorization or use the HTTP port.

Playwright proxy setup: Per-browser/context IPs | Socks5Proxy