selenium-proxy-auth 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- selenium_proxy_auth/__init__.py +4 -0
- selenium_proxy_auth/extension.py +80 -0
- selenium_proxy_auth-0.1.0.dist-info/METADATA +85 -0
- selenium_proxy_auth-0.1.0.dist-info/RECORD +7 -0
- selenium_proxy_auth-0.1.0.dist-info/WHEEL +5 -0
- selenium_proxy_auth-0.1.0.dist-info/licenses/LICENSE +21 -0
- selenium_proxy_auth-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"""Generate a Chrome extension that configures an authenticated proxy for Selenium.
|
|
2
|
+
|
|
3
|
+
Selenium can't pass proxy credentials to Chrome directly — ``--proxy-server`` has
|
|
4
|
+
no place for a username/password, so an authenticated proxy pops a native auth
|
|
5
|
+
dialog that Selenium can't dismiss. The standard fix is a tiny extension that sets
|
|
6
|
+
``chrome.proxy`` and answers ``onAuthRequired`` with your credentials. This builds
|
|
7
|
+
that extension on the fly, no selenium-wire dependency.
|
|
8
|
+
"""
|
|
9
|
+
import os
|
|
10
|
+
import tempfile
|
|
11
|
+
from urllib.parse import unquote, urlparse
|
|
12
|
+
|
|
13
|
+
__all__ = ["make_proxy_extension", "add_proxy"]
|
|
14
|
+
|
|
15
|
+
_MANIFEST = """{
|
|
16
|
+
"name": "Selenium Proxy Auth",
|
|
17
|
+
"version": "1.0.0",
|
|
18
|
+
"manifest_version": 3,
|
|
19
|
+
"permissions": ["proxy", "webRequest", "webRequestAuthProvider"],
|
|
20
|
+
"host_permissions": ["<all_urls>"],
|
|
21
|
+
"background": { "service_worker": "background.js" },
|
|
22
|
+
"minimum_chrome_version": "108"
|
|
23
|
+
}"""
|
|
24
|
+
|
|
25
|
+
_BACKGROUND = """var config = {
|
|
26
|
+
mode: "fixed_servers",
|
|
27
|
+
rules: {
|
|
28
|
+
singleProxy: { scheme: "%(scheme)s", host: "%(host)s", port: %(port)d },
|
|
29
|
+
bypassList: ["localhost", "127.0.0.1"]
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
chrome.proxy.settings.set({ value: config, scope: "regular" }, function () {});
|
|
33
|
+
chrome.webRequest.onAuthRequired.addListener(
|
|
34
|
+
function () {
|
|
35
|
+
return { authCredentials: { username: "%(user)s", password: "%(password)s" } };
|
|
36
|
+
},
|
|
37
|
+
{ urls: ["<all_urls>"] },
|
|
38
|
+
["blocking"]
|
|
39
|
+
);
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def make_proxy_extension(proxy_url, directory=None):
|
|
44
|
+
"""Write an unpacked Chrome extension for ``proxy_url`` and return its path.
|
|
45
|
+
|
|
46
|
+
``proxy_url`` is an ordinary ``scheme://user:pass@host:port`` URL.
|
|
47
|
+
Caller is responsible for deleting the directory when done.
|
|
48
|
+
"""
|
|
49
|
+
p = urlparse(proxy_url)
|
|
50
|
+
if not p.hostname or not p.port:
|
|
51
|
+
raise ValueError(f"Proxy URL needs host and port: {proxy_url!r}")
|
|
52
|
+
fields = {
|
|
53
|
+
"scheme": (p.scheme or "http").replace("https", "http"),
|
|
54
|
+
"host": p.hostname,
|
|
55
|
+
"port": int(p.port),
|
|
56
|
+
"user": unquote(p.username or ""),
|
|
57
|
+
"password": unquote(p.password or ""),
|
|
58
|
+
}
|
|
59
|
+
directory = directory or tempfile.mkdtemp(prefix="selenium_proxy_auth_")
|
|
60
|
+
with open(os.path.join(directory, "manifest.json"), "w") as f:
|
|
61
|
+
f.write(_MANIFEST)
|
|
62
|
+
with open(os.path.join(directory, "background.js"), "w") as f:
|
|
63
|
+
f.write(_BACKGROUND % fields)
|
|
64
|
+
return directory
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def add_proxy(chrome_options, proxy_url):
|
|
68
|
+
"""Build the extension for ``proxy_url`` and load it into ``chrome_options``.
|
|
69
|
+
|
|
70
|
+
Returns the extension directory so you can ``shutil.rmtree`` it afterwards.
|
|
71
|
+
|
|
72
|
+
opts = webdriver.ChromeOptions()
|
|
73
|
+
ext = add_proxy(opts, "http://USER:PASS@us.jibaoproxy.com:913")
|
|
74
|
+
driver = webdriver.Chrome(options=opts)
|
|
75
|
+
...
|
|
76
|
+
shutil.rmtree(ext, ignore_errors=True)
|
|
77
|
+
"""
|
|
78
|
+
directory = make_proxy_extension(proxy_url)
|
|
79
|
+
chrome_options.add_argument(f"--load-extension={directory}")
|
|
80
|
+
return directory
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: selenium-proxy-auth
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Authenticated proxies for Selenium + Chrome without selenium-wire. Generates a proxy-auth extension on the fly.
|
|
5
|
+
Author-email: JiBao Proxy <support@jibaoproxy.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://jibaoproxy.com
|
|
8
|
+
Project-URL: Source, https://github.com/jibaoproxyofficial-pixel/selenium-proxy-auth
|
|
9
|
+
Keywords: selenium,proxy,proxy-authentication,chrome,web-scraping,browser-automation,residential-proxy
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
14
|
+
Requires-Python: >=3.8
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
# selenium-proxy-auth
|
|
20
|
+
|
|
21
|
+
[](https://pypi.org/project/selenium-proxy-auth/)
|
|
22
|
+
[](https://pypi.org/project/selenium-proxy-auth/)
|
|
23
|
+
[](https://opensource.org/licenses/MIT)
|
|
24
|
+
|
|
25
|
+
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.
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install selenium-proxy-auth
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## The problem
|
|
32
|
+
|
|
33
|
+
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:
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
# ❌ no place for credentials; Chrome shows a popup Selenium can't dismiss
|
|
37
|
+
opts.add_argument("--proxy-server=http://user:pass@gw.example.com:913")
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
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.
|
|
41
|
+
|
|
42
|
+
## Usage
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
import shutil
|
|
46
|
+
from selenium import webdriver
|
|
47
|
+
from selenium_proxy_auth import add_proxy
|
|
48
|
+
|
|
49
|
+
opts = webdriver.ChromeOptions()
|
|
50
|
+
opts.add_argument("--headless=new")
|
|
51
|
+
|
|
52
|
+
ext = add_proxy(opts, "http://USERNAME:PASSWORD@us.jibaoproxy.com:913")
|
|
53
|
+
|
|
54
|
+
driver = webdriver.Chrome(options=opts)
|
|
55
|
+
try:
|
|
56
|
+
driver.get("https://httpbin.org/ip")
|
|
57
|
+
print(driver.find_element("tag name", "body").text)
|
|
58
|
+
finally:
|
|
59
|
+
driver.quit()
|
|
60
|
+
shutil.rmtree(ext, ignore_errors=True) # clean up the generated extension
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
`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.
|
|
64
|
+
|
|
65
|
+
## How it works
|
|
66
|
+
|
|
67
|
+
- Manifest V3 extension with the `proxy`, `webRequest`, and `webRequestAuthProvider` permissions.
|
|
68
|
+
- A background service worker sets `chrome.proxy.settings` to your `host:port` and returns `authCredentials` from `onAuthRequired`.
|
|
69
|
+
- Loaded via `--load-extension`, so it works in headless `--headless=new`. (Old `--headless` does not load extensions; use `--headless=new`.)
|
|
70
|
+
|
|
71
|
+
Need just the files (e.g. for undetected-chromedriver)? Use `make_proxy_extension(url)` to get the directory and load it yourself.
|
|
72
|
+
|
|
73
|
+
## Rotating IPs
|
|
74
|
+
|
|
75
|
+
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](https://jibaoproxy.com/blog/ja3-tls-fingerprint-detection-explained.html) before the page loads. We build [JiBao Proxy](https://jibaoproxy.com) for clean residential exits — 72M+ IPs, 200+ countries, sticky sessions. Works with any provider, though.
|
|
76
|
+
|
|
77
|
+
## Related
|
|
78
|
+
|
|
79
|
+
- [Selenium & Playwright proxy authentication, explained](https://jibaoproxy.com/blog/selenium-playwright-proxy-authentication.html)
|
|
80
|
+
- [AdsPower / Multilogin proxy setup](https://jibaoproxy.com/blog/adspower-multilogin-proxy-setup.html)
|
|
81
|
+
- [Bypassing DataDome & PerimeterX in 2026](https://jibaoproxy.com/blog/datadome-perimeterx-bypass-2026.html)
|
|
82
|
+
|
|
83
|
+
## License
|
|
84
|
+
|
|
85
|
+
MIT
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
selenium_proxy_auth/__init__.py,sha256=f7fXtKh63GPovP6raB-fjW691djKo3GJgMPkMrNhFgA,126
|
|
2
|
+
selenium_proxy_auth/extension.py,sha256=5gvvYLHmVednAlWv80Ys3aY92DyAZujppztIZxc-k78,2886
|
|
3
|
+
selenium_proxy_auth-0.1.0.dist-info/licenses/LICENSE,sha256=EqlXESyqjpkAYUf6imqo1JrW9eYaOurSRNBh4LO7bQE,1068
|
|
4
|
+
selenium_proxy_auth-0.1.0.dist-info/METADATA,sha256=u0zaKnwQwB8Fn66Qqp2-eVG8PmMNktK_hIhRWIJ1gXk,4191
|
|
5
|
+
selenium_proxy_auth-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
6
|
+
selenium_proxy_auth-0.1.0.dist-info/top_level.txt,sha256=gWP2fy3dSabuxy-vB17N54UhLRCY2omXmOPNWFzKzlg,20
|
|
7
|
+
selenium_proxy_auth-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 JiBao Proxy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
selenium_proxy_auth
|