Skip to content

Selenium Change Proxy Per Session or Per Tab: What Works

What Selenium can switch, what it cannot, and a pattern for giving every session its own proxy.

What Selenium can switch

In Selenium's documentation the proxy is set on the options object (options.proxy, or a Chrome argument) before webdriver.Chrome() is called, and every example works that way. There is no command in that setup to change it for a single tab or to swap it in a running browser. In practice "change the proxy" means "start the next session with another proxy".

Chrome itself has an experimental DevTools call, Target.createBrowserContext, that accepts a proxyServer for a new empty context. It is not part of Selenium's API, we did not test driving such a context with Selenium window commands, and we do not recommend building on it. Playwright and Puppeteer expose per-context proxies as normal options.

Ways to get a different proxy

Ways to get a different proxy
ItemHow it worksGood forWatch out for
New driver per proxyQuit the browser, start the next with another proxySequential jobs, one IP per jobStart-up time per session; use a clean profile each time
Parallel driversSeveral browsers at once, each with its own proxy and local portWorkers that must run side by sideMemory per browser; one forwarder per proxy if the login is SOCKS5
Rotating gatewayOne proxy address; a new connection gets a new IPMany one-off requests without restartingNot a switch per tab: Chrome reuses open connections, see below
Per-context proxyPlaywright or Puppeteer, proxy on the contextMany isolated sessions in one browserA different tool; the Selenium page stays for existing tests

Source: Selenium documentation (driver options), Chrome DevTools Protocol and Playwright documentation, read on 13 November 2026; gateway behaviour from the Proxy302 product facts file.

A clean session per proxy (Python)

# pip install -U selenium    and install gost (see gost.run)
import socket, subprocess, tempfile, time
from selenium import webdriver
from selenium.webdriver.common.by import By

PROXIES = [  # one entry per IP, copied from My assets (SOCKS5 endpoints)
    ("HOST", "PORT", "LOGIN_1", "PASSWORD_1"),
    ("HOST", "PORT", "LOGIN_2", "PASSWORD_2"),
]

def start_forwarder(local_port, host, port, login, password):
    proc = subprocess.Popen(["gost", "-L", f"socks5://127.0.0.1:{local_port}",
                             "-F", f"socks5://{login}:{password}@{host}:{port}"])
    for _ in range(50):
        try:
            socket.create_connection(("127.0.0.1", local_port), timeout=0.2).close()
            return proc
        except OSError:
            time.sleep(0.2)
    proc.terminate()
    raise RuntimeError("forwarder did not start")

def run_session(local_port, entry):
    forwarder = start_forwarder(local_port, *entry)
    options = webdriver.ChromeOptions()
    options.add_argument(f"--proxy-server=socks5://127.0.0.1:{local_port}")
    options.add_argument(f"--user-data-dir={tempfile.mkdtemp()}")   # a clean profile per session
    driver = webdriver.Chrome(options=options)                       # the proxy is fixed from here on
    try:
        driver.get("https://ipinfo.io/json")
        print(entry[2], driver.find_element(By.TAG_NAME, "body").text)
    finally:
        driver.quit()
        forwarder.terminate()

for i, entry in enumerate(PROXIES):
    run_session(1080 + i, entry)   # next proxy = next browser session

Example only: replace HOST, PORT, LOGIN and PASSWORD with the values from My assets. Chrome cannot send a SOCKS5 login itself, so the example puts a local forwarder in front of each proxy.

Setting the proxy with Selenium's Proxy class

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

proxy = Proxy()
proxy.proxy_type = ProxyType.MANUAL
proxy.socks_proxy = "127.0.0.1:1080"   # the local forwarder, no login in the address
proxy.socks_version = 5

options = webdriver.ChromeOptions()
options.proxy = proxy                  # set before the browser starts
driver = webdriver.Chrome(options=options)

Example only: the proxy is part of the options, so it applies to the whole session that starts from them.

A new IP without a new browser

With Proxy302 rotating residential or datacenter proxies and no session set, each new connection gets a new IP, not each request: a connection that stays open (keep-alive) keeps its IP. Chrome reuses open connections, so consecutive page loads in one browser may show the same IP for a while.

If a job needs a guaranteed new IP, start a new browser session. If it needs the same IP for a long time, use a static IP or open a session of the length you need.

Choosing in 4 steps

  1. Step 1

    Decide what must stay constant: one IP per job, one per account, or a new one per request.

  2. Step 2

    One IP per job or per account: use a static IP and one browser session per IP. A fresh profile per session keeps cookies apart.

  3. Step 3

    New IP per request and no need for a fixed address: use a rotating proxy and expect connection reuse inside one browser.

  4. Step 4

    Many isolated sessions at once: move that part of the work to a tool with per-context proxies.

