Skip to content
Proxies
ISP Proxies (Static Residential)
from $4.69
Rotating Residential Proxies
from $2.42
Rotating Datacenter Proxies
from $1.21
Rotating Mobile Proxies
from $4.84
Locations
Europe
Asia
Middle East
Africa
North America
South America
Oceania
Learn

How to use a proxy with Playwright

Last updated

Short answer

To use a proxy with Playwright, pass a proxy object with a server, username and password when you launch the browser or create a context. Give each context its own sticky session so a page keeps one IP, use HTTP rather than SOCKS5 when you need authentication in Chromium, and block images and media to cut per-GB traffic.

Set a proxy when you launch the browser

The simplest setup sends every page in the browser through one proxy. Pass a proxy object to launch():

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch(
        proxy={
            "server": "http://HOST:823",
            "username": "USERNAME",
            "password": "PASSWORD",
        }
    )
    page = browser.new_page()
    page.goto("https://api.ipify.org")
    print(page.inner_text("body"))  # the proxy's IP
    browser.close()

The same in Node.js:

import { chromium } from 'playwright';

const browser = await chromium.launch({
  proxy: { server: 'http://HOST:823', username: 'USERNAME', password: 'PASSWORD' },
});
const page = await browser.newPage();
await page.goto('https://api.ipify.org');
console.log(await page.innerText('body'));
await browser.close();

The server uses http:// even for HTTPS sites: the browser tunnels HTTPS through the proxy with the CONNECT method, so the pages stay encrypted end to end.

Use a different proxy per context

A browser context is an isolated session with its own cookies and storage. Giving each context its own proxy settings lets one browser check several locations at once:

with sync_playwright() as p:
    browser = p.chromium.launch()
    for country in ["us", "de", "jp"]:
        context = browser.new_context(
            proxy={
                "server": "http://HOST:823",
                "username": f"USERNAME__cr.{country}",
                "password": "PASSWORD",
            }
        )
        page = context.new_page()
        page.goto("https://api.ipify.org")
        print(country, page.inner_text("body"))
        context.close()
    browser.close()

The country code in the username (__cr.de) picks where the IP comes from. Location targeting lists city, state and ZIP options too.

Keep one IP per page with sticky sessions

On a rotating gateway, every new connection gets a new IP. A browser opens several connections per page and reuses them, so one page load can mix IPs, which some sites treat as odd and which makes location checks inconsistent.

Give each context a session name instead. The gateway then keeps one IP for that session for about 30 minutes:

import uuid

session = uuid.uuid4().hex[:8]
context = browser.new_context(
    proxy={
        "server": "http://HOST:823",
        "username": f"USERNAME__cr.de;sessid.{session}",
        "password": "PASSWORD",
    }
)

Create a new context with a new session name whenever you want a new IP. Rotating proxies explains when to rotate and when to stay sticky.

Authentication and SOCKS5

Playwright accepts a username and password in the proxy object for HTTP proxies. Chromium does not support username and password authentication for SOCKS5 proxies, so an authenticated socks5:// server will fail. You have two options:

  • Use the HTTP port (http://HOST:823) with credentials. For websites, it works just as well.
  • Allowlist your server's public IPv4 address in the dashboard and use SOCKS5 (socks5://HOST:824) without credentials.

See SOCKS5 vs HTTP proxy for the differences.

Block heavy assets to save traffic

Per-GB proxies charge for every byte the browser downloads. Images, fonts and video are usually most of a page's weight and rarely needed for data checks. Block them with a route:

BLOCK = {"image", "font", "media"}

page.route(
    "**/*",
    lambda route: route.abort()
    if route.request.resource_type in BLOCK
    else route.continue_(),
)

A page that weighs several megabytes with everything loaded can drop to a few hundred kilobytes. Proxy pricing explained shows how much that saves.

Match locale and timezone to the proxy

For location checks, make the browser look like a local visitor so sites serve their localised version:

context = browser.new_context(
    proxy={"server": "http://HOST:823", "username": "USERNAME__cr.de", "password": "PASSWORD"},
    locale="de-DE",
    timezone_id="Europe/Berlin",
)

Without this, a German IP with an English browser locale may get an English or international page.

Troubleshooting

SymptomLikely causeFix
net::ERR_PROXY_CONNECTION_FAILEDWrong host or port, or outbound traffic blockedCheck the host and port in your dashboard; allow outbound connections
407 or an authentication promptWrong credentialsCheck the username and password; special characters are fine in the proxy object
SOCKS5 fails with credentialsChromium lacks SOCKS5 authUse the HTTP port, or allowlist your IP
Navigation timeoutsSlow route, distant country or heavy pageRaise timeout in goto(), block assets
The IP changes mid-pageRotating port without a sessionAdd sessid to the username

Use browser automation responsibly

Automate only public pages, follow each site's terms and robots.txt, and keep the pace close to a person's. Do not use Playwright with proxies to create accounts, log in to accounts you do not own, or get around logins, paywalls or other access controls. FuseProxy's acceptable use policy lists what is not allowed, and is web scraping legal? covers the legal side. For plain HTTP requests without a browser, see how to use a proxy with Python requests.

FAQ

Questions, answered

How do I set a proxy in Playwright?
Pass `proxy={"server": "http://HOST:PORT", "username": "USERNAME", "password": "PASSWORD"}` to `chromium.launch()` for the whole browser, or to `browser.new_context()` for one context. Every request from that browser or context then goes through the proxy.
Can Playwright use an authenticated SOCKS5 proxy?
Not with Chromium: it does not support username and password authentication for SOCKS5. Use the HTTP proxy port with credentials, or allowlist your server's IP and use SOCKS5 without credentials.
How do I rotate proxies in Playwright?
With a rotating gateway, each new connection gets a new IP, but a browser reuses connections, so one page can mix IPs. For predictable results, give each browser context a sticky session name in the username, and start a new context when you want a new IP.
How do I reduce proxy traffic with Playwright?
Block images, fonts and media with `page.route()`, avoid reloading pages, and close contexts when you finish. A text-only page load often uses a fraction of the traffic of a full one.
Should I set locale and timezone when using a proxy?
Yes, for location checks. Set the context's locale and timezone to match the proxy country, so sites show the same localised version a visitor there would see.

Start with the proxies you need

Create an account, top up and connect in minutes. Every price is on the pricing page.