Skip to content
PhantomProxies

Integration

Playwright Proxy Setup: Python & Node.js

To use an authenticated proxy in Playwright, set the HTTP gateway as proxy.server and pass proxy.username and proxy.password separately when launching the browser. This works in both Python and Node.js. Keep the credentials in server-side environment variables and verify the exit IP before testing a full page.

By PhantomProxiesLast updated October 28, 20268 min read

How do you configure a Playwright proxy in Node.js?

Pass the HTTP gateway URL as server, with the username and generated password in their own fields. Install Playwright and its Chromium browser, then set PROXY_SERVER to http://HOST:HTTP_PORT and set PROXY_USERNAME and PROXY_PASSWORD from the dashboard. Do not include credentials inside PROXY_SERVER.

javascript
import { chromium } from "playwright";

const { PROXY_SERVER, PROXY_USERNAME, PROXY_PASSWORD } = process.env;
if (!PROXY_SERVER || !PROXY_USERNAME || !PROXY_PASSWORD) {
  throw new Error("Set all three proxy environment variables");
}

const browser = await chromium.launch({
  proxy: {
    server: PROXY_SERVER,
    username: PROXY_USERNAME,
    password: PROXY_PASSWORD,
  },
});

try {
  const page = await browser.newPage();
  await page.goto("https://api.ipify.org?format=json", {
    waitUntil: "domcontentloaded",
    timeout: 30_000,
  });
  console.log(await page.textContent("body"));
} finally {
  await browser.close();
}

How do you configure a Playwright proxy in Python?

Use the same server, username, and password fields in Python's browser launch options. Install the Python Playwright package and its Chromium browser first, then provide the three environment variables. Use the original username and password values rather than URL-encoding these separate fields.

python
import os
from playwright.sync_api import sync_playwright

proxy = {
    "server": os.environ["PROXY_SERVER"],
    "username": os.environ["PROXY_USERNAME"],
    "password": os.environ["PROXY_PASSWORD"],
}

with sync_playwright() as playwright:
    browser = playwright.chromium.launch(proxy=proxy)
    try:
        page = browser.new_page()
        page.goto(
            "https://api.ipify.org?format=json",
            wait_until="domcontentloaded",
            timeout=30_000,
        )
        print(page.locator("body").inner_text())
    finally:
        browser.close()

Why does authenticated SOCKS5 fail in Chromium?

Playwright supports HTTP and SOCKS proxy servers, but its username and password options are documented for HTTP proxies. Chromium can reject SOCKS5 proxy authentication even when those credentials work in another client.

For PhantomProxies browser automation, use the authenticated HTTP(S) gateway and its HTTP port. Do not swap in the SOCKS5 port or repeatedly rotate a working password to address a browser compatibility error.

Choose rotation before launch

Use the dashboard generator to create the password configuration. For a sticky browser journey, keep the same generated password for that browser context. For independent checks, use separate generated lines or rotating mode.

Control page weight

A real browser loads more than HTML. Fonts, images, scripts, and media all contribute to proxy bandwidth. If a legitimate test does not require heavy asset types, block them explicitly and confirm that doing so does not change the behavior being measured.

javascript
await page.route("**/*", async (route) => {
  const type = route.request().resourceType();
  if (["image", "media", "font"].includes(type)) {
    await route.abort();
  } else {
    await route.continue();
  }
});

Debug in layers

First test the same credentials with cURL. If cURL works, verify the Playwright endpoint syntax and environment variables. If the route works but the destination rejects it, that is a destination response rather than a proxy authentication failure.

Sources and further reading