Integrations menu
Developer guide

Selenium Proxy: Authenticated Setup in Python and Java

To use a proxy in Selenium with Chrome, pass --proxy-server=http://gate.proxyfield.io:<port> in ChromeOptions with your IP on the allowlist, where <port> is the port you set up in the dashboard; for a username and password on gate.proxyfield.io:7000, answer Chrome's login with a small extension or Selenium's network auth handler, because the flag takes no credentials. ProxyField residential proxies cost from $1.95/GB ($2.95/GB for 1 GB), with a 99.6% success rate, according to our service data. Start with the Easy Trial: 1 GB for $2.95, no subscription, and the traffic never expires.

residential IPs
412M+
from, traffic never expires
$1.95/GB
Easy Trial
1 GB for $2.95
gate.proxyfield.io:7000
What goes in a Selenium setup
Selenium settingProxyField value
--proxy-serverhttp://gate.proxyfield.io:7000 for a username and password: HTTP, HTTPS and SOCKS5 run on the same host and port
Username<login>-country-us-city-new_york; the optional keys are -country-<cc>, -region-<region>, -city-<city>, -session-<id> and -ttl-<seconds> (30 to 129,600 s, 20 min when ttl is left out); add -mobile or -dc right after the login for mobile or rotating datacenter IPs (-dc takes the country only)
Passwordyour ProxyField password, given to driver.network.add_auth_handler() or the auth extension, never in the flag
SOCKS5Chrome sends no SOCKS5 username or password, so use the allowlist; Firefox takes SOCKS5 through its preferences, with remote DNS; tools that take a proxy URL write socks5h:// with the same username and password
No passwordadd the machine's IP to the allowlist (up to 100 IPv4 addresses) and use the port you set up in the dashboard in --proxy-server (Method 1)
IP behavioura new IP on every request, or one IP for 30 s to 36 h with -session-<id>-ttl-<seconds>
Sessions at onceunlimited concurrent threads, so several Selenium sessions can run at the same time
Headersthe gateway adds no Via, X-Forwarded-For or Forwarded header; the headers the browser under Selenium sends pass through; your Proxy-Authorization is removed before the request goes to the site
Credentialsin your account dashboard; the configurator generates as many proxy lines as you need

Set up Selenium with ProxyField

  1. Check the login once with curl (section 1).
  2. From a fixed IP: allowlist it and pass --proxy-server=http://gate.proxyfield.io:<port>, with the port you set up in the dashboard.
  3. With a username and password: set options.enable_bidi = True and pass --proxy-server=http://gate.proxyfield.io:7000.
  4. Register the login with driver.network.add_auth_handler(username, password), or load the auth extension (Method 2).
  5. Open https://api.ipify.org?format=json to see the exit IP.

Method 3 in Python, Selenium's network auth handler, with a New York exit IP.

Python
from selenium import webdriver

options = webdriver.ChromeOptions()
options.enable_bidi = True
options.add_argument("--proxy-server=http://gate.proxyfield.io:7000")
driver = webdriver.Chrome(options=options)
driver.network.add_auth_handler("<login>-country-us-city-new_york", "<password>")
driver.get("https://api.ipify.org")
print(driver.find_element("tag name", "body").text)
driver.quit()

Selenium's own guide to its auth handlers: WebDriver BiDi Network Features (Selenium).

Mobile 5G/4G proxies cost $3.45/GB for 1 GB down to $2.45/GB from 1,000 GB on the same gateway and balance, over HTTP, HTTPS and SOCKS5.

Pick your method:

MethodAuthBest whenNeeds
1. IP allowlist + --proxy-serveryour IP is allowlisted in the dashboarda fixed server or office IPnothing extra
2. Auth extension (Manifest V3)username + passworddynamic IPs, laptops, CIChrome for Testing or Chromium
3. Selenium network auth handlerusername + passwordcurrent Selenium with WebDriver BiDia Selenium release with driver.network (Python, 4.32 or later)

