Code and command line
Selenium proxy setup
Selenium is the oldest browser automation tool still in wide use, and its proxy story has one sharp edge. Chrome accepts a proxy address through --proxy-server, but there is no flag for a username and password, and WebDriver cannot type into the browser login prompt. Without an extra piece, an authenticated proxy simply fails.
There are two practical answers. The first is a tiny browser extension that hands the login to Chrome when the proxy asks for it. The second is Selenium Wire, a library that runs a local proxy and adds the login for you. This guide shows both in Python and explains when to pick which.
What do you need before adding a proxy in Selenium?
Tick these off before the first step. Your login and password appear in your account once the first top-up of $40 or more has been credited.
| Requirement | Detail |
|---|---|
| Selenium 4 | pip install selenium. Selenium Manager fetches a matching driver. |
| A Chromium build that loads extensions from the command line | Recent branded Google Chrome releases ignore --load-extension. Chrome for Testing and Chromium still accept it. |
| TopProxy login and password | For example tp7k2m9_country-us. |
| Optional: Selenium Wire | Only for the second route. It is no longer actively maintained, so pin the versions that work for you. |
Where do the proxy host, port and login go in Selenium?
Work through the steps in order. Swap YOUR_PASSWORD for your proxy password and tp7k2m9 for your account name.
Understand why a flag alone fails
Run Chrome with only
--proxy-serverand the gateway answers the first request with a login challenge. Chrome would show a sign-in dialog to a human, but WebDriver cannot reach that dialog, so the page never loads. Something has to answer the challenge automatically.Route A: build a small auth extension
A Manifest V3 extension can set the proxy and reply to the challenge with
webRequest.onAuthRequired. It needs thewebRequestAuthProviderpermission for that listener. Write the two files below into a folder; the Python step fills in the login.{ "manifest_version": 3, "name": "TopProxy auth", "version": "1.0", "permissions": ["proxy", "webRequest", "webRequestAuthProvider"], "host_permissions": ["<all_urls>"], "background": { "service_worker": "background.js" } }Load the extension from Python
Generate the folder at runtime so each driver can get its own login, then point Chrome at it. The function below writes the files into a temporary directory and starts the browser.
import json, os, tempfile from selenium import webdriver # the background.js file from the previous step, kept next to this script with open("background.js") as f: BACKGROUND_JS = f.read() def proxied_chrome(login, password): folder = tempfile.mkdtemp(prefix="tp-auth-") manifest = { "manifest_version": 3, "name": "TopProxy auth", "version": "1.0", "permissions": ["proxy", "webRequest", "webRequestAuthProvider"], "host_permissions": ["<all_urls>"], "background": {"service_worker": "background.js"}, } with open(os.path.join(folder, "manifest.json"), "w") as f: json.dump(manifest, f) with open(os.path.join(folder, "background.js"), "w") as f: f.write(BACKGROUND_JS.replace("LOGIN_HERE", login).replace("PASSWORD_HERE", password)) opts = webdriver.ChromeOptions() opts.add_argument(f"--load-extension={folder}") return webdriver.Chrome(options=opts) driver = proxied_chrome("tp7k2m9_country-us", os.environ["TOPPROXY_PASSWORD"]) driver.get("https://ipinfo.io/json") print(driver.find_element("tag name", "body").text) driver.quit()Tip.The script swaps LOGIN_HERE and PASSWORD_HERE for real values in a fresh folder, so the file on disk never holds your password. Run it with Chrome for Testing or Chromium, since branded Chrome now skips command-line extensions.
Route B: let Selenium Wire add the login
Selenium Wire starts a local proxy inside your Python process, sends the browser through it, and forwards upstream with your credentials. Setup is short, but it intercepts TLS with its own certificate and the project is archived, so treat it as a convenience for quick jobs.
from seleniumwire import webdriver upstream = "http://tp7k2m9_country-us:YOUR_PASSWORD@proxy.topproxy.shop:8080" driver = webdriver.Chrome(seleniumwire_options={ "proxy": {"http": upstream, "https": upstream, "no_proxy": "localhost,127.0.0.1"}, }) driver.get("https://ipinfo.io/json") print(driver.find_element("tag name", "body").text) driver.quit()Firefox: preferences plus a saved login
Firefox reads the proxy from preferences, which Selenium can set. It still prompts for the login, so the same idea applies: either an extension that answers
onAuthRequired, or Selenium Wire. The preferences below send all traffic to the gateway.opts = webdriver.FirefoxOptions() opts.set_preference("network.proxy.type", 1) opts.set_preference("network.proxy.http", "proxy.topproxy.shop") opts.set_preference("network.proxy.http_port", 8080) opts.set_preference("network.proxy.ssl", "proxy.topproxy.shop") opts.set_preference("network.proxy.ssl_port", 8080) driver = webdriver.Firefox(options=opts)
How can you confirm the proxy is active in Selenium?
Open ipinfo.io and read the body text. If the page loads and shows an address that is not yours, the challenge was answered. A blank page or an endless load means nothing replied to the login request.
driver.get("https://ipinfo.io/json")
info = json.loads(driver.find_element("tag name", "body").text)
print(info["ip"], info["country"])The response shown here is shortened to the fields that matter. The region and time zone follow the exit, in this case Italy.
{
"ip": "198.51.100.47",
"city": "Milan",
"region": "Lombardy",
"country": "IT",
"timezone": "Europe/Rome"
}198.51.100.47 is an address reserved for documentation. A live check prints a real exit.
How do you switch between rotating and held IPs in Selenium?
The login is fixed when the driver starts, so a new address means a new driver with a new login. For flows that log in and click through several pages, use a sticky login so the site sees one address for the whole flow.
driver = proxied_chrome("tp7k2m9_country-us", password)How the login is put together
Every setting lives in the login, joined with underscores. Nothing else in Selenium changes when you switch location or session.
| Part | Meaning | Rule |
|---|---|---|
| tp7k2m9 | Your account name | Always first. Yours is shown in your account and replaces tp7k2m9 in every example here. |
| _country-us | Exit country | Two-letter code in lowercase. 64 countries to choose from. |
| _city-new-york | Exit city, optional | Lowercase, spaces become hyphens. 172 cities in total. |
| _session-a1b2c3 | Session name, optional | Letters and digits you pick. Same name, same exit. New name, new exit. |
| _life-30 | Session life in minutes | Only with a session. Residential 1 to 120 minutes, mobile 1 to 60 minutes, long session ISP up to 12 hours (life 720). |
All parts togethertp7k2m9_country-us_city-new-york_session-a1b2c3_life-30
How do you choose an exit country or city in Selenium?
Choose the location in the login you pass to the driver factory. City values are lowercase with hyphens.
driver = proxied_chrome("tp7k2m9_country-it", password)Codes and city values for all 64 countries are listed on the proxy locations pages.
How do you fix proxy connection errors in Selenium?
Find the line that matches what you see. Most problems come down to the login, the port or the network you are on.
| Symptom | Likely cause | Fix |
|---|---|---|
| Page stays blank, then times out | Nothing answered the proxy login challenge. | Load the auth extension or use Selenium Wire. A flag alone cannot carry the password. |
| Extension never loads | Branded Chrome ignores --load-extension in recent versions. | Use Chrome for Testing or Chromium as the browser binary. |
ERR_CERT_AUTHORITY_INVALID with Selenium Wire | Selenium Wire signs pages with its own certificate. | Accept insecure certs in the options for that driver, or switch to the extension route. |
| Exit is correct but the site asks for verification | Datacenter exits or headless defaults look automated. | Use residential or mobile exits and run with a normal window size and locale. |
Still stuck? Run the same login through the cURL check. If cURL connects, the issue is in the Selenium settings. If it does not, write to support with the error text.
What kind of proxy pairs well with Selenium?
All products sit behind the same gateway and share one prepaid balance, so moving from one to another means buying the other product and changing the login, nothing more.
- Static Residential IPsOne fixed household address per driver for account work that runs for days.$2.34 per IP per month
- Rotating Residential ProxiesSticky sessions up to 120 minutes for test flows across many countries.$0.23 per GB
- Dedicated ISP ProxiesFast fixed IPs for QA suites that must start from a known address.$0.33 per IP per month
Calling pages from code at scale? The TopProxy API docs cover the Scraping API, which renders pages and retries on its own.
What else do Selenium users ask about proxies?
Why can I not just write login:password@host in --proxy-server?
Chrome drops credentials from that switch. It only uses the scheme, host and port. The password has to be supplied in answer to the proxy challenge, which is what the extension or Selenium Wire does.
Is Selenium Wire safe to use?
It works, but it is archived and no longer updated, and it decrypts your traffic locally with its own certificate. That is fine for testing on your own machine. For long-term projects the extension route has fewer moving parts.
Does the extension work in headless mode?
Chrome in its current headless mode loads extensions the same way as a normal window. The legacy headless mode did not, so avoid the old headless switch.
Can Selenium use the SOCKS5 port?
Only without a password, which TopProxy does not offer for this gateway. Use the HTTP port 8080, which tunnels https pages with CONNECT.
What about Selenium in Java or C#?
The extension route is language independent: create the same two files and load the folder with ChromeOptions in your language. The login format and gateway do not change.
Related setup guides
- PlaywrightProxy server, username and password at launch or per context, in Node.js and Python, with one location per context.
- PuppeteerThe --proxy-server switch plus page.authenticate, one browser per location, and a clean way to switch sessions.
- Google ChromeA separate Chrome profile launched with --proxy-server, the sign-in prompt, and when to use system settings instead.
- Python RequestsA proxies dictionary, a Session with retries, SOCKS5 through PySocks and a pool of sticky logins.
Ready to connect Selenium?
Open an account, add $40 or more in crypto, and your login and password are waiting in the account area.