Skip to content
Blog

Patchright, nodriver and SeleniumBase UC with Authenticated Proxies

Authenticated residential proxies in Patchright, nodriver and SeleniumBase UC mode, verified on Chrome 158: what works, what silently fails, and SOCKS5 caveats.

Exitway team··6 min read

Chrome ignores credentials in --proxy-server=http://user:pass@host:port. It sends the first CONNECT without a Proxy-Authorization header, receives a 407, and only answers that challenge if something supplies credentials. Each tool solves this differently, and one popular setup no longer does it at all:

Tool How to pass the proxy Credentials on the wire (Chrome 158)
Patchright 1.64.4 proxy={"server", "username", "password"} Answers the 407 challenge
nodriver 0.50.99 browser.create_context(url, proxy_server="http://user:pass@host:port") Local forwarder sends them preemptively
SeleniumBase 4.58.3, CDP mode SB(uc=True, proxy="user:pass@host:port") + activate_cdp_mode() Answers the 407 challenge
SeleniumBase 4.58.3, classic UC WebDriver mode same proxy= Never sent: its auth extension wasn’t loaded

Tested with Google Chrome 158.0.8127.36 on Python 3.12, in a Debian container under Xvfb. To see what each tool actually sends, we put a small logging relay in front of gw.exitway.net:7777 that records the request line, the username and the gateway’s status line. On a test account with no bandwidth, correctly authenticated requests end in 402 Payment Required and unauthenticated ones in 407. We then ran every snippet below on a funded account: Patchright, nodriver, SeleniumBase CDP mode and sb_cdp all loaded https://ipinfo.io/json from US residential IPs.

Patchright: the Playwright proxy dict

Patchright keeps Playwright’s API, so the proxy is the usual dict. Use real Chrome (channel="chrome"), a persistent context and a headed window:

import os

from patchright.sync_api import sync_playwright

USER, PASS = os.environ["EXITWAY_USER"], os.environ["EXITWAY_PASS"]
SESSION = "us01"

with sync_playwright() as p:
    context = p.chromium.launch_persistent_context(
        user_data_dir=f"profiles/{SESSION}",
        channel="chrome",          # real Chrome, not bundled Chromium
        headless=False,            # run under Xvfb on servers
        no_viewport=True,
        proxy={
            "server": "http://gw.exitway.net:7777",
            "username": f"{USER}-country-us-session-{SESSION}-lifetime-30",
            "password": PASS,
        },
    )
    page = context.new_page()
    page.goto("https://ipinfo.io/json", timeout=60_000)
    print(page.inner_text("body"))
    context.close()

The relay showed Chrome’s unauthenticated CONNECTs answered with 407, then a CONNECT carrying USERNAME-country-us-session-us01-lifetime-30 answered with 402. The credentials arrive. browser.new_context(proxy=...) works the same way per context. The fingerprinting article uses it for a consistency audit.

How failures surface in Patchright:

Cause page.goto error Page shown
Valid credentials, no bandwidth (402) net::ERR_TUNNEL_CONNECTION_FAILED “This site can’t be reached”
Wrong password net::ERR_HTTP_RESPONSE_CODE_FAILURE “HTTP ERROR 407”
No username/password in the dict net::ERR_INVALID_AUTH_CREDENTIALS none
socks5:// server with credentials launch fails: Browser does not support socks5 proxy authentication none

Run it headed. With headless=True, Patchright still reported a HeadlessChrome User-Agent, even though it hid navigator.webdriver.

nodriver: create_context with a local forwarder

nodriver has no proxy argument on start(). In 0.50.99, credentials go through Browser.create_context():

import os

import nodriver as uc

USER, PASS = os.environ["EXITWAY_USER"], os.environ["EXITWAY_PASS"]


async def main():
    browser = await uc.start()            # no --proxy-server here
    proxy = (f"http://{USER}-country-us-session-us02-lifetime-30:{PASS}"
             "@gw.exitway.net:7777")
    # New browser context + local forwarder that adds Proxy-Authorization
    tab = await browser.create_context("https://ipinfo.io/json",
                                       proxy_server=proxy)
    await tab.sleep(5)
    print(await tab.evaluate("document.body.innerText"))
    browser.stop()

uc.loop().run_until_complete(main())

