How to Use a Proxy with Selenium (Chrome, Firefox and Authentication)

Short answer: pass the proxy host and port to the browser: --proxy-server=http://{PROXY_HOST}:{PORT} for Chrome, or Selenium’s Proxy class for Chrome and Firefox. The catch: Chrome and Firefox do not accept a username and password in that setting, so for authenticated proxies you need IP whitelisting, a local forwarding proxy, or selenium-wire.

This guide shows the basic setup, explains why authentication fails, and gives three ways around it. It is part of our guide to proxies for web scraping. If you do not have to use Selenium, Playwright handles proxy credentials natively and is simpler for authenticated proxies.

Use proxies for public data and legitimate testing only: market research, price monitoring, ad verification, SEO checks and QA. Respect each site’s terms and robots.txt.

Prerequisites

  • Python 3.8 or newer and Selenium 4: pip install selenium
  • Chrome or Firefox installed. Selenium 4.6 and newer downloads the matching driver automatically through Selenium Manager.
  • Proxy details from your dashboard: host and port, plus username and password if your plan uses them. New to these terms? Read what a proxy host and port are.

Chrome: set the proxy server

from selenium import webdriver
from selenium.webdriver.common.by import By

options = webdriver.ChromeOptions()
options.add_argument("--proxy-server=http://{PROXY_HOST}:{PORT}")
# options.add_argument("--headless=new")  # optional: run without a window

driver = webdriver.Chrome(options=options)
try:
    driver.set_page_load_timeout(60)
    driver.get("https://httpbin.org/ip")
    print(driver.find_element(By.TAG_NAME, "body").text)
finally:
    driver.quit()

The printed origin should be the proxy’s IP, not yours. This works as is when your proxy authenticates by IP address (whitelisting). For other ways to check a proxy, see how to test proxies.

Chrome and Firefox: the Proxy class

Selenium’s Proxy object works for both browsers:

from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy, ProxyType

proxy = Proxy()
proxy.proxy_type = ProxyType.MANUAL
proxy.http_proxy = "{PROXY_HOST}:{PORT}"
proxy.ssl_proxy = "{PROXY_HOST}:{PORT}"

options = webdriver.FirefoxOptions()  # or webdriver.ChromeOptions()
options.proxy = proxy

driver = webdriver.Firefox(options=options)
driver.get("https://httpbin.org/ip")
print(driver.page_source)
driver.quit()

Note that the values are host:port without a scheme and without credentials.

Why credentials in the proxy URL do not work

This is the part that trips most people up. If you write --proxy-server=http://USERNAME:PASSWORD@{PROXY_HOST}:{PORT}, Chrome ignores the credentials. Depending on the version you may see an authentication dialog that Selenium cannot click, a 407 page, or errors such as ERR_NO_SUPPORTED_PROXIES. Firefox behaves similarly: it shows a login prompt that WebDriver does not handle.

You have three practical options.

Option 1: IP whitelisting (simplest)

If your plan lets you whitelist your server’s public IP in the dashboard, you do not need credentials at all. Use the Chrome or Firefox examples above. This is the most stable setup, but it only works when your own IP stays the same. See what IP whitelisting is.

Option 2: a local forwarding proxy

Run a small local proxy that adds your credentials, then point Selenium at it without authentication. For example, with the open-source pproxy package:

pip install pproxy
pproxy -l http://127.0.0.1:8888 -r "http://{PROXY_HOST}:{PORT}#USERNAME:PASSWORD"

Then in Selenium:

options = webdriver.ChromeOptions()
options.add_argument("--proxy-server=http://127.0.0.1:8888")
driver = webdriver.Chrome(options=options)

Check the pproxy documentation for the exact syntax on your version. Any local forwarder that supports upstream authentication works the same way. Keep it bound to 127.0.0.1 so that nobody else can use it.

Option 3: selenium-wire

selenium-wire adds proxy authentication on top of Selenium:

pip install selenium-wire
from seleniumwire import webdriver

PROXY_URL = "http://USERNAME:PASSWORD@{PROXY_HOST}:{PORT}"

seleniumwire_options = {
    "proxy": {
        "http": PROXY_URL,
        "https": PROXY_URL,
        "no_proxy": "localhost,127.0.0.1",
    }
}

driver = webdriver.Chrome(seleniumwire_options=seleniumwire_options)
driver.get("https://httpbin.org/ip")
print(driver.page_source)
driver.quit()

Be aware that selenium-wire is no longer actively maintained. It can break with newer versions of Selenium or its dependencies (for example the blinker package), and it intercepts HTTPS traffic through its own certificate. Pin your versions, test before relying on it in production, and prefer Option 1 or 2 for long-running jobs.

Special characters in the password

If the password contains characters such as @, : or /, URL-encode it before building any proxy URL:

from urllib.parse import quote

user = quote("USERNAME", safe="")
password = quote("PASSWORD", safe="")
PROXY_URL = f"http://{user}:{password}@{{PROXY_HOST}}:{{PORT}}"

The doubled braces keep the {PROXY_HOST} and {PORT} placeholders literal. In real code, replace them with your values and use single braces for your own variables.