Written for Selenium 4.51 (Python and Java).

New to ProxyField? Start with the quick start in the docs.

On this page 14 sections

1. Check the credentials with cURL

Test the gateway before you touch Selenium: one cURL command tells you whether the credentials and targeting work.

Shell
curl -x gate.proxyfield.io:7000 -U "<login>-country-us-city-new_york:<password>" https://api.ipify.org

You should see an IP that is not yours. Check the country with https://ipinfo.io/json or test your proxy in the ProxyField checker. If cURL fails, Selenium will fail too; the cURL setup page covers the errors.

2. Method 1: IP allowlist (simplest)

To set up a proxy in Selenium without credentials, add your public IP to the IP allowlist (IP whitelist) in the dashboard, then pass the gateway to Chrome with --proxy-server on the port you set up in the dashboard (<port> in the code). Chrome needs no username, so nothing else is required.

Python
# pip install selenium   (Selenium Manager downloads the driver)
from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument("--proxy-server=http://gate.proxyfield.io:<port>")  # <port>: the port you set up in the dashboard
driver = webdriver.Chrome(options=options)
driver.get("https://api.ipify.org?format=json")
print(driver.find_element("tag name", "body").text)
driver.quit()

The allowlist only works from the IP you added. A laptop or a CI runner whose IP changes needs Method 2 or 3. The allowlist takes up to 100 IPv4 addresses per account; with the allowlist, the product, location and session are set per port in the dashboard.

3. Method 2: username and password with an auth extension

A small Manifest V3 extension sets the proxy and answers Chrome's auth challenge, so the username and password never touch the command line. It uses chrome.proxy and chrome.webRequest.onAuthRequired with the webRequestAuthProvider permission (Chrome webRequest API, Chrome proxy API).

Create a folder pf-auth with two files. manifest.json:

JSON
{
  "manifest_version": 3,
  "name": "ProxyField auth",
  "version": "1.0",
  "permissions": ["proxy", "webRequest", "webRequestAuthProvider"],
  "host_permissions": ["<all_urls>"],
  "background": { "service_worker": "background.js" }
}

background.js (it reads the credentials from config.js, which the Python helper writes):

JavaScript
importScripts("config.js");

chrome.proxy.settings.set({
  value: {
    mode: "fixed_servers",
    rules: {
      singleProxy: { scheme: "http", host: self.PF.host, port: self.PF.port }
    }
  },
  scope: "regular"
});

chrome.webRequest.onAuthRequired.addListener(
  (details, callback) => {
    if (details.isProxy) {
      callback({ authCredentials: { username: self.PF.username, password: self.PF.password } });
    } else {
      callback({});
    }
  },
  { urls: ["<all_urls>"] },
  ["asyncBlocking"]
);

The Python helper writes config.js and loads the extension:

Python
import json
import os
import pathlib
from selenium import webdriver

EXT_DIR = pathlib.Path("pf-auth").resolve()

def write_credentials(username, password):
    config = {"host": "gate.proxyfield.io", "port": 7000,
              "username": username, "password": password}
    (EXT_DIR / "config.js").write_text("self.PF = " + json.dumps(config) + ";\n")

write_credentials(os.environ["PF_USER"], os.environ["PF_PASS"])  # e.g. <login>-country-us

options = webdriver.ChromeOptions()
options.binary_location = os.environ["CFT_CHROME"]  # path to Chrome for Testing, see the note
options.add_argument(f"--load-extension={EXT_DIR}")
driver = webdriver.Chrome(options=options)
driver.get("https://api.ipify.org?format=json")
print(driver.find_element("tag name", "body").text)
driver.quit()

Keep the credentials in environment variables (PF_USER, PF_PASS), not in the script.

