Selenium proxy setup: Connect SOCKS5/HTTP proxies to Chrome & Firefox
This guide shows Selenium 4 Chrome/Firefox proxy setup and IP auth workarounds for Chrome's password limitations.
Why is proxy auth hard in Selenium?
Chrome accepts proxy addresses via the --proxy-server launch argument, but doesn't support username/password authentication within the address. When connecting to proxies requiring credentials, Chrome shows an authentication popup that's difficult to handle with Selenium.
Cleanest solution: IP authorization. Register your Selenium server's IPv4 in dashboard to use proxies without credentials - just ip:port in Chrome. Supports up to 10 IPs for multiple servers.
The example uses IP 198.51.100.23, HTTP port 8000, and SOCKS5 port 1080.
pip install seleniumHow do I connect an HTTP proxy to Chrome?
After enabling IP auth, configure Chrome with --proxy-server argument. Selenium 4.6+ automatically fetches chromedriver via Selenium Manager.
The same arguments apply even in headless mode. To verify the connection, open an IP check address and see if the displayed IP is the proxy IP.
from selenium import webdriver
from selenium.webdriver.common.by import By
opts = webdriver.ChromeOptions()
opts.add_argument("--proxy-server=http://198.51.100.23:8000") # this machine's IP is authorized in the dashboard
opts.add_argument("--headless=new")
driver = webdriver.Chrome(options=opts)
try:
driver.get("https://api.ipify.org")
print(driver.find_element(By.TAG_NAME, "body").text) # should print the proxy IP
finally:
driver.quit()How do I use a SOCKS5 proxy in Chrome?
Use socks5:// address in --proxy-server. Chrome performs DNS resolution through the proxy with SOCKS5, but some environments may still use local DNS. Adding --host-resolver-rules to block local resolution is a common workaround.
SOCKS5 also works with IP auth because Chrome doesn't support SOCKS username/password authentication.
from selenium import webdriver
opts = webdriver.ChromeOptions()
opts.add_argument("--proxy-server=socks5://198.51.100.23:1080")
# make sure host names are resolved through the proxy
opts.add_argument('--host-resolver-rules=MAP * ~NOTFOUND , EXCLUDE 198.51.100.23')
driver = webdriver.Chrome(options=opts)
driver.get("https://api.ipify.org")
print(driver.page_source)
driver.quit()How do I connect with Firefox?
Firefox configures proxies via preferences: Set network.proxy.type to 1 (manual), enter HTTP/SOCKS address/port. For SOCKS5, set network.proxy.socks_version to 5 and network.proxy.socks_remote_dns to True for proxy-side DNS resolution.
Firefox lacks launch options for proxy credentials - IP authorization is simplest.
from selenium import webdriver
opts = webdriver.FirefoxOptions()
opts.set_preference("network.proxy.type", 1)
opts.set_preference("network.proxy.socks", "198.51.100.23")
opts.set_preference("network.proxy.socks_port", 1080)
opts.set_preference("network.proxy.socks_version", 5)
opts.set_preference("network.proxy.socks_remote_dns", True)
driver = webdriver.Firefox(options=opts)
driver.get("https://api.ipify.org")
print(driver.page_source)
driver.quit()How do I launch multiple browsers with different IPs simultaneously?
Launch browsers separately with different proxy addresses. This sample code fetches ip:port lists via API to launch 3 browsers on different IPs. Adjust concurrency based on server capacity.
For long browser sessions, it's best to assign one dedicated IP per browser and keep it unchanged until the task completes.
import requests
from selenium import webdriver
KEY = "YOUR_API_KEY"
lines = requests.get(
"https://socks5proxy.io/api/v1/proxies/download",
params={"format": "ip:port", "protocol": "http"},
headers={"Authorization": "Bearer " + KEY},
timeout=30,
).text.split()
drivers = []
for line in lines[:3]:
opts = webdriver.ChromeOptions()
opts.add_argument("--headless=new")
opts.add_argument("--proxy-server=http://" + line)
drivers.append(webdriver.Chrome(options=opts))
for d in drivers:
d.get("https://api.ipify.org")
print(d.page_source)
d.quit()What if username/password authentication is mandatory?
For environments without fixed IPs (e.g., rotating outbound IPs): 1) Use middleware like selenium-wire for auth, or 2) Run a local proxy that handles Socks5Proxy authentication.
Both methods add one more component to manage. If possible, using IP authorization from a fixed IP server is simplest and fastest.
What settings adjust browsers for local authenticity?
Set Chrome's --lang argument and Accept-Language header to match your target IP country for localized content. For time-sensitive sites, use CDP command Emulation.setTimezoneOverride to align timezones.
Set window size with --window-size argument. For mobile views, enable device emulation. Save these as country-specific presets to run consistent tests across regions.
from selenium import webdriver
opts = webdriver.ChromeOptions()
opts.add_argument("--proxy-server=http://198.51.100.23:8000")
opts.add_argument("--lang=de-DE")
opts.add_argument("--window-size=1366,900")
driver = webdriver.Chrome(options=opts)
driver.execute_cdp_cmd("Emulation.setTimezoneOverride", {"timezoneId": "Europe/Berlin"})
driver.get("https://example.com/")
driver.quit()Does this work with Selenium Grid or remote browsers?
Yes. ChromeOptions and FirefoxOptions work remotely too. Pass the same options to webdriver.Remote, and Grid nodes' browsers will use those proxies. For IP auth, register the Grid node's outgoing IP, not your local PC.
For multiple nodes, register all their IPs (max 10). Attaching fixed IPs to cloud nodes simplifies management in dynamic environments.
from selenium import webdriver
opts = webdriver.ChromeOptions()
opts.add_argument("--proxy-server=http://198.51.100.23:8000") # authorize the Grid node IP, not this machine
driver = webdriver.Remote(command_executor="http://grid.example.internal:4444", options=opts)
driver.get("https://api.ipify.org")
print(driver.page_source)
driver.quit()What should I check if the connection doesn't work?
ERR_PROXY_CONNECTION_FAILED often indicates incorrect address/port. Verify you're not using SOCKS5 port for HTTP address. ERR_TUNNEL_CONNECTION_FAILED or auth popups suggest IP mismatch - check your outgoing IP via curl api.ipify.org without proxy and register it.
Cloud servers may change outgoing IPs upon restart. Use a fixed IP or update the registration list in the dashboard when the IP changes.