Common problems

The second session still shows the first IP

Check The old browser or its forwarder is still running, or both sessions use one profile.

Fix Call driver.quit() and terminate the forwarder in a finally block, and give each session its own --user-data-dir.

IP does not change between page loads on a rotating proxy

Check Chrome kept an open connection, which keeps its IP.

Fix Start a new session when you need a new IP, or use a static IP per session.

Every session shows your own IP

Check The proxy flag or Proxy object was not passed to the options that created the driver.

Fix Check the options object given to webdriver.Chrome, and test the proxy with curl first.

Stop when If curl through the proxy also fails, the problem is the address or login, not Selenium.

Proxy with a SOCKS5 login fails in Chrome

Check Chromium cannot send a SOCKS5 login.

Fix Put a local forwarder in front, as in the example, or use the HTTP endpoint.

How to do it with Proxy302

For one fixed address per session, a static ISP IP costs US$0.50 for 1 day or US$7.99 for 30 days (about US$0.27 a day), does not rotate during the lease, and up to 100 can be bought in one order. For a pool of changing IPs, rotating residential on the Budget line costs US$1.50 per GB.

Because Chrome cannot send a SOCKS5 login, give Selenium either the HTTP endpoint (port 2222) or a local forwarder in front of the SOCKS5 endpoint (port 3333). No free trial; the smallest purchase is 1 GB of residential traffic or one IP for one day.

Steps in Proxy302

  1. Step 1

    Open the static ISP page (or rotating residential), choose the country and protocol, review the cost and pay from the wallet.

  2. Step 2

    Open My assets and copy host, port, username and password for each IP you need.

  3. Step 3

    Put one entry per session into the PROXIES list in the example.

  4. Step 4

    Run it and confirm that each session prints a different exit on https://ipinfo.io/json.

Selenium proxy switching FAQ

Can I change the proxy in a running Selenium browser?

Not through Selenium's documented options: the proxy is set when the driver starts. Quit the driver and start a new one with the new proxy.

Can each Selenium tab use a different proxy?

Not with a normal Selenium setup. Tabs share the browser's proxy. Use one browser per proxy, or a tool with per-context proxies.

How do I use several proxies in Selenium at the same time?

Start several drivers, each with its own proxy flag and its own --user-data-dir, for example in separate threads or processes.

Does a rotating proxy change IP on every page load?

Not necessarily. A new connection gets a new IP, but Chrome reuses open connections. Start a new session when you need a new IP for certain.

Is restarting the browser the only way?

For Selenium, yes. If restarting is too slow, use Playwright or Puppeteer, where a context can have its own proxy.

Reference links

5
  1. Selenium documentation: driver options, proxy

    Official documentation · Confirmed on:

    Read on 13 November 2026: the Python example builds ChromeOptions, sets options.proxy = Proxy({"proxyType": ProxyType.MANUAL, "httpProxy": "http.proxy:1234"}) and only then starts webdriver.Chrome(options=options); the examples contain no user:pass.

    The visible part of the page does not state in so many words that the proxy cannot be changed after the session starts; this guide relies on the examples, where the proxy is always part of the options passed at start.

  2. Chrome DevTools Protocol: Target.createBrowserContext

    Official documentation · Confirmed on:

    Read on 13 November 2026 in the protocol JSON: createBrowserContext creates a new empty browser context, similar to an incognito profile; its parameters proxyServer ("similar to the one passed to --proxy-server") and proxyBypassList are marked experimental.

    Not tested with Selenium window commands.

  3. Chromium source: socks5_client_socket.cc

    Official documentation · Confirmed on:

    Read on 13 November 2026: the SOCKS5 greeting Chromium sends is 05 01 00 (one method, "no authentication"), so a login cannot be passed to a SOCKS5 proxy from Chrome.

  4. Playwright: Network, HTTP proxy

    Official documentation · Confirmed on:

    Read on 13 November 2026: proxy can be set globally for the browser or for each browser context individually.

  5. Proxy302 product facts and price list

    Product observation · Confirmed on:

    Product facts file, checked on 13 November 2026 against the console, backend and price list: static ISP lease prices per IP (US$, 1 PTC = US$1), rotating residential Budget line price per GB, HTTP port 2222 and SOCKS5 port 3333 on proxy.proxy302.com, which protocols work for which product, no free trial.

Ready to try it?

Create an account, top up once, then pick rotating residential, static ISP or datacenter IPs and have one running in your browser within minutes.