Selenium WebDriver and authenticated proxies: what works
Updated:
Selenium proxy authentication needs a workaround, because ChromeDriver's --proxy-server=http://ip:port flag cannot carry a username and password; Chrome drops inline user:pass and shows a login dialog that WebDriver cannot fill. The two dependable fixes are selenium-wire, which handles the ProxyV4 login in Python, and a small Chrome extension that answers onAuthRequired in any Selenium language.
http://user:pass@ip:port (selenium-wire / Chrome proxy extension)Options compared
| Method | How you configure it | Good fit |
|---|---|---|
selenium-wire (Python) | seleniumwire_options={'proxy': {'http': 'http://user:pass@ip:port', 'https': 'http://user:pass@ip:port'}} | Quickest route in Python; the proxy can be changed while the browser is open |
| Auth extension | A zipped extension whose background script handles chrome.webRequest.onAuthRequired | Java, C#, Python and undetected-chromedriver alike |
| Move to Playwright | browser.newContext({ proxy: { server, username, password } }) | New projects; proxy login is built in, no extension |
What happens with plain --proxy-server
Chrome takes the proxy address from the command line but ignores any credentials written into it. When the proxy replies 407, Chrome opens a native sign-in prompt. That prompt is outside the page DOM, so find_element cannot see it and the script waits until it times out. Every working method therefore supplies the credentials somewhere other than the flag.
Note that selenium-wire is no longer actively maintained. It still works for many setups, but for long-lived projects the extension approach or Playwright is the safer bet.
Keeping proxied Selenium runs efficient
- Set
options.page_load_strategy = 'eager'so the script continues once the DOM is ready rather than waiting on slow third-party scripts - For headless runs on Chrome 109 or later use
--headless=new; extensions, including the auth extension, behave as in a normal window - Turn off image loading in Chrome preferences when you only need text such as prices or titles
- Put
driver.quit()in atry / finallyblock so a crash does not leave Chrome processes behind
Before you scale up
Each WebDriver session is a full browser, so give every session its own IP if the site links accounts by address. A ProxyV4 private IPv4 is rented to one customer and keeps its address when you renew, which keeps long-running test accounts on the same IP. Run new proxies through the proxy checker first so a bad line does not show up as a confusing Selenium timeout.
Step by step
- 1
Install selenium-wire
In your virtual environment, run
pip install selenium-wire. - 2
Describe the proxy
Build
sw_options = {'proxy': {'http': 'http://user:pass@ip:port', 'https': 'http://user:pass@ip:port'}}from your ProxyV4 order. - 3
Start Chrome with those options
Create the driver with
driver = webdriver.Chrome(seleniumwire_options=sw_options), importingwebdriverfromseleniumwire. - 4
Check the exit IP
Call
driver.get('https://proxyv4.com/api/my-ip')and confirm the page shows the proxy address.
Frequently asked questions
Why is `--proxy-server=http://user:pass@ip:port` ignored in ChromeOptions?
Chrome removes credentials from the --proxy-server value by design. Supply them through selenium-wire, an onAuthRequired extension, or switch to Playwright, which accepts a username and password directly.
Can selenium-wire change proxy without restarting the browser?
Yes. Assign a new dict, driver.proxy = {'http': 'http://...', 'https': 'http://...'}, and the following requests use the new upstream proxy.
Does the auth extension work in headless Chrome?
Yes, with --headless=new. The old --headless mode did not load extensions the same way.
Selenium times out on every page through the proxy. What next?
Load the IP endpoint with cURL using the same credentials. If cURL fails too, the line or port is the problem; the proxy timeout guide lists what to check.
Stable IPs for Selenium sessions
Private IPv4 in 7 countries and static ISP in the US and Vietnam, with user and password, unmetered and one customer per IP.
Check live US prices