The installed source (ProxyForwarder in nodriver/core/util.py) shows how this works:

  • It starts an unauthenticated HTTP proxy on 127.0.0.1 at a random free port and points a new browser context at it with CDP Target.createBrowserContext(proxyServer=...).
  • For each CONNECT it opens a connection to the real proxy and adds Proxy-Authorization itself. The relay confirmed this: credentials on the first request, no 407 round trip.
  • It handles only CONNECT. Per the source, any other request (plain http:// proxying) gets 400 Bad Request from the forwarder.
  • If the upstream refuses, it answers Chrome with a 502, so the page always shows ERR_TUNNEL_CONNECTION_FAILED. The real reason goes to the nodriver.core.util logger at ERROR level, which Python prints to stderr even without logging configured:
Upstream proxy rejected connection: HTTP/1.1 402 Payment Required

With a wrong password the same line says 407 Proxy Authentication Required. Grep your logs for it.

Two side effects follow from that design. Any local process can use the forwarder (and your bandwidth) while it runs. Only the context’s traffic goes through it; Chrome’s own background requests leave from your machine’s IP.

SeleniumBase UC mode: use CDP mode

SeleniumBase takes proxy="user:pass@host:port" and, for authenticated proxies, builds a small Chrome extension and passes --load-extension. On Chrome 158 that path failed silently in our tests: the command line contained --load-extension=.../proxy_ext_dir, but chrome://extensions-internals listed only the built-in PDF viewer. The relay saw only unauthenticated CONNECTs answered with 407, and the page stayed blank (<html><head></head><body></body></html>).

CDP mode handles proxy auth itself, through Fetch.enable(handleAuthRequests=True) and Fetch.continueWithAuth:

import os

from seleniumbase import SB

USER, PASS = os.environ["EXITWAY_USER"], os.environ["EXITWAY_PASS"]
proxy = f"{USER}-country-us-session-us03-lifetime-30:{PASS}@gw.exitway.net:7777"

with SB(uc=True, proxy=proxy, locale="en-US") as sb:
    sb.activate_cdp_mode("https://ipinfo.io/json")
    sb.sleep(3)
    print(sb.get_text("body"))

Or skip WebDriver entirely with pure CDP mode:

import os

from seleniumbase import sb_cdp

USER, PASS = os.environ["EXITWAY_USER"], os.environ["EXITWAY_PASS"]
proxy = f"{USER}-country-us-session-us04-lifetime-30:{PASS}@gw.exitway.net:7777"

sb = sb_cdp.Chrome("https://ipinfo.io/json", proxy=proxy, locale="en-US")
sb.sleep(3)
print(sb.get_text("body"))
sb.driver.stop()

In both, the relay showed the 407 challenge followed by the full Exitway username, then 402. On Linux, sb_cdp.Chrome starts its own Xvfb unless you ask for headless.

One parsing gotcha: proxy="socks5://user:pass@host:port" is split on @ and :, and the relay received the username socks5. Pass the HTTP form, user:pass@host:port, without a scheme.

One sticky session per browser

A page load opens several connections: at least one per origin, plus retries and Chrome’s own background requests (below). Without a session parameter, Exitway assigns a new IP to every new connection, so one page could be assembled from several exits. For browsers, always use a sticky session:

  • One -session-<id> per browser, per persistent profile or per context. IDs are 1-32 letters and digits; -session-us_01 is rejected with 400.
  • -lifetime-<minutes> (up to 1440) longer than the job.
  • Name profiles after the session ID (profiles/us01) so cookies stay paired with their IP.

Rotating vs sticky sessions goes deeper on choosing lifetimes.

SOCKS5 caveats

Chromium has no SOCKS5 username/password support, and each tool reacts differently:

Tool socks5:// with credentials
Patchright / Playwright refuses at launch
nodriver works through its forwarder, but the forwarder calls socket.gethostbyname() for every target. With local DNS disabled, every SOCKS connection failed with gaierror while the HTTP form kept working. Your DNS lookups stay local.
SeleniumBase mis-parses the string (username becomes socks5)

Every Exitway port accepts both HTTP CONNECT and SOCKS5 on the same host:port, so switching to http:// costs nothing. Use SOCKS5 with clients that support authenticated socks5h://, such as curl or curl_cffi.

Diagnosing before you launch Chrome

A browser turns most proxy errors into the same ERR_TUNNEL_CONNECTION_FAILED. Check the credentials with curl first. A plain-HTTP request returns the gateway’s verdict as a status line and a header:

curl -s -D - -o /dev/null \
  -x "http://$EXITWAY_USER-country-us-session-us01:$EXITWAY_PASS@gw.exitway.net:7777" \
  http://example.com/ | grep -E "^HTTP|^X-Exitway"
HTTP/1.1 402 Payment Required
X-Exitway-Error: insufficient_balance

A 407 here means the credentials are wrong; a 400 names the bad parameter. Don’t leave a browser retrying a wrong password: after repeated failed logins the gateway answers 429 to that IP for a while, even for correct credentials. We hit exactly that while testing failure modes. The full error table is in the docs.

Background traffic counts

Chrome talks to Google while you scrape. Through a Patchright browser-level proxy, the relay recorded CONNECTs to accounts.google.com, update.googleapis.com, www.gstatic.com and several to www.google.com, some carrying your credentials, so they use your bandwidth. --disable-background-networking --disable-component-update removed the update traffic in our test but not the rest. Per-context proxies (new_context(proxy=...), nodriver’s create_context) kept most of it off the proxy. When you buy by the GB, measure a few page loads before scaling.

Which one to use

  • Patchright if your code is already Playwright: smallest change, clean auth, run headed.
  • nodriver for a lean async CDP client and per-context proxies; read the logs for proxy errors.
  • SeleniumBase if you want its helpers; use CDP mode for authenticated proxies.
  • None of them if the data is reachable without JavaScript. An HTTP client with a browser TLS fingerprint is a fraction of the cost, and Camoufox is the Firefox alternative.

Collect public data only, respect robots.txt and rate limits, and follow Exitway’s Acceptable Use Policy.

Set it up

Exitway residential bandwidth starts at $0.70/GB, pay as you go, and unused GB never expire. Create an account, grab the proxy username and password from your dashboard, and start with the curl check above. For the basic Playwright and Puppeteer setup, see Playwright and Puppeteer proxy authentication.

More guides