Skip to content
Hopmind

Guides

How to set up a proxy in Playwright (Node.js and Python)

The proxy option in Playwright's launch and browser context for Node.js and Python: an HTTP proxy with a login and password.

What you need

The proxy is issued in the format host:port:login:password. Replace HOST, PORT, LOGIN and PASSWORD with your own values. Install Playwright and a browser for it.

Node.js.
npm install playwright
npx playwright install chromium
Python.
pip install playwright
playwright install chromium

Example

Node.js: the file ip.mjs.
import { chromium } from "playwright";

const browser = await chromium.launch({
  proxy: {
    // The proxy scheme is http:// even for HTTPS sites
    server: "http://HOST:PORT",
    // Login and password in separate fields, no need to encode them
    username: "LOGIN",
    password: "PASSWORD",
  },
});

const page = await browser.newPage();

// Page navigation timeout in milliseconds
await page.goto("https://api.ipify.org", { timeout: 30000 });

// The service returns the address the request came from
console.log(await page.innerText("body"));

await browser.close();
Python.
from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch(
        proxy={
            # The proxy scheme is http:// even for HTTPS sites
            "server": "http://HOST:PORT",
            # Login and password in separate fields, no need to encode them
            "username": "LOGIN",
            "password": "PASSWORD",
        }
    )
    page = browser.new_page()

    # Page navigation timeout in milliseconds
    page.goto("https://api.ipify.org", timeout=30000)

    # The service returns the address the request came from
    print(page.inner_text("body"))

    browser.close()

If you need different proxies for different tabs, set proxy not in launch but when creating the context: browser.newContext({ proxy: {...} }) in Node.js or browser.new_context(proxy={...}) in Python.

If SOCKS5

You can specify socks5://HOST:SOCKS_PORT in the server field and Playwright will route traffic through SOCKS5. But the documentation describes the username and password fields only for HTTP proxies, so we do not recommend a SOCKS5 port with a login and password. For a proxy with authentication, use the HTTP port.

Common errors

  1. 407 or ERR_INVALID_AUTH_CREDENTIALS on the page: the login or password is wrong. Check the order in the issued host:port:login:password.
  2. TimeoutError or ERR_PROXY_CONNECTION_FAILED: check HOST and PORT, whether the SOCKS5 port was put into HTTP mode, and increase the goto timeout.
  3. Special characters in the password: username and password are passed in separate fields, percent-encoding is not needed. Do not put the login and password into server.
  4. The https:// scheme in server: the issued proxy works over HTTP, so write http://HOST:PORT; the short form HOST:PORT is also treated as an HTTP proxy.
  5. If server is written without a port or with extra characters, the browser will not start or the page will not load.

Sources

Checked against the official documentation: October 2026. Program interfaces change: if item names differ, follow the documentation.

All guides are collected on the Guides page.

Find a proxy in the chat