When you’re running a Selenium script and your IP suddenly gets blocked mid-run, it’s enough to derail your entire workflow. That’s exactly where proxies come in. They give you control over how your automated browser interacts with the web—whether you need anonymity, geo-targeting, or multiple clean sessions. With the right proxy setup, your Selenium workflow becomes far more robust, stealthy, and flexible. Let’s cut through the noise and dive straight into setting up proxies in Selenium. We’ll cover Chrome and Firefox, handle authentication, explore SOCKS proxies, and even touch on proxy rotation for serious automation.

A proxy isn't just a shield—it's a tool. Here's what it can do for you:
Change your IP to avoid blocks.
Bypass rate limits for high-volume requests.
Access geo-restricted content seamlessly.
Separate multiple sessions without conflicts.
Enhance anonymity when scraping sensitive data.
If your Selenium automation gets blocked frequently, integrating proxies is necessary. It's the difference between smooth execution and hitting constant roadblocks.
Selenium doesn't set proxies directly. Instead, it passes proxy settings to the browser via options or capabilities. Chrome, Firefox, and Edge all have slightly different methods, so knowing the nuances is crucial.
Requirements for proxy setup:
Selenium WebDriver
Browser driver (e.g., ChromeDriver)
Proxy server (host and port)
Optional: username/password for authenticated proxies
Once configured, Selenium will route all browser traffic through the specified proxy, making your automation safer and more realistic.
For a simple HTTP/HTTPS proxy (no authentication):
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
proxy = "123.45.67.89:8080"
chrome_options = Options()
chrome_options.add_argument(f"--proxy-server=http://{proxy}")
driver = webdriver.Chrome(options=chrome_options)
driver.get("https://example.com")
Want to run headless? Just add:
chrome_options.add_argument("--headless")
Chrome can't handle username/password proxies directly from command-line flags. Instead, you can generate a small Chrome extension dynamically:
import zipfile
def create_extension(proxy_host, proxy_port, username, password):
manifest = """
{
"version": "1.0.0",
"manifest_version": 2,
"name": "ProxyAuth",
"permissions": ["proxy", "tabs", "unlimitedStorage", "storage", "<all_urls>", "webRequest", "webRequestBlocking"],
"background": {
"scripts": ["background.js"]
}
}
"""
background = f"""
chrome.proxy.settings.set({ {
value: { {
mode: "fixed_servers",
rules: { {
singleProxy: { {
scheme: "http",
host: "{proxy_host}",
port: parseInt({proxy_port})
}}
}}
}},
scope: "regular"
}});
chrome.webRequest.onAuthRequired.addListener(
function handler(details) { {
return { {
authCredentials: { {username: "{username}", password: "{password}"}}
}};
}},
{ {urls: ["<all_urls>"]}},
["blocking"]
);
"""
with zipfile.ZipFile("proxy_auth.zip", "w") as zp:
zp.writestr("manifest.json", manifest)
zp.writestr("background.js", background)
Load the extension:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
proxy_host = "123.45.67.89"
proxy_port = "8080"
username = "user123"
password = "pass123"
create_extension(proxy_host, proxy_port, username, password)
chrome_options = Options()
chrome_options.add_extension("proxy_auth.zip")
driver = webdriver.Chrome(options=chrome_options)
driver.get("https://example.com")
Selenium Wire is another way to handle proxy authentication and inspect traffic seamlessly.
Firefox makes proxy configuration more direct through profiles:
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
profile = webdriver.FirefoxProfile()
profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.http", "123.45.67.89")
profile.set_preference("network.proxy.http_port", 8080)
profile.set_preference("network.proxy.ssl", "123.45.67.89")
profile.set_preference("network.proxy.ssl_port", 8080)
profile.update_preferences()
driver = webdriver.Firefox(firefox_profile=profile, options=Options())
driver.get("https://example.com")
Selenium supports SOCKS proxies, perfect for high-anonymity use cases:
proxy = "123.45.67.89:1080"
chrome_options = Options()
chrome_options.add_argument(f"--proxy-server=socks5://{proxy}")
driver = webdriver.Chrome(options=chrome_options)
driver.get("https://example.com")
Headless mode + SOCKS proxies = fully automated, stealthy browsing.
Single proxies get blocked fast. Rotate them to stay ahead:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import random
proxies = [
"123.45.67.89:8080",
"98.76.54.32:3128",
"11.22.33.44:8000"
]
def get_random_proxy():
return random.choice(proxies)
for i in range(5):
proxy = get_random_proxy()
chrome_options = Options()
chrome_options.add_argument(f"--proxy-server=http://{proxy}")
driver = webdriver.Chrome(options=chrome_options)
driver.get("https://httpbin.org/ip")
print(driver.page_source)
driver.quit()
Rotate intelligently to bypass IP bans, geo-restrictions, and anti-scraping defenses.
Verify that Selenium is using your proxy:
driver.get("https://httpbin.org/ip")
Check the returned IP. It should match your proxy.
Proxy not applied: Ensure the proxy type matches (http, https, socks4, socks5).
Authentication popup: Use the custom extension approach for Chrome.
Connection errors: Double-check firewall, timeout, or credentials.
HTTPS issues: Some proxies only support HTTP; CONNECT tunneling may be required.
Setting up a proxy in Selenium isn't complicated—but doing it right makes automation far more reliable. Whether you're testing, scraping, or geo-targeting, proxies let you simulate real users, manage sessions, and bypass blocks. Use Chrome or Firefox options, handle authentication smartly, rotate your proxies, and your Selenium scripts will run like clockwork.