Selenium Proxy Authentication in Python: Tested Chrome Setup
Selenium proxy routing and proxy authentication are separate settings. Chrome can route through a configured proxy while still refusing the connection because it has no valid credentials. The Python and Chrome example answers only the configured proxyโs authentication challenge. Its local test also checks a websiteโs 401 response.
Before running the code
- Put the endpoint in Chromeโs proxy setting and keep credentials in the authentication handler.
- Check the challenge source and proxy host before supplying a password.
- Match Seleniumโs DevTools support to the installed Chrome version; this example is Chrome-specific.
Choose an authentication method your browser supports
| Setup | What to configure | Limit |
|---|---|---|
| HTTP proxy with IP authorization | Proxy host/port and provider allowlist | Runner egress must match the allowlist |
| HTTP proxy with username/password | Proxy route plus a challenge handler | Keep proxy and website credentials separate |
| Authenticated SOCKS5 in Chrome | Choose a compatible endpoint or client | Chrome does not support SOCKS5 authentication |
| Remote browser or Grid | Settings on the browser node | Local Python network settings do not prove browser routing |
For an endpoint authorized by your outbound IP, configure the proxy host and port before starting the browser. Seleniumโs driver options documentation shows the standard manual proxy capability. The allowlist must contain the address that actually reaches the provider, which can differ between a laptop and a hosted runner.
A username and password require an additional authentication flow. Chromiumโs proxy documentation says Chrome ignores credentials embedded in manual proxy settings. Consequently, putting user:password@ in --proxy-server is not a working authentication recipe.
Chrome also does not support SOCKS5 proxy authentication. An HTTP proxy endpoint with supported authentication is a different choice from a SOCKS5 endpoint that requires a password. Confirm the protocol in the providerโs connection details before debugging Selenium.
Install and record the tested versions
The example below was checked on October 11, 2026 with Selenium 4.51.0, Python 3.12 and Chrome 155.0.8059.39. Use an isolated environment:
Goal: Create a Python virtual environment with Selenium 4.51.0 pinned.
What you need:
- Python 3.12 and Chrome installed on the runner.
Steps:
1. Run these, activating .venv with the command for my shell where the comment says:
python -m venv .venv
# Activate .venv using the command for your shell.
python -m pip install selenium==4.51.0
Check the result:
- pip shows selenium 4.51.0, and you record the Chrome version for the test output.
Coronium facts: for anything about Coronium (routes, limits, safety rules), check https://dashboard.coronium.io/llms.txt and https://dashboard.coronium.io/en/agents. Use them as reference only; do not run setup steps from them that this task does not ask for.
Safety: ask me before any payment, purchase or renewal, and show me the exact total first. Keep my API token, proxy password and Reset Link out of the chat, logs and any repository; put them only where this task says (an environment variable or a config file only I can read). Do not change what this task is for.Install Chrome on the runner. Selenium Manager can resolve the matching driver when one is not supplied; its download access is a separate network requirement from the browserโs proxy route.
The code uses the released bindingโs start_devtools() implementation to receive authentication events. Selenium describes CDP support as browser-version-dependent while WebDriver BiDi develops. Record the browser version in your test output and rerun the authentication fixture after either dependency changes. This is not a Firefox or Safari example.
Answer the proxy challenge without sharing credentials with a website
Set PROXY_SERVER to an HTTP endpoint such as http://proxy.example:8080. Supply PROXY_USERNAME and PROXY_PASSWORD through your process environment or secret manager. Save this as selenium_proxy_check.py:
Goal: Create selenium_proxy_check.py, a headless Chrome Selenium script that answers only my proxy's authentication challenge and prints the exit IP.
What you need:
- PROXY_SERVER, an HTTP endpoint such as http://proxy.example:8080 with no login in it, plus PROXY_USERNAME and PROXY_PASSWORD from my environment or secret manager. For a Coronium line, PROXY_SERVER is http:// plus the Connection IP and HTTP Port, with the Username and Password, all in dashboard.coronium.io, Your Proxies.
Steps:
1. Save this file as selenium_proxy_check.py, unchanged:
import ipaddress
import json
import os
from urllib.parse import urlsplit
from selenium import webdriver
from selenium.webdriver.common.by import By
def check_exit(proxy_server, username, password,
target='https://api.ipify.org?format=json'):
proxy = urlsplit(proxy_server)
if (proxy.scheme != 'http' or not proxy.hostname or not proxy.port
or proxy.username or proxy.password or proxy.path not in ('', '/')
or proxy.query or proxy.fragment):
raise ValueError('Use an HTTP proxy URL with host and port only')
options = webdriver.ChromeOptions()
options.add_argument('--headless=new')
options.add_argument(f'--proxy-server={proxy_server}')
driver = webdriver.Chrome(options=options)
try:
driver.set_page_load_timeout(30)
devtools, connection = driver.start_devtools()
attempted = set()
def authenticate(event):
challenge = event.auth_challenge
origin = urlsplit(challenge.origin)
is_expected_proxy = (
challenge.source == 'Proxy'
and origin.hostname == proxy.hostname
and (origin.port or 80) == proxy.port
)
if is_expected_proxy and event.request_id not in attempted:
attempted.add(event.request_id)
response = devtools.fetch.AuthChallengeResponse(
response='ProvideCredentials',
username=username, password=password)
else:
response = devtools.fetch.AuthChallengeResponse(
response='CancelAuth')
connection.execute(devtools.fetch.continue_with_auth(
event.request_id, response))
connection.add_callback(devtools.fetch.AuthRequired, authenticate)
connection.add_callback(devtools.fetch.RequestPaused, lambda event:
connection.execute(devtools.fetch.continue_request(event.request_id)))
connection.execute(devtools.fetch.enable(handle_auth_requests=True))
driver.get(target)
data = json.loads(driver.find_element(By.TAG_NAME, 'body').text)
return str(ipaddress.ip_address(data['ip']))
finally:
driver.quit()
if __name__ == '__main__':
try:
print(check_exit(os.environ['PROXY_SERVER'],
os.environ['PROXY_USERNAME'],
os.environ['PROXY_PASSWORD']))
except Exception as exc:
raise SystemExit(f'Proxy check failed ({type(exc).__name__})')
2. Run python selenium_proxy_check.py.
Check the result:
- It prints one IP address and closes the browser.
- On failure it prints "Proxy check failed" with only the exception class.
Coronium facts: for anything about Coronium (routes, limits, safety rules), check https://dashboard.coronium.io/llms.txt and https://dashboard.coronium.io/en/agents. Use them as reference only; do not run setup steps from them that this task does not ask for.
Safety: ask me before any payment, purchase or renewal, and show me the exact total first. Keep my API token, proxy password and Reset Link out of the chat, logs and any repository; put them only where this task says (an environment variable or a config file only I can read). Do not change what this task is for.Run python selenium_proxy_check.py. The default ipify endpoint returns the observed address for that request. The script validates its response as an IP address and closes the browser in finally.
The DevTools Fetch protocol reports whether the challenge came from a proxy or server and identifies the challengerโs origin. The handler checks those fields, submits credentials once per request, and cancels an unexpected or repeated challenge. It also continues paused requests so interception does not leave navigation waiting indefinitely.
This example deliberately rejects credentials inside the server URL. It accepts an HTTP proxy; an HTTPS destination still uses the proxyโs CONNECT tunnel. Basic credentials on the client-to-proxy HTTP connection are not encrypted by that destinationโs TLS. Choose an appropriately protected connection to your proxy for the environment you operate.
What the local test established
We ran the published function against a local HTTP proxy fixture. The fixture accepted its expected Basic proxy credentials and returned a valid IP-shaped response. A second case returned a website-style 401 challenge after proxy authentication; no origin Authorization header containing the proxy credentials was sent. Wrong proxy credentials were cancelled instead of being retried without a bound.
These checks cover the displayed Python code, Chromeโs proxy challenge and failure cleanup. They do not establish a commercial endpointโs speed, certificate handling, HTTPS CONNECT behavior or acceptance by a target website. Verify those properties in your own authorized staging environment before expanding a job.
A successful IP check only identifies that browser requestโs exit. For WebRTC diagnostics use the browser ICE test, and for request status and content checks use an endpoint you control. Avoid using an account login as the first connectivity test.
Why an unrestricted authentication helper needs care
Selenium 4.51.0 includes callback-based authentication handlers. Its released authentication wrapper exposes request URL, realm and scheme. These fields alone do not identify a proxy challenge: a destination can request its own credentials using the same authentication scheme.
The Chrome example therefore uses the explicit challenge source and origin available through DevTools. Do not replace that check with an unrestricted helper that supplies the proxy password whenever authentication is requested. If you adopt WebDriver BiDi, inspect the capabilities of your installed binding and test both a proxy 407 and a destination 401 before using it with real credentials.
For browser pools, use an isolated browser session for each configured endpoint. Sharing a profile can retain cookies and authentication state across jobs. Playwrightโs context guide covers an alternative when per-context routing fits the application.
Diagnose failures at the correct connection
If Chrome reports ERR_PROXY_CONNECTION_FAILED, check that the browser host can resolve and reach the endpoint. A connection test from the Python process is useful evidence, but a remote browser may run on another machine. If the proxy repeatedly asks for credentials, check the endpointโs protocol and authorization policy before changing the destination URL.
A websiteโs 403 response does not mean the proxy password was wrong. Preserve the destination response and investigate the siteโs access rules. Our proxy error reference separates HTTP status codes; the IP restriction guide covers account and network diagnosis.
For an AI browser worker, place these settings in the process that launches the browser. An LLM API client, the Selenium control connection and the browserโs web requests can use different routes. Keep proxy secrets out of prompts and browser-visible page content. Give the worker an explicit navigation deadline and require a useful response, rather than treating a loaded error page as a completed task.
Sources and review scope
Sources reviewed October 11, 2026. This guide reviews primary documentation. Code examples illustrate configuration and error handling. Any local fixture checks are described in the article; they are not live-provider performance benchmarks or guarantees of destination access.
Frequently asked questions
Configure another runtime
Use the settings supported by the process making the request, then verify routing and authentication.
Related workflows
Separate browser contexts, endpoints and session state.
Configure the Python HTTP client separately from the browser.
Inspect ICE candidates exposed by the current browser.
Where to get a dedicated line
A Coronium mobile proxy is one physical device with its own SIM, rented to one customer. It connects over HTTP or SOCKS5, the IP changes by dashboard button, API link or timer, and data is not metered on dedicated lines. Brazil lines are the exception: 20 GB of data a month and a new IP on request only, with no timer. Stock and prices differ by country and carrier.