Integration · Selenium
Use RoProxy with Selenium
Selenium is the awkward one: Chrome's --proxy-server flag takes a host and a port but no username or password, and RoProxy sessions always authenticate with both. The dependable fix is a small local forwarder: Chrome talks to it without a password, and it passes every connection on to your session with the credentials. This guide sets one up with gost, runs Selenium through it in Python, headless or not, and covers the session type that suits browser tests and the errors you will meet.
Why Chrome needs a forwarder
Chrome reads its proxy from --proxy-server, which has no place for a username or a password. When the proxy answers with 407, Chrome shows a login prompt, and a headless run just waits until it times out.
The WebDriver BiDi auth handler of Selenium 4 does not help with this yet. Tested with Chrome 154 and Selenium 4.49, the handler sees the proxy's challenge, but the credentials never reach the proxy and the page load times out. selenium-wire, the old workaround, is no longer maintained.
1. Start a local forwarder
gost (go-gost/gost v3) listens on your machine without a password and forwards each connection to the session with its credentials. Leave it running while the browser runs.
# Listens on 127.0.0.1:8080 without a password and forwards to the RoProxy session.
gost -L http://127.0.0.1:8080 -F "http://USERNAME:PASSWORD@GATEWAY_HOST:HTTP_PORT"2. Point Selenium at the forwarder
Chrome now sees a proxy without a password, so there is no challenge to answer. Uncomment the headless line to run without a window, in CI for example.
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("--proxy-server=http://127.0.0.1:8080") # the local forwarder
# options.add_argument("--headless=new") # no window
driver = webdriver.Chrome(options=options)
driver.get("https://api.ipify.org?format=json")
print(driver.find_element("tag name", "body").text)
driver.quit()Choosing the session type for tests
Sticky (bind)
One IP for the whole test: logins, carts and anything that checks the IP against the session cookie.
Timed rotation
A new IP between test runs without touching the code; set an interval longer than one run.
Several sessions
Run one forwarder per session on its own local port (8080, 8081…) and give each worker its own port, instead of rotating one IP faster.
Common errors
A proxy login prompt, or a headless run that hangs
Chrome is talking to the gateway directly and waits for credentials. Point --proxy-server at the local forwarder instead.
ERR_PROXY_CONNECTION_FAILED
Nothing listens on 127.0.0.1:8080: start gost first and keep it running.
ERR_TUNNEL_CONNECTION_FAILED
gost reached the gateway but the session refused it: check the gateway host, port, username and password, and that the session has not expired.
Frequently asked questions
Why does Chrome ask for a proxy password?
--proxy-server carries no credentials, so Chrome prompts for them when the proxy answers 407. With a local forwarder in between, Chrome never sees that challenge.
Can I use the WebDriver BiDi auth handler instead?
Not for proxies yet. Tested with Chrome 154 and Selenium 4.49, it sees the proxy's challenge but the credentials never reach the proxy. The forwarder works today.
Can I use the SOCKS5 port with Selenium?
Chrome ignores SOCKS5 usernames and passwords. Keep Chrome on the forwarder and the forwarder on the session's HTTP port; HTTPS sites work through it.
Does this work in headless mode?
Yes. Add --headless=new to the Chrome options; the forwarder does not need a window either.
How do I run tests from different IPs?
Give each worker its own session through its own forwarder port, and rotate a session through the API between runs if a site starts blocking.