Selenium proxy setup in Python and Java
Selenium can route a browser through a proxy in a couple of lines — but authenticated proxies need an extension or an outbound helper, because Chrome will not take USER:PASS on the command line. Here is the reliable pattern.
The authentication problem in Selenium
Setting an unauthenticated proxy in Selenium is trivial: add --proxy-server=http://host:3128 to Chrome options, or fill Selenium's Proxy object, and you are done. The moment the proxy needs a username and password, that simple path breaks — Chrome refuses credentials inline, and unlike Puppeteer or Playwright, Selenium has no built-in authenticate() hook to answer the 407 challenge.
The robust, cross-language fix is a tiny Chrome extension generated at runtime that carries your credentials and answers the proxy's auth request through the webRequest API. It works headless, needs no extra services, and behaves the same in Python and Java. With s4m you point the extension at proxy.s4m.online:3128 (HTTP) and your USER:PASS. See the proxy page and the authentication guide for background; for a no-auth option during testing, the free list has open proxies you can drop straight into the command-line flag.
Authenticated proxy via a generated extension
This Python helper writes a throwaway Chrome extension carrying your credentials, then loads it. Replace USER:PASS before running.
import os, zipfile, tempfile
from selenium import webdriver
HOST, PORT, USER, PASS = "proxy.s4m.online", 3128, "USER", "PASS"
manifest = '{"version":"1.0.0","manifest_version":2,"name":"s4m-proxy",'\
'"permissions":["proxy","webRequest","webRequestBlocking","<all_urls>"],'\
'"background":{"scripts":["bg.js"]}}'
bg = ('var c={mode:"fixed_servers",rules:{singleProxy:'
'{scheme:"http",host:"%s",port:%d}}};'
'chrome.proxy.settings.set({value:c,scope:"regular"},function(){});'
'chrome.webRequest.onAuthRequired.addListener('
'function(d){return {authCredentials:{username:"%s",password:"%s"}};},'
'{urls:["<all_urls>"]},["blocking"]);') % (HOST, PORT, USER, PASS)
path = os.path.join(tempfile.mkdtemp(), "s4m_proxy.zip")
with zipfile.ZipFile(path, "w") as z:
z.writestr("manifest.json", manifest)
z.writestr("bg.js", bg)
opts = webdriver.ChromeOptions()
opts.add_extension(path)
driver = webdriver.Chrome(options=opts)
driver.get("https://api.ipify.org")
print("Exit IP:", driver.find_element("tag name", "body").text)
driver.quit()
# ----- Java (unauthenticated proxy) -----
// Proxy p = new Proxy();
// p.setHttpProxy("proxy.s4m.online:3128");
// ChromeOptions o = new ChromeOptions();
// o.setProxy(p);
// WebDriver driver = new ChromeDriver(o);Choosing your approach
Pick based on whether the proxy needs credentials.
No auth? Use the flag
For an unauthenticated proxy, just add --proxy-server=http://host:3128 to ChromeOptions, or set Selenium's Proxy object. Nothing else needed.
Auth? Generate an extension
For USER:PASS proxies, ship a tiny runtime extension that answers onAuthRequired. It works headless and behaves the same across languages.
HTTP endpoint for browsers
Use proxy.s4m.online:3128 (HTTP). Authenticated SOCKS5 inside a browser is unreliable, so keep SOCKS5 for CLI and library clients.
Keep the extension private
The generated extension embeds your credentials in a temp file. Write it to a private temp dir and clean it up after the run.
Reliability and honest expectations
Selenium drives a real browser, which is both its strength and its cost: it is heavier than a raw HTTP client, so keep sessions purposeful and close drivers promptly. If you only need HTML, an HTTP client behind a proxy is far cheaper — see scraping with requests. Reach for Selenium when JavaScript rendering or genuine user interaction is required.
As always, a proxy changes your IP, not your fingerprint. s4m proxies are datacenter — ideal for functional testing, monitoring and moderate scraping, but detectable as datacenter on hostile sites. When a login or allowlist expects one stable address, add a dedicated personal IP. For newer projects, consider Playwright, whose native proxy auth avoids the extension dance entirely. Verify exits with the tools and read the API docs to automate credential rotation.
Questions, answered
Why can't I put USER:PASS in Selenium's proxy flag?
Chrome ignores credentials in the --proxy-server flag and instead raises a native auth prompt a headless browser cannot answer. The reliable fix is a small runtime Chrome extension that responds to onAuthRequired with your username and password.
Is there a simpler way for unauthenticated proxies?
Yes. Without credentials you can just add --proxy-server=http://host:3128 to ChromeOptions, or fill Selenium's Proxy object in Java. The extension is only needed when the proxy requires USER:PASS.
Should I use SOCKS5 or HTTP with Selenium?
Use the HTTP endpoint on port 3128 for browsers. Authenticated SOCKS5 in a browser is unreliable; keep SOCKS5 for command-line and library clients.
Would Playwright be easier?
Often, yes. Playwright takes proxy credentials natively in its proxy object, so you skip the extension entirely. Selenium is still the right pick when your project already depends on it.
Drive browsers through a proxy
Authenticated datacenter proxies on proxy.s4m.online, ready for Selenium via a generated extension. Metered pay-as-you-go, with a dedicated IP option for stable logins.
People found this page by searching for
- Selenium proxy setup in Python and java
- what is proxy for scraping
- how to avoid IP bans when scraping
- proxy for scraping
- proxychains: how to chain SOCKS5 proxies
- free proxy list comparison
- best VPN protocols in 2026
- ip address for scraping
- proxy authentication
- download proxy authentication
- fresh proxy setup
- how to check if a proxy is valid (with a ready script)
- proxy setup
- working free proxy list
- openvpn for windows
- ip address for android
- ip address
Real search phrases this page answers — the linked ones open the page that covers them in depth.