Skip to content

Playwright Proxy Authentication: Per-Browser or Per-Context

Where the username and password go, when one proxy per browser is enough, and how to give each context its own IP.

Per browser or per context: which one to pick

A proxy in launch() applies to the whole browser, so all its contexts and pages leave from one IP. A proxy in new_context() applies to that context only, so one browser process can run several isolated sessions, each from a different IP.

Pick per-browser for a single job or a test run that needs one location. Pick per-context for parallel workers, one account per context, or a list of IPs you walk through. Cookies and storage are already separate per context; the proxy is the part that has to be set on top.

launch() vs new_context() at a glance

launch() vs new_context() at a glance
ItemWhere you set itWhat it coversUsername and password
Per browserchromium.launch(proxy=...)All contexts and pages in that browserFields server, username, password
Per contextbrowser.new_context(proxy=...)Only pages opened in that contextSame fields; the browser itself can stay without a proxy
Browser flagargs=["--proxy-server=..."]Chromium command line, whole browserNot a place for a login: Chromium takes the credentials from the Playwright proxy fields instead

Source: Playwright documentation, Network and Browser.new_context pages, read on 13 November 2026. The browser-flag row is the Chromium command-line form; use the proxy object when you need a login.

One proxy for the whole browser (Python)

# pip install playwright   then   playwright install chromium
from playwright.sync_api import sync_playwright

proxy = {
    "server": "http://HOST:PORT",   # HTTP endpoint from My assets
    "username": "LOGIN",
    "password": "PASSWORD",
}

with sync_playwright() as p:
    browser = p.chromium.launch(proxy=proxy)   # every context in this browser uses it
    page = browser.new_page()
    page.goto("https://ipinfo.io/json")
    print(page.inner_text("body"))             # shows the proxy's exit IP
    browser.close()

Example only: replace HOST, PORT, LOGIN and PASSWORD with the values from My assets.

One proxy per context, several in parallel (Python)

# pip install playwright   then   playwright install chromium
import asyncio
from playwright.async_api import async_playwright

PROXIES = [  # one entry per IP, copied from My assets
    {"server": "http://HOST:PORT", "username": "LOGIN_1", "password": "PASSWORD_1"},
    {"server": "http://HOST:PORT", "username": "LOGIN_2", "password": "PASSWORD_2"},
]

async def check(browser, proxy):
    context = await browser.new_context(proxy=proxy)   # this context only
    try:
        page = await context.new_page()
        await page.goto("https://ipinfo.io/json")
        print(proxy["username"], await page.inner_text("body"))
    finally:
        await context.close()

async def main():
    async with async_playwright() as p:
        browser = await p.chromium.launch()            # no proxy on the browser itself
        await asyncio.gather(*(check(browser, x) for x in PROXIES))
        await browser.close()

asyncio.run(main())

Example only: replace HOST, PORT, LOGIN and PASSWORD with the values from My assets.

The same in Node.js

// npm i playwright   then   npx playwright install chromium
import { chromium } from 'playwright'

const proxies = [ // one entry per IP, copied from My assets
  { server: 'http://HOST:PORT', username: 'LOGIN_1', password: 'PASSWORD_1' },
  { server: 'http://HOST:PORT', username: 'LOGIN_2', password: 'PASSWORD_2' },
]

const browser = await chromium.launch() // no proxy on the browser itself
await Promise.all(proxies.map(async (proxy) => {
  const context = await browser.newContext({ proxy }) // this context only
  try {
    const page = await context.newPage()
    await page.goto('https://ipinfo.io/json')
    console.log(proxy.username, await page.textContent('body'))
  } finally {
    await context.close()
  }
}))
await browser.close()

Example only: replace HOST, PORT, LOGIN and PASSWORD with the values from My assets.

HTTP or SOCKS5 in the server field

The server field accepts both http:// and socks5:// addresses, but the username and password fields are described for HTTP proxies. Chromium's own SOCKS5 client sends only the "no authentication" method, so a SOCKS5 proxy that wants a login does not work in Chromium even if you fill in the fields.

So for Chromium use the HTTP endpoint of your proxy. On Proxy302 that is port 2222 on proxy.proxy302.com. Which protocol an asset accepts depends on the product, so look at the protocol shown for the asset in My assets. If you need SOCKS5 with a login in a browser anyway, see the guide linked below.

Check that the proxy is really used

  1. Step 1

    Run the one-proxy script above without a proxy first and note your own IP from ipinfo.io/json.

  2. Step 2

    Add the proxy object and run again. The ip field should now be the proxy's exit IP, and the country should match the one you chose.

    Expected result The IP and country in the JSON differ from your own.

  3. Step 3

    For per-context, print the IP for every context. Two contexts with two different static IPs should show two different addresses.

  4. Step 4

    If the result is your own IP, the proxy object was passed to a different call than the one that created the page. Check which browser or context the page came from.

Test the login outside the browser first

