Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

selenium-proxy-auth

PyPI version Python versions License: MIT

Use an authenticated (user:pass) proxy with Selenium + Chrome — without selenium-wire. It generates a tiny proxy-auth extension on the fly and loads it, so Chrome never shows the native auth popup that Selenium can't click.

pip install selenium-proxy-auth

The problem

Chrome's --proxy-server flag has nowhere to put a username and password. So with an authenticated proxy, Chrome throws a native auth dialog — which Selenium can't interact with — and every request hangs or 407s:

# ❌ no place for credentials; Chrome shows a popup Selenium can't dismiss
opts.add_argument("--proxy-server=http://user:pass@gw.example.com:913")

The reliable fix is a small extension that sets chrome.proxy and answers onAuthRequired with your credentials. This package builds and loads it for you.

Usage

import shutil
from selenium import webdriver
from selenium_proxy_auth import add_proxy

opts = webdriver.ChromeOptions()
opts.add_argument("--headless=new")

ext = add_proxy(opts, "http://USERNAME:PASSWORD@us.jibaoproxy.com:913")

driver = webdriver.Chrome(options=opts)
try:
    driver.get("https://httpbin.org/ip")
    print(driver.find_element("tag name", "body").text)
finally:
    driver.quit()
    shutil.rmtree(ext, ignore_errors=True)   # clean up the generated extension

add_proxy returns the path to the generated extension directory so you can delete it afterwards. The extension contains your credentials in plaintext — it's written to a temp dir; don't commit it.

How it works

  • Manifest V3 extension with the proxy, webRequest, and webRequestAuthProvider permissions.
  • A background service worker sets chrome.proxy.settings to your host:port and returns authCredentials from onAuthRequired.
  • Loaded via --load-extension, so it works in headless --headless=new. (Old --headless does not load extensions; use --headless=new.)

Need just the files (e.g. for undetected-chromedriver)? Use make_proxy_extension(url) to get the directory and load it yourself.

Rotating IPs

A rotating residential gateway hands out a new exit IP per connection from one URL — point add_proxy at the gateway and each fresh webdriver.Chrome gets a different IP. If you're still getting blocked after authenticating, the exit IP is the issue: datacenter ranges get scored as bots by ASN and TLS fingerprint before the page loads. We build JiBao Proxy for clean residential exits — 72M+ IPs, 200+ countries, sticky sessions. Works with any provider, though.

Related

License

MIT

About

Authenticated proxies for Selenium + Chrome without selenium-wire. Generates a proxy-auth extension on the fly and answers onAuthRequired.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages