$0.00
A

Proxyvizr blog

How to set up a proxy in Playwright

Playwright supports proxies with a username and password out of the box: set one for the whole browser or for a single context. The examples below are in Python; Node.js uses the same options.

Where to get the proxy details

Buy proxies in the Proxyvizr catalog or unified search and open "My proxies". Each proxy has a host:port:username:password line there, and traffic packages generate a list for the country you need on the same page. If your software needs another format, convert the list with the free Proxyvizr proxy converter.

Proxy for the whole browser

Pass a proxy dict when launching the browser:

from playwright.sync_api import sync_playwright
with sync_playwright() as p:
    browser = p.chromium.launch(proxy={
        "server": "http://HOST:PORT",
        "username": "LOGIN",
        "password": "PASSWORD",
    })
    page = browser.new_page()
    page.goto("https://proxyvizr.com/api/my-ip")
    print(page.inner_text("body"))
    browser.close()

Different proxies per context

A Playwright context is a separate profile with its own cookies. Each context can have its own proxy, which is handy for several accounts in one browser:

context = browser.new_context(proxy={
    "server": "http://HOST2:PORT2",
    "username": "LOGIN2",
    "password": "PASSWORD2",
})

SOCKS5

A socks5://HOST:PORT address works, but Chromium in Playwright does not support a username and password for SOCKS5. Use the provider HTTP access or a proxy with IP authentication. Check Firefox in Playwright on your version too.

Common mistakes

Putting the credentials inside server: pass them as separate username and password fields. SOCKS5 with a password in Chromium: not supported. One proxy for all contexts with several accounts: the accounts get linked by IP.

Conclusion

Playwright accepts authenticated proxies for the whole browser or per context. For SOCKS5 with a password in Chromium, use HTTP access.

Ready to pick your proxies?

Create an account in a minute and choose proxies for your task — residential, mobile, ISP, datacenter and SOCKS5 from trusted providers.