Skip to content
Browser automation (Python)

How to use proxies with Selenium in Python

Selenium can set a proxy with --proxy-server=http://HOST:PORT, but Chrome ignores a username and password in that flag. Either authorize your machine's IP for your CleanProxies ISP proxies (no password needed), or load a small Manifest V3 extension that sets the proxy and answers the login.

What you need

Proxy authentication is the classic Selenium headache. There is no Chrome flag for proxy credentials, Chrome supports no SOCKS5 authentication at all, and the popular selenium-wire package has been archived since January 2024. These are the approaches that still work.
  • An active CleanProxies plan: static ISP proxies for fixed US IPs, or rotating residential / mobile proxies for pools. The trial works too.
  • Your credential line from the dashboard's proxy manager: host (or IP), port, username and password.
  • Python 3.9+ and pip install selenium (Selenium Manager fetches the driver).
  • Chrome, Chromium or Chrome for Testing.

New to proxies? For the overview, read Proxies with Python Requests, Playwright and Puppeteer. This guide goes deeper on Selenium only.

Your CleanProxies credentials

Every CleanProxies product works over HTTP(S) and SOCKS5. This is what the dashboard gives you.
ProductLine in your dashboardNotes
Static ISP proxiesIP:PORT:USER:PASSOne line per dedicated IP. With IP whitelisting turned on, the line is just IP:PORT and no password is sent.
Rotating residential and mobileHOST:PORT:USER:PASSGenerated in the proxy manager. The username carries the location and session you pick, so generate a new list to change them.

Most tools want the same details as a URL: http://USERNAME:PASSWORD@HOST:PORT for HTTP(S) or socks5://USERNAME:PASSWORD@HOST:PORT for SOCKS5. The examples on this page use those placeholders; copy the host, port, username and password from your CleanProxies dashboard. To convert a whole list at once, paste it into the proxy list formatter.

How to set up CleanProxies in Selenium

  1. 1

    Choose an auth method

    IP whitelisting is simplest for ISP proxies on a fixed server; the extension works with username and password on any product.
  2. 2

    Set the proxy

    Add --proxy-server=http://HOST:PORT (whitelisting) or load the extension, which sets the proxy itself.
  3. 3

    Start the driver

    Create webdriver.Chrome(options=options).
  4. 4

    Check the exit IP

    Open https://api.ipify.org and print driver.find_element("tag name", "body").text.

Option 1: IP whitelisting (no password)

In the CleanProxies dashboard, authorize the public IP of the machine that runs Selenium for your ISP proxies. The line becomes IP:PORT, and Chrome connects without a login prompt. SOCKS5 works here too, because no authentication is involved.

Chrome with a whitelisted ISP proxyPython
from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument("--proxy-server=http://IP:PORT")  # or socks5://IP:PORT

driver = webdriver.Chrome(options=options)
driver.get("https://api.ipify.org")
print("Exit IP:", driver.find_element("tag name", "body").text)
driver.quit()

Option 2: a Manifest V3 extension for username and password

A tiny extension sets the proxy with chrome.proxy and answers the proxy's 407 challenge with webRequest.onAuthRequired. Save these two files in a folder such as proxy_auth/.

proxy_auth/manifest.jsonJSON
{
  "manifest_version": 3,
  "name": "CleanProxies auth",
  "version": "1.0",
  "permissions": ["proxy", "webRequest", "webRequestAuthProvider"],
  "host_permissions": ["<all_urls>"],
  "background": { "service_worker": "background.js" }
}
proxy_auth/background.jsJavaScript
chrome.proxy.settings.set({
  value: {
    mode: "fixed_servers",
    rules: {
      singleProxy: { scheme: "http", host: "HOST", port: PORT },
      bypassList: ["localhost", "127.0.0.1"],
    },
  },
  scope: "regular",
});

chrome.webRequest.onAuthRequired.addListener(
  (details, callback) => {
    if (!details.isProxy) return callback({});
    callback({ authCredentials: { username: "USERNAME", password: "PASSWORD" } });
  },
  { urls: ["<all_urls>"] },
  ["asyncBlocking"],
);
Load it from SeleniumPython
import os
from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument(f"--load-extension={os.path.abspath('proxy_auth')}")

driver = webdriver.Chrome(options=options)
driver.get("https://api.ipify.org")
print(driver.find_element("tag name", "body").text)

Branded Google Chrome 137 and later ignore --load-extension; it still works in Chromium and Chrome for Testing. On branded Chrome, recent Selenium releases can install the folder at runtime instead: set options.enable_webextensions = True and call driver.webextension.install(path="proxy_auth") before the first navigation.

Selenium BiDi and selenium-wire

  • Selenium's WebDriver BiDi API adds driver.network.add_auth_handler("USERNAME", "PASSWORD") after you set options.enable_bidi = True. It answers HTTP authentication challenges; combine it with --proxy-server=http://HOST:PORT and test it with your Chrome version before relying on it for proxy logins.
  • selenium-wire (seleniumwire_options={"proxy": {...}}) is archived and unmaintained since January 2024, with its last release in 2022. It may still run in old projects, but don't build anything new on it.
  • Firefox has the same limitation: proxy preferences take host and port, not credentials. The extension approach (as a Firefox add-on) or IP whitelisting apply there too.

Static ISP vs rotating residential in Selenium

Both products use the same setup. What changes is how long an IP stays with you.

Static ISP proxies

With IP whitelisting, each ISP line is a dedicated US IP you can hand to one driver per account, with no extension and unlimited bandwidth. The address never changes between runs.

Static ISP ProxiesAs low as $0.75/IP

Rotating residential proxies

Residential lines need username and password, so use the extension. Generate sticky lines so a whole Selenium session stays on one IP; one extension folder per line keeps drivers on separate identities.

Rotating Residential ProxiesAs low as $0.63/GB

Verify your exit IP

Each example prints the exit IP. If you see your own IP, the proxy wasn't applied: on branded Chrome 137+, check that the extension was actually installed.

Open What is my IP? through the proxy to see the address and headers a website receives, or paste up to ten lines into the free proxy checker to test connectivity, latency and exit IP before you start.

Troubleshooting Selenium proxy errors

ProblemLikely causeFix
A login popup appears in ChromeCredentials can't be passed through --proxy-server.Use the extension or IP whitelisting.
Extension doesn't loadBranded Chrome 137+ ignores --load-extension.Use Chrome for Testing/Chromium, or driver.webextension.install() with enable_webextensions.
ERR_TUNNEL_CONNECTION_FAILEDWrong credentials in background.js, or IP not whitelisted.Copy the line again; authorize the server's current public IP.
SOCKS5 with password failsChrome supports no SOCKS5 authentication.Use scheme: "http" in the extension, or SOCKS5 with whitelisting.
ModuleNotFoundError or crashes in selenium-wireAn archived package with outdated dependencies.Move to the extension or IP whitelisting.

Still stuck? Our 24/7 support team answers fast: contact us with the error and the line you used (leave the password out).

Selenium proxy FAQs

Chrome reads only the scheme, host and port from that flag and ignores credentials. Authentication has to be answered separately, by an extension, a BiDi auth handler, or avoided with IP whitelisting.

Get CleanProxies for Selenium

Super clean US ISP IPs from $0.75/IP with unlimited bandwidth, rotating residential from $0.63/GB and mobile from $0.79/GB. Instant delivery, 99.9% uptime and 24/7 support.