# HTTP endpoint (the one Chromium can log in to)
curl -x http://LOGIN:PASSWORD@HOST:PORT https://ipinfo.io/json

# SOCKS5 endpoint (works in curl, not in Chromium with a login)
curl -x socks5h://LOGIN:PASSWORD@HOST:PORT https://ipinfo.io/json

Example only: replace HOST, PORT, LOGIN and PASSWORD with the values from My assets.

When Playwright and the proxy disagree

Error page or 407 Proxy Authentication Required

Check Username or password has a typo, or the asset has expired or has no traffic left.

Fix Copy LOGIN and PASSWORD again from My assets, and test them with the curl commands above. Fix this before touching Playwright.

Stop when If curl also fails with 407, stop changing code: the credentials or the asset are the problem. Open a Support ticket with the order number.

Works over http:// but not over socks5:// with a login in Chromium

Check Chromium offers no password method for SOCKS5.

Fix Switch the server field to the HTTP endpoint of the same asset.

Connection reset or timeout on the HTTP port

Check The asset was issued for the other protocol, or HOST or PORT is wrong.

Fix Check the protocol and port shown for the asset: HTTP uses 2222 and SOCKS5 uses 3333 on proxy.proxy302.com. Generate or buy a new asset with the protocol you need.

Every context shows the same IP

Check The proxy was set in launch() and also in new_context() with the same entry, or all entries point to the same IP.

Fix Pass different credentials to each new_context(). On rotating residential, remember that without a session each new connection can get a new IP, so use a static IP when a context must keep one address.

The page loads but the site shows the wrong country

Check The exit IP is not in the country you expected.

Fix Look the IP up on ipinfo.io and choose the exit country again when you generate or buy the asset.

How to do it with Proxy302

For one fixed address per context, a static ISP IP fits: it does not rotate during the lease, costs US$0.50 for 1 day and US$7.99 for 30 days (about US$0.27 a day), and you can buy up to 100 in one order. For many different IPs from one pool, rotating residential costs US$1.50 per GB on the Budget line; with no session set, each new connection gets a new IP.

In both cases choose the HTTP protocol when you generate or buy, so the same login can go straight into the Playwright proxy object. The Playwright page has the setup and the rest of the options.

Steps in Proxy302

  1. Step 1

    Open the static ISP page (or rotating residential), choose the country and HTTP as the protocol, review the cost and pay from the wallet.

  2. Step 2

    Open My assets and copy host, port, username and password. For several contexts, buy or generate several assets.

  3. Step 3

    Put the values into the proxy object as server (http://HOST:PORT), username and password.

  4. Step 4

    Confirm the exit with https://ipinfo.io/json from inside Playwright, as in the examples above.

Playwright proxy FAQ

How do I set a proxy with username and password in Playwright?

Pass proxy={"server": "http://HOST:PORT", "username": "LOGIN", "password": "PASSWORD"} to chromium.launch() for the whole browser, or to browser.new_context() for one context.

Can each browser context use a different proxy?

Yes. Playwright documents that the proxy can be set for each browser context individually, so one browser can run contexts with different IPs.

Does Playwright support SOCKS5 proxies with a password?

The server field accepts socks5:// addresses, but the username and password are documented for HTTP proxies. In Chromium, a SOCKS5 proxy that requires a login does not work; use the HTTP endpoint.

Do I still need the --proxy-server argument?

No. The proxy option of launch() and new_context() is the supported place for the server and the login.

How do I check which IP Playwright is using?

Open https://ipinfo.io/json in a page of the same context and read the ip field.

Reference links

4
  1. Playwright: Network, HTTP proxy

    Official documentation · Confirmed on:

    Read on 13 November 2026: proxy can be set globally for the whole browser or for each browser context; username and password are optional fields for an HTTP(S) proxy; examples use launch(proxy={server, username, password}) and new_context(proxy={server}).

  2. Playwright: Browser.new_context, proxy option

    Official documentation · Confirmed on:

    Read on 13 November 2026: server accepts HTTP and SOCKS proxies, for example http://myproxy.com:3128 or socks5://myproxy.com:3128; bypass is a comma-separated list of domains; username and password are used "if HTTP proxy requires authentication".

  3. Chromium source: socks5_client_socket.cc

    Official documentation · Confirmed on:

    Read on 13 November 2026: the SOCKS5 greeting Chromium sends is 05 01 00 (one method, "no authentication"), and a reply that selects any other method is treated as an unexpected-auth error.

  4. Proxy302 product facts and price list

    Product observation · Confirmed on:

    Product facts file, checked on 13 November 2026 against the console, backend and price list: static ISP lease prices per IP (US$, 1 PTC = US$1), rotating residential Budget line price per GB, HTTP port 2222 and SOCKS5 port 3333 on proxy.proxy302.com, which protocols work for which product, no free trial.

Ready to try it?

Create an account, top up once, then pick rotating residential, static ISP or datacenter IPs and have one running in your browser within minutes.