Prompt
How do I use proxies with Selenium?
Latest observation
Oct 10, 2026
OpenAI APIWeb search: off
To use a proxy with Selenium, you typically configure the browser you’re automating to route traffic through the proxy before launching it.
Chrome
Python example
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
proxy = "http://127.0.0.1:8080" # or http://user:pass@host:port for simple auth
options = Options()
options.add_argument(f'--proxy-server={proxy}')
driver = webdriver.Chrome(options=options)
driver.get("https://example.com")
Notes
- For HTTP/HTTPS proxies,
--proxy-server=is usually enough. - For SOCKS proxies:
options.add_argument("--proxy-server=socks5://127.0.0.1:9050") - Chrome does not reliably support proxy auth via
user:pass@host:portin all cases; authenticated proxies often need extra handling.
Firefox
Python example
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
profile = FirefoxProfile()
profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.http", "127.0.0.1")
profile.set_preference("network.proxy.http_port", 8080)
profile.set_preference("network.proxy.ssl", "127.0.0.1")
profile.set_preference("network.proxy.ssl_port", 8080)
profile.update_preferences()
driver = webdriver.Firefox(firefox_profile=profile)
driver.get("https://example.com")
SOCKS example
profile = FirefoxProfile()
profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.socks", "127.0.0.1")
profile.set_preference("network.proxy.socks_port", 9050)
profile.set_preference("network.proxy.socks_version", 5)
profile.update_preferences()
Using Selenium 4 / W3C proxy settings
You can also configure proxy settings via Proxy capabilities.
Python example
from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy, ProxyType
proxy = Proxy()
proxy.proxy_type = ProxyType.MANUAL
proxy.http_proxy = "127.0.0.1:8080"
proxy.ssl_proxy = "127.0.0.1:8080"
capabilities = webdriver.DesiredCapabilities.CHROME.copy()
proxy.add_to_capabilities(capabilities)
driver = webdriver.Chrome(desired_capabilities=capabilities)
Authenticated proxies
If your proxy needs a username/password, common approaches are:
- Use browser-specific proxy auth extensions
- Use a local proxy helper that injects credentials
- Use tools like Selenium Wire (often easiest for intercepting and proxying requests)
Example with selenium-wire:
from seleniumwire import webdriver
options = {
'proxy': {
'http': 'http://user:pass@host:port',
'https': 'https://user:pass@host:port',
'no_proxy': 'localhost,127.0.0.1'
}
}
driver = webdriver.Chrome(seleniumwire_options=options)
Quick tips
- Set the proxy before creating the driver.
- Make sure the proxy supports the protocol you need.
- If websites behave oddly, check for:
- DNS leaks
- HTTPS certificate issues
- WebRTC leaks in browsers
- For headless mode, proxy settings work similarly.
If you tell me your language and browser (Chrome/Firefox/Edge) and whether your proxy needs authentication, I can give you a ready-to-run snippet.