If you have ever tried to run Chrome through Selenium with a proxy like
--proxy-server=http://user:password@ip:port,
you have likely encountered the issue where the browser either opens without a proxy at all or displays a system authentication window,
which blocks the entire script. This is not a bug in your code — it is an architectural limitation of Chromium that Selenium
does not directly address. In this article, we will discuss why this happens and provide 4 working methods to pass the proxy login and password
to Chrome without manual input.
Why --proxy-server does not accept user:pass
The --proxy-server
flag in Chromium was originally designed only to specify the protocol, IP address, and port of the proxy server.
The syntax with credentials like user:password@host:port
works in curl, wget, and many other utilities, but Chromium simply discards this part of the URL when parsing the flag.
This is confirmed behavior, documented in the Chromium bug tracker since the 50s releases, and over the years the developers
have not added support for command-line authentication — for security reasons: the password in process arguments is visible through ps aux
or task manager, which is considered a leak.
As a result, Chrome connects to the proxy server, but as soon as it responds with the code
407 Proxy Authentication Required,
the browser shows a native dialog box with fields for "Username" and "Password." Selenium cannot interact
with OS system dialogs — it only manages the DOM tree of the page, so it is impossible to automatically close or fill
this window through the standard WebDriver API. The script simply hangs, waiting for someone to manually
enter the data or for the timeout to expire.
It is important to understand that the problem is specifically relevant for HTTP/HTTPS and SOCKS5 proxies with login and password authentication.
If the proxy is protected by an IP-whitelist (without login), the authentication dialog does not appear at all, and the flag
--proxy-server works as expected.
Therefore, for scraping and automation through datacenter proxies,
many developers initially choose a plan with IP binding rather than password binding — this eliminates the problem at its root.
However, if you have a pool of rotating residential proxies,
IP binding is often inconvenient, and the task must be solved programmatically.
Method 1: Chrome extension with proxy authentication
The most reliable and long-lasting method is to generate a mini Chrome extension (Manifest V2 or V3) that
intercepts the onAuthRequired
event and automatically fills in the username and password, bypassing the system dialog. The extension is created on the fly in Python code
and connected to Chrome through the add_extension option.
import zipfile
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
def create_proxy_extension(proxy_host, proxy_port, proxy_user, proxy_pass, plugin_path="proxy_auth.zip"):
manifest_json = """
{
"version": "1.0.0",
"manifest_version": 2,
"name": "Chrome Proxy Auth",
"permissions": [
"proxy", "tabs", "unlimitedStorage", "storage",
"<all_urls>", "webRequest", "webRequestBlocking"
],
"background": {"scripts": ["background.js"]},
"minimum_chrome_version":"22.0.0"
}
"""
background_js = f"""
var config = {{
mode: "fixed_servers",
rules: {{
singleProxy: {{
scheme: "http",
host: "{proxy_host}",
port: parseInt({proxy_port})
}},
bypassList: ["localhost"]
}}
}};
chrome.proxy.settings.set({{value: config, scope: "regular"}}, function() {{}});
chrome.webRequest.onAuthRequired.addListener(
function(details) {{
return {{
authCredentials: {{username: "{proxy_user}", password: "{proxy_pass}"}}
}};
}},
{{urls: ["<all_urls>"]}},
["blocking"]
);
"""
with zipfile.ZipFile(plugin_path, "w") as zp:
zp.writestr("manifest.json", manifest_json)
zp.writestr("background.js", background_js)
return plugin_path
plugin = create_proxy_extension("gate.example.com", 7000, "login123", "pass456")
options = Options()
options.add_extension(plugin)
driver = webdriver.Chrome(options=options)
driver.get("https://httpbin.org/ip")
print(driver.page_source)
driver.quit()
This method completely eliminates the authentication dialog — Chrome automatically supplies the credentials for each 407 request. The downside of this approach is that it only works with a visible browser (headless mode in older versions of Chrome with extensions can be unstable), and for each new proxy, you need to recreate the zip archive. For mass launching of 20-50 profiles with different proxies, this is solved by generating a unique plugin for each profile in a loop.
Method 2: Selenium Wire
If you do not want to deal with generating extensions, you can use the selenium-wire library —
it wraps regular Selenium and adds its own proxy layer between the browser and the target server.
The login and password are passed directly in the options, without dialogs or extensions.
from seleniumwire import webdriver
proxy_options = {
'proxy': {
'http': 'http://login123:[email protected]:7000',
'https': 'http://login123:[email protected]:7000',
'no_proxy': 'localhost,127.0.0.1'
}
}
driver = webdriver.Chrome(seleniumwire_options=proxy_options)
driver.get("https://httpbin.org/ip")
print(driver.page_source)
driver.quit()
Pros: minimal code, SOCKS5 support, easy to change proxies on the fly between requests — this is important if you are doing IP rotation on every N-th page when scraping Wildberries or Ozon. Cons: Selenium Wire adds its own local MITM proxy, which slightly slows down page loading and sometimes conflicts with sites that use strict HSTS and certificate pinning. The project has also not been updated as actively as the main Selenium, so compatibility with new versions of Chrome should be checked before production use.
Method 3: CDP and Network.setBasicAuth (Selenium 4 BiDi)
Starting with Selenium 4, it became possible to work directly through the Chrome DevTools Protocol (CDP), which allows
intercepting authorization requests without third-party libraries. Chrome supports the event
Fetch.authRequired,
which can be subscribed to through a DevTools session and programmatically respond with credentials.
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("--proxy-server=gate.example.com:7000")
driver = webdriver.Chrome(options=options)
# Enable network event interception via CDP
driver.execute_cdp_cmd("Network.enable", {})
driver.execute_cdp_cmd("Network.setExtraHTTPHeaders", {"headers": {}})
# In Selenium 4.10+, a simplified authentication API is available
driver.execute_cdp_cmd("Fetch.enable", {
"handleAuthRequests": True,
"patterns": [{"urlPattern": "*"}]
})
# Example handler (in real code, a listener through the CDP session websockets is needed)
# driver.on_auth_required(lambda: {"username": "login123", "password": "pass456"})
driver.get("https://httpbin.org/ip")
driver.quit()
In practice, a full implementation of this handler requires working with a low-level CDP WebSocket connection
(the pycdp library or
the built-in BiDi client in Selenium 4.10+), which is more of an engineering task than a quick script. This method
should be chosen if you are building your own automation framework and want to eliminate the dependency
on selenium-wire or extension generation. For most SMM automation and marketplace scraping tasks,
it is easier to use method 1 or 2.
Method 4: Proxy without password via IP-whitelist
The simplest solution is to not pass the login and password to Chrome at all. Many proxy providers, including
mobile proxies, support
authentication by the IP address of the server or machine from which the request is made. You add your external IP to the whitelist
in the provider's personal account, and after that, the flag
--proxy-server=http://ip:port
works without a single authentication dialog — because the proxy server itself determines that the request came from an allowed IP,
and does not send a 407 code.
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("--proxy-server=http://45.12.34.56:7000") # proxy without login, IP already in whitelist
driver = webdriver.Chrome(options=options)
driver.get("https://httpbin.org/ip")
print(driver.page_source)
driver.quit()
This approach is ideal for server-side scenarios — when the script runs on a dedicated VPS with a fixed external IP, and you write it in the whitelist once. The downside arises when the machine's IP changes frequently (for example, home internet with a dynamic IP or cloud functions with ephemeral addresses) — then the whitelist will have to be updated manually with each run, which is inconvenient for automation.
Comparison of methods
| Method | Complexity | Headless mode | When to use |
|---|---|---|---|
| Chrome extension | Medium | Limited | Account farming, visual automation |
| Selenium Wire | Low | Yes | Scraping, fast proxy rotation |
| CDP / Fetch.authRequired | High | Yes | Custom automation framework |
| IP-whitelist without password | Minimal | Yes | Servers with fixed IP |
Checklist for debugging proxy authentication issues
- Check if the system dialog appears when running without headless mode — this is a 100% sign of a 407 issue.
- Ensure that the proxy port is specified correctly: HTTP and SOCKS5 often operate on different ports with the same provider.
- If using Selenium Wire, check the version — older releases may conflict with Chrome 115+.
- For the Chrome extension, ensure that the zip archive is rebuilt with each change of the proxy login/password.
- When working with SOCKS5 authentication, keep in mind: native SOCKS5 in Chrome does not support login/password at all — you need an HTTP tunnel or Selenium Wire.
- Check the logs of the proxy provider: sometimes a 407 occurs not due to the code, but due to an expired plan or incorrect login format (with session/geo suffixes).
Conclusion
The --proxy-server flag in Chrome
has never supported passing the login and password directly in the string — this is a feature of the Chromium architecture,
not a Selenium error. There are four working workarounds: a custom extension with interception of
onAuthRequired,
the Selenium Wire library, low-level work through CDP, or a complete refusal of the password in favor of IP-whitelist.
For most scraping and testing automation tasks, Selenium Wire is sufficient; for visual work with
anti-detect profiles, the Chrome extension is more convenient.
If you are setting up automation on servers with a fixed IP, consider datacenter proxies with binding via whitelist — this completely eliminates the authentication problem in Chrome. And for tasks that require changing the login and password on the fly with geo rotation, residential proxies are better suited in conjunction with Selenium Wire — this way you get both flexibility and connection stability without authentication dialog boxes.