Rotation and sessions

If your plan gives you a rotating gateway, one proxy configuration is enough, and new IPs appear on the schedule or per connection that you set. USA 4G/5G proxies rotate every 5, 10 or 30 minutes depending on your setting. If a flow must keep one IP across several page loads, use a sticky session or a static IP and keep the whole flow in one driver instance. Check your dashboard for the exact options. For trade-offs, see rotating vs static residential proxies.

Selenium cannot change the proxy of a running Chrome session. To use a different proxy, start a new driver.

Save bandwidth on per-GB plans

A browser downloads everything a page references. On per-GB plans such as residential proxies, disable what you do not need. In Chrome, for example, images:

options = webdriver.ChromeOptions()
options.add_argument("--proxy-server=http://{PROXY_HOST}:{PORT}")
options.add_experimental_option(
    "prefs", {"profile.managed_default_content_settings.images": 2}
)

Test the effect on a small sample first, because some pages render differently without images. With USA 4G/5G mobile proxies (unlimited bandwidth, billed by time), this matters less.

Wait for pages, then handle failures

import random
import time

from selenium.common.exceptions import TimeoutException, WebDriverException
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait


def load(driver, url, retries=3):
    for attempt in range(retries):
        try:
            driver.get(url)
            WebDriverWait(driver, 20).until(
                EC.presence_of_element_located((By.TAG_NAME, "body"))
            )
            return driver.page_source
        except (TimeoutException, WebDriverException) as exc:
            print(f"attempt {attempt + 1} failed: {exc.msg}")
            time.sleep(2 ** attempt + random.random())
    raise RuntimeError(f"Failed after {retries} attempts: {url}")
SymptomLikely causeFix
ERR_PROXY_CONNECTION_FAILEDWrong host or port, or proxy unreachableVerify {PROXY_HOST} and {PORT}, test with curl
ERR_NO_SUPPORTED_PROXIES or a login promptCredentials placed in --proxy-serverRemove them and use whitelisting, a local forwarder or selenium-wire
ERR_TUNNEL_CONNECTION_FAILEDProxy refused the tunnel (bad credentials, IP not whitelisted, blocked destination)Check credentials and the whitelist, try another target
TimeoutExceptionSlow target or heavy pageRaise set_page_load_timeout, block heavy resources, retry with backoff
Your own IP is shownProxy not applied, or a different driver instance is usedCheck that options are passed to the driver you actually start
HTTP 429 from the siteToo many requests to the targetLower concurrency, add delays, back off

Exact error text varies between browser and driver versions, so treat the table as a starting point. A fuller breakdown is in proxy errors: what each one means and how to fix it.

Node.js (selenium-webdriver)

const { Builder } = require("selenium-webdriver");
const chrome = require("selenium-webdriver/chrome");

(async () => {
  const options = new chrome.Options().addArguments(
    "--proxy-server=http://{PROXY_HOST}:{PORT}"
  );
  const driver = await new Builder()
    .forBrowser("chrome")
    .setChromeOptions(options)
    .build();
  try {
    await driver.get("https://httpbin.org/ip");
    console.log(await driver.getPageSource());
  } finally {
    await driver.quit();
  }
})();

The same authentication limit applies, so use whitelisting or a local forwarder for authenticated proxies.

Next steps

Load one page through the proxy, confirm the exit IP, then scale gradually and watch your error rate. For choosing between residential, mobile and ISP proxies and estimating cost, read proxies for web scraping. Using lightweight HTTP clients instead? See Python requests proxy and Scrapy proxy setup.

Need proxies to test with? Compare residential proxies (per GB), USA 4G/5G mobile proxies (per day, unlimited bandwidth) and static ISP proxies (30-day plans), or see the pricing page. Every plan comes with a 24-hour money-back guarantee.

See residential plans

FAQ

How do I set a proxy in Selenium?

For Chrome, add --proxy-server=http://{PROXY_HOST}:{PORT} to ChromeOptions. For Chrome or Firefox you can also set options.proxy with Selenium’s Proxy class using a host:port value.

How do I use a proxy with username and password in Selenium?

Chrome and Firefox do not accept credentials in the proxy setting. Use IP whitelisting if your plan supports it, run a local forwarding proxy that adds the credentials, or use selenium-wire. If you can choose the tool, Playwright accepts username and password directly.

Why does my Selenium proxy show a login prompt or ERR_NO_SUPPORTED_PROXIES?

You most likely put the username and password inside --proxy-server. The browser ignores or rejects them. Remove the credentials from the setting and use one of the authentication options above.

Can I change the proxy while a Selenium session is running?

No. The proxy is set when the browser starts. To use a different proxy, quit the driver and start a new one with new options.

Is selenium-wire still a good choice?

It works for many setups, but it is no longer actively maintained and can conflict with newer Selenium or dependency versions. Pin versions and test it, or choose IP whitelisting or a local forwarder for production jobs.

How do I check that Selenium uses the proxy?

Open https://httpbin.org/ip in the driver and read the origin field. It should show the proxy’s IP, not yours.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.