Version note. Branded Google Chrome ignores --load-extension since Chrome 137. Chrome for Testing and Chromium still load it, so point options.binary_location at one of them. Extensions also load in the new headless mode (--headless=new).

4. Method 3: Selenium's network auth handler

Selenium for Python (4.32 and later) has a network auth handler over WebDriver BiDi, with no extension and no MITM certificate. Turn on BiDi, point Chrome at the gateway, and register the credentials with driver.network.add_auth_handler() (Selenium BiDi docs). On port 7000 the gateway asks for the login with a 407 that carries Proxy-Authenticate: Basic, on CONNECT too.

Python
import os
from selenium import webdriver

options = webdriver.ChromeOptions()
options.enable_bidi = True
options.add_argument("--proxy-server=http://gate.proxyfield.io:7000")
driver = webdriver.Chrome(options=options)

handler_id = driver.network.add_auth_handler(os.environ["PF_USER"], os.environ["PF_PASS"])
driver.get("https://api.ipify.org?format=json")
print(driver.find_element("tag name", "body").text)

driver.network.remove_auth_handler(handler_id)
driver.quit()

It loads no extension, so branded Chrome's --load-extension limit does not apply to it; check the exit IP on the first page it opens. Older Selenium releases lack driver.network; upgrade with pip install -U selenium.

5. How do I rotate proxies in Selenium without restarting the browser?

Point Selenium at the gateway once: every new connection gets a new IP, with no proxy list to cycle through and no restart. Chrome keeps connections open, so several loads of the same site can share one IP; to force a new IP, start a new driver. More on how this works: rotating proxies.

Check it in one driver:

Python
for _ in range(3):
    driver.get("https://api.ipify.org?format=json")
    print(driver.find_element("tag name", "body").text)

If all three loads show the same IP, Chrome reused its open connection to the gateway; a new driver opens a new connection and gets a new IP.

For a sticky IP per job, put a session in the username. Sticky sessions run from 30 s to 36 h, with presets of 1, 5, 10 and 30 min and 1, 3 and 6 h. Region, session and session time go in the same username: -region-<region>, -session-<id> and -ttl-<seconds> (30 to 129,600 seconds, 20 minutes by default), as in <login>-country-us-region-new_york-city-new_york-session-he9f2qga-ttl-600; every part after the login is optional. Residential is the default; add -mobile after the login for mobile IPs: <login>-mobile-country-us. To change the session per job:

  • Method 2: call write_credentials() with the new username and start a new driver.
  • Method 3: start a new driver and register the new username with add_auth_handler().
  • Method 1: there is no username: with the allowlist, the session is set per port in the dashboard.

6. Country, city and sticky sessions

Country and city go in the username: <login>-country-us for the United States, <login>-country-us-city-new_york for New York. Targeting covers country, region (state) and city, and in the US all 50 states. All username parameters are in the docs.

TargetUsername
Country<login>-country-us
Country and city<login>-country-us-city-new_york
Region (state)<login>-country-us-region-new_york
Sticky session, 30 s to 36 h<login>-country-us-region-new_york-city-new_york-session-he9f2qga-ttl-600
Mobile IPs (residential is the default)<login>-mobile-country-us

The same gateway serves residential proxies and mobile 5G/4G proxies. ASN, ZIP and carrier targeting are not offered.

7. Java

In Java, add --proxy-server to ChromeOptions with your IP on the allowlist; <port> is the port you set up in the dashboard. Maven: org.seleniumhq.selenium:selenium-java:4.51.0.

Java
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class ProxyFieldSelenium {
    public static void main(String[] args) {
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--proxy-server=http://gate.proxyfield.io:<port>");
        WebDriver driver = new ChromeDriver(options);
        try {
            driver.get("https://api.ipify.org?format=json");
            System.out.println(driver.findElement(By.tagName("body")).getText());
        } finally {
            driver.quit();
        }
    }
}

The org.openqa.selenium.Proxy object does the same through capabilities:

Java
import org.openqa.selenium.Proxy;

Proxy proxy = new Proxy();
proxy.setHttpProxy("gate.proxyfield.io:<port>");
proxy.setSslProxy("gate.proxyfield.io:<port>");
ChromeOptions options = new ChromeOptions();
options.setProxy(proxy);
WebDriver driver = new ChromeDriver(options);

For a username and password in Java, load the Method 2 extension the same way: options.setBinary("/path/to/chrome-for-testing") and options.addArguments("--load-extension=/abs/path/pf-auth").

8. Firefox (geckodriver)

Firefox takes the proxy through preferences, including SOCKS5 with remote DNS. Use the allowlist, or the Method 3 auth handler for a username and password: Firefox supports WebDriver BiDi natively. Port 7000 below is for a username and password; with the allowlist, put the port you set up in the dashboard in its place.

Python
from selenium import webdriver

options = webdriver.FirefoxOptions()
options.set_preference("network.proxy.type", 1)  # manual proxy configuration
options.set_preference("network.proxy.http", "gate.proxyfield.io")
options.set_preference("network.proxy.http_port", 7000)
options.set_preference("network.proxy.ssl", "gate.proxyfield.io")
options.set_preference("network.proxy.ssl_port", 7000)
driver = webdriver.Firefox(options=options)
driver.get("https://api.ipify.org?format=json")
print(driver.find_element("tag name", "body").text)
driver.quit()

For SOCKS5 proxies, replace the four http/ssl lines:

Python
options.set_preference("network.proxy.socks", "gate.proxyfield.io")
options.set_preference("network.proxy.socks_port", 7000)
options.set_preference("network.proxy.socks_version", 5)
options.set_preference("network.proxy.socks_remote_dns", True)

SOCKS5 takes the same username and password. Setting the proxy by hand in the browser instead? See Firefox proxy settings and Chrome proxy settings.

9. selenium-wire: does it still work?

selenium-wire passes user:pass@host:port to the upstream proxy through its own local proxy, but the project has had no release since 5.1.0 (October 15, 2022), and its author archived the GitHub repository (PyPI). It can still install and run, but it gets no fixes; prefer Method 1, 2 or 3.

Python
# pip install selenium-wire
import os
from urllib.parse import quote
from seleniumwire import webdriver

proxy = f"http://{quote(os.environ['PF_USER'], safe='')}:{quote(os.environ['PF_PASS'], safe='')}@gate.proxyfield.io:7000"
seleniumwire_options = {"proxy": {"http": proxy, "https": proxy, "no_proxy": "localhost,127.0.0.1"}}
driver = webdriver.Chrome(seleniumwire_options=seleniumwire_options)
driver.get("https://api.ipify.org?format=json")
print(driver.find_element("tag name", "body").text)
driver.quit()

quote() URL-encodes special characters in the password (p@ss becomes p%40ss). selenium-wire decrypts HTTPS with its own CA certificate (a man-in-the-middle setup), so the browser must trust that certificate. On recent Python versions it may also need pip install "blinker<1.8".

10. Cut traffic

Turn off images to cut what you pay: billing is per GB of traffic, and images make up much of a full page load.

Python
options.add_experimental_option(
    "prefs", {"profile.managed_default_content_settings.images": 2}
)
driver = webdriver.Chrome(options=options)

The dashboard shows real-time usage and the gigabytes you have left, so you can compare a run before and after the change.

11. Detection, user agent and CAPTCHAs

options.add_argument("--user-agent=...") sets the user agent (more in our scraping headers guide ); sites still read navigator.webdriver and the browser fingerprint, which our browser fingerprinting guide covers .

A proxy changes the IP, its location and its reputation. It spreads requests over many IPs, which cuts IP rate-limit blocks. It does not solve CAPTCHAs, and it does not hide a headless browser's fingerprint or TLS signature. Our anti-bot guide explains how sites detect bots and what proxies can and cannot fix.

12. Troubleshooting

SymptomLikely causeFix
407 Proxy Authentication Requiredwrong or missing credentials, or the allowlist doesn't hold your current IPtest with cURL (section 1); add your current IP to the allowlist
An auth popup appears and the script hangsno auth method in placeuse Method 1, 2 or 3
Timeouts or connection refusedwrong host or port, or the wrong protocol on the portuse gate.proxyfield.io:7000 with a username and password, or the port you set up in the dashboard with the allowlist, and the scheme your code expects
ERR_NO_SUPPORTED_PROXIEScredentials inside a socks5:// URL in --proxy-serverChrome takes no credentials in that flag; use the allowlist
The extension doesn't loadbranded Chrome 137 or lateruse Chrome for Testing or Chromium (section 3), or Method 3
Wrong countrythe parameter spelling, or a reused keep-alive connectioncheck the username in cURL; start a new driver
The proxy works in cURL but not in Seleniuman old driver or a typo in the flagupdate Selenium (Selenium Manager fetches the driver); check --proxy-server=
The site loads without the proxythe option never reached the browser, or the host is on a proxy exception listprint options.arguments; remove the host from the exception list
One site category won't loadsome site categories are restricted to protect the network, including financial and government servicessee the acceptable use policy

The gateway answers 407 Proxy Authentication Required for a wrong login or password, an IP not on the allowlist or a malformed location, 402 Payment Required when no traffic is left and 502 Bad Gateway when no exit could be connected; a restricted site gets no separate response, and a 403 comes from the site itself. All gateway responses: proxy errors.

Get started

No minimum purchase, no subscription; the traffic never expires and all purchases are final. See pricing.

Using another framework? See the Playwright and Puppeteer setup pages. For Selenium itself (locators, waits, Grid), our Selenium web scraping tutorial covers the basics.

Selenium Proxy FAQ

How do I set up an authenticated proxy in Selenium with Chrome?

ProxyField sets up in Selenium with Chrome through one gateway, gate.proxyfield.io, from $1.95/GB. Chrome's --proxy-server flag takes no password, so either allowlist your IP and pass the flag with the port you set up in the dashboard, or use port 7000 and answer the login with a Manifest V3 extension or driver.network.add_auth_handler(). Start with the Easy Trial: 1 GB for $2.95.

How do I rotate proxies in Selenium with Python without restarting the browser every time?

Point the driver at the rotating gateway once: every new connection gets a new IP, with no proxy list to cycle through. Chrome reuses open connections, so loads in one driver can share an IP; start a new driver when a job needs a fresh one.

How do I handle proxy authentication in Selenium WebDriver?

Chrome has no credentials flag. Use the IP allowlist, a Manifest V3 extension with onAuthRequired, or Selenium's network auth handler over WebDriver BiDi (Python 4.32 and later).

How do I set up a proxy in Selenium?

With your IP on the allowlist, add --proxy-server=http://gate.proxyfield.io:<port> to ChromeOptions before you create the driver, where <port> is the port you set up in the dashboard, then open https://api.ipify.org to see the exit IP. For a username and password, use port 7000 and answer the login with the auth extension or the network auth handler.

How do I use a proxy in Selenium with Python?

Create webdriver.ChromeOptions(), call options.add_argument("--proxy-server=http://gate.proxyfield.io:7000") and pass the options to webdriver.Chrome(). For a username and password, register them with driver.network.add_auth_handler() after the driver starts.

How do I use a proxy in Selenium Java?

Allowlist your IP and add --proxy-server=http://gate.proxyfield.io:<port> with ChromeOptions.addArguments(), or set an org.openqa.selenium.Proxy object with options.setProxy(); <port> is the port you set up in the dashboard. For credentials in Java, load the auth extension from section 3, which connects to gate.proxyfield.io:7000.

How do I use a proxy with SeleniumBase?

SeleniumBase takes the proxy as --proxy=<login>:<password>@gate.proxyfield.io:7000 on the command line, or as proxy="<login>:<password>@gate.proxyfield.io:7000" in SB or Driver. It handles the proxy login itself, so you need no extension.

Does selenium-wire still work?

It can still install and run, but it has had no release since 5.1.0 (October 15, 2022), and its GitHub repository is archived. Prefer the allowlist, the extension or the network auth handler.

What is selenium-wire?

selenium-wire is a Python package that runs a local man-in-the-middle proxy, so Selenium can use authenticated upstream proxies and inspect requests. The browser has to trust its own CA certificate for HTTPS.

Which proxy type works best for Selenium?

Residential proxies suit most public-data jobs in Selenium, and mobile 5G/4G proxies suit targets that treat carrier IPs differently. For sites that accept datacenter IPs, rotating datacenter proxies cost $0.29/GB down to $0.22/GB.

Show 11 more questionsShow fewer questions

Does Selenium support SOCKS5 proxies?

Yes. Chrome takes a socks5:// address in --proxy-server but sends no SOCKS5 username or password, so allowlist your IP and use socks5://gate.proxyfield.io:<port> with the port you set up in the dashboard; Firefox takes SOCKS5 through preferences, with remote DNS. See SOCKS5 proxies.

Which browser works best with Selenium and proxies?

Chrome for Testing or Chromium if you use the extension method, because branded Chrome 137 and later ignores --load-extension. Firefox takes SOCKS5 and remote DNS through preferences, and both speak WebDriver BiDi, which Selenium's network auth handler uses.

How do I set a proxy for Edge in Selenium?

Edge is built on Chromium, so webdriver.EdgeOptions() takes the same --proxy-server argument. The same three auth methods apply: the allowlist, with http://gate.proxyfield.io:<port> and the port you set up in the dashboard, or an extension or the network auth handler, with http://gate.proxyfield.io:7000.

Can I run several Selenium sessions at once through proxies?

Yes. ProxyField allows unlimited concurrent threads, so each driver can run at the same time through the same gateway. Give each driver its own country or session in the username to keep their IPs apart.

Do I need proxies for Selenium web scraping?

Not for a few pages, but at volume a single IP hits rate limits and regional differences. A rotating gateway spreads the requests over many IPs and lets you choose the country, region or city.

Why use proxies with Selenium?

To spread requests over many IPs, which cuts IP rate-limit blocks, and to load pages as a visitor from a chosen country or city sees them. A proxy changes the IP, its location and its reputation, not the browser itself.

Will a proxy get Selenium past Cloudflare, CAPTCHAs or DataDome?

Not on its own. A proxy changes the IP, its location and its reputation, and spreading requests cuts IP rate-limit blocks; it does not solve CAPTCHAs or hide a headless browser's fingerprint or TLS signature, which these systems also check.

What is selenium-stealth?

selenium-stealth is a Python package that changes some of the signals Chrome exposes under Selenium, such as navigator.webdriver. It uses the same ChromeOptions, so the proxy setup does not change, and it hides only some of the signals sites check.

Can I use free proxies with Selenium?

Free proxy lists are public IPs shared by anyone, often slow or already blocked, and they rarely support authentication. ProxyField does not offer free proxies; the smallest purchase is 1 GB for $2.95.

What proxy format does Selenium use?

--proxy-server=scheme://host:port, for example http://gate.proxyfield.io:7000, with no credentials in the string. Credentials inside that URL make Chrome fail with ERR_NO_SUPPORTED_PROXIES.

How do I check if my Selenium proxy is working?

Open https://api.ipify.org in the driver and compare the IP with your own; https://ipinfo.io/json shows its country. You can also test your proxy in the ProxyField checker before you run Selenium.

Easy Trial: 1 GB for $2.95.

Try for the price of 1 GB, no subscription, traffic never expires.