selenium-netwire 0.1.0__tar.gz

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.
@@ -0,0 +1,36 @@
1
+ name: release
2
+
3
+ on:
4
+ push:
5
+ tags: ["v*"]
6
+
7
+ jobs:
8
+ build:
9
+ runs-on: ubuntu-latest
10
+ permissions:
11
+ contents: read
12
+ steps:
13
+ - uses: actions/checkout@v4
14
+ - uses: astral-sh/setup-uv@v6
15
+ - name: Check the tag matches the package version
16
+ run: |
17
+ version=$(uv run --no-project python -c "import tomllib;print(tomllib.load(open('pyproject.toml','rb'))['project']['version'])")
18
+ test "v$version" = "$GITHUB_REF_NAME" || { echo "tag $GITHUB_REF_NAME does not match version $version"; exit 1; }
19
+ - run: uv build
20
+ - uses: actions/upload-artifact@v4
21
+ with:
22
+ name: dist
23
+ path: dist/
24
+
25
+ publish:
26
+ needs: build
27
+ runs-on: ubuntu-latest
28
+ environment: pypi
29
+ permissions:
30
+ id-token: write # trusted publishing: PyPI trusts this workflow, no token stored
31
+ steps:
32
+ - uses: actions/download-artifact@v4
33
+ with:
34
+ name: dist
35
+ path: dist/
36
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,40 @@
1
+ name: test
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ schedule:
8
+ - cron: "17 6 * * 1" # weekly, to catch new Chrome releases
9
+ workflow_dispatch:
10
+
11
+ permissions:
12
+ contents: read
13
+
14
+ jobs:
15
+ test:
16
+ runs-on: ubuntu-latest
17
+ strategy:
18
+ fail-fast: false
19
+ matrix:
20
+ python: ["3.10", "3.12", "3.13"]
21
+ chrome: ["stable"]
22
+ include:
23
+ - python: "3.12"
24
+ chrome: "beta"
25
+ steps:
26
+ - uses: actions/checkout@v4
27
+ - uses: astral-sh/setup-uv@v6
28
+ with:
29
+ python-version: ${{ matrix.python }}
30
+ - id: chrome
31
+ uses: browser-actions/setup-chrome@v2
32
+ with:
33
+ chrome-version: ${{ matrix.chrome }}
34
+ install-chromedriver: true
35
+ - run: uv sync
36
+ - run: uv run pytest -v
37
+ env:
38
+ CHROME_BINARY: ${{ steps.chrome.outputs.chrome-path }}
39
+ # Ubuntu 24.04 runners block the user namespaces Chrome's sandbox needs.
40
+ NETWIRE_NO_SANDBOX: "1"
@@ -0,0 +1,5 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.egg-info/
4
+ dist/
5
+ .pytest_cache/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Tugay Abdullazade
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,194 @@
1
+ Metadata-Version: 2.5
2
+ Name: selenium-netwire
3
+ Version: 0.1.0
4
+ Summary: Capture and modify the browser's network traffic in Selenium. A maintained, drop-in successor to selenium-wire, built on the browser's DevTools protocol instead of a proxy.
5
+ Project-URL: Homepage, https://github.com/tugayabdulla/selenium-netwire
6
+ Project-URL: Issues, https://github.com/tugayabdulla/selenium-netwire/issues
7
+ Author: Tugay Abdullazade
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Keywords: cdp,devtools,intercept,network,proxy,scraping,selenium,selenium-wire
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Framework :: Pytest
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Topic :: Internet :: WWW/HTTP :: Browsers
16
+ Classifier: Topic :: Software Development :: Testing
17
+ Requires-Python: >=3.10
18
+ Requires-Dist: selenium>=4.20
19
+ Requires-Dist: websocket-client>=1.6
20
+ Description-Content-Type: text/markdown
21
+
22
+ # selenium-netwire
23
+
24
+ See and change the network traffic of a Selenium browser: requests, responses,
25
+ bodies, websocket messages, and proxies with a username and password.
26
+
27
+ It is a drop-in replacement for [selenium-wire](https://github.com/wkeeling/selenium-wire),
28
+ which was archived in January 2024. Same API, but built on the browser's
29
+ DevTools protocol instead of a man-in-the-middle proxy, so there are no
30
+ certificates to install and nothing sits between the browser and the site.
31
+
32
+ ```bash
33
+ pip install selenium-netwire
34
+ ```
35
+
36
+ ```python
37
+ from netwire import webdriver
38
+
39
+ driver = webdriver.Chrome()
40
+ driver.get("https://example.com")
41
+
42
+ for request in driver.requests:
43
+ if request.response:
44
+ print(request.method, request.url, request.response.status_code)
45
+ ```
46
+
47
+ ## Moving from selenium-wire
48
+
49
+ Change the import. Everything else stays the same, `seleniumwire_options`
50
+ included:
51
+
52
+ ```diff
53
+ - from seleniumwire import webdriver
54
+ + from netwire import webdriver
55
+ ```
56
+
57
+ Options that only configured selenium-wire's own proxy (`ca_cert`, `ca_key`,
58
+ `verify_ssl`, `port`, `addr`, `request_storage`, `disable_encoding` and so on)
59
+ are accepted and ignored.
60
+
61
+ ## Why not selenium-wire
62
+
63
+ selenium-wire sends all browser traffic through a proxy it runs inside your
64
+ Python process, and decrypts HTTPS with its own certificate. That is why it
65
+ needed certificates, broke when its dependencies moved on (`blinker._saferef`),
66
+ slowed pages down, and changed the browser's TLS fingerprint, which anti-bot
67
+ systems notice.
68
+
69
+ netwire asks the browser itself. Chrome reports every request over its
70
+ DevTools protocol and can pause, change or answer requests there. The traffic
71
+ goes from the browser to the site exactly as it would without netwire.
72
+
73
+ ## Why not Selenium's own network API
74
+
75
+ Selenium 4 has `driver.network` over WebDriver BiDi. Capturing works, but
76
+ changing requests does not mix with normal Selenium code yet: with a request
77
+ handler set, `driver.get()` hangs in Chrome, because ChromeDriver does not
78
+ process the "continue this request" command while `get()` is running
79
+ ([selenium#17373](https://github.com/SeleniumHQ/selenium/issues/17373),
80
+ [selenium#18116](https://github.com/SeleniumHQ/selenium/issues/18116)).
81
+ netwire talks to the browser's DevTools socket directly, next to
82
+ ChromeDriver, so `get()`, clicks and everything else keep working while
83
+ requests are being changed.
84
+
85
+ ## Capturing
86
+
87
+ ```python
88
+ driver.requests # every captured request, oldest first
89
+ driver.last_request
90
+ driver.iter_requests()
91
+ del driver.requests # clear
92
+
93
+ request = driver.wait_for_request("/api/products", timeout=10)
94
+ request.url, request.method, request.headers, request.body, request.params
95
+ request.response.status_code, request.response.headers, request.response.body
96
+ request.ws_messages # websocket frames, for websocket requests
97
+ request.cert # the server's TLS certificate details
98
+
99
+ driver.scopes = [".*example.com/api/.*"] # only capture these
100
+ driver.har # HAR 1.2 archive as JSON
101
+ ```
102
+
103
+ Response bodies are already decompressed. `netwire.utils.decode()` is there
104
+ for code written for selenium-wire and returns the body unchanged.
105
+
106
+ ## Changing requests and responses
107
+
108
+ ```python
109
+ def interceptor(request):
110
+ del request.headers["User-Agent"]
111
+ request.headers["User-Agent"] = "my-agent"
112
+ if request.path.endswith((".png", ".jpg")):
113
+ request.abort()
114
+ if request.url == "https://example.com/api/config":
115
+ request.create_response(200, {"Content-Type": "application/json"}, b'{"beta": true}')
116
+
117
+ driver.request_interceptor = interceptor
118
+
119
+
120
+ def response_interceptor(request, response):
121
+ if request.path == "/api/data":
122
+ response.body = b'{"value": 7}'
123
+
124
+ driver.response_interceptor = response_interceptor
125
+
126
+ del driver.request_interceptor # stop intercepting
127
+ ```
128
+
129
+ Headers behave like selenium-wire's: names are case-insensitive, setting a
130
+ header adds it, so delete it first to replace it, and a missing header reads
131
+ as `None`.
132
+
133
+ ## Proxies
134
+
135
+ ```python
136
+ driver = webdriver.Chrome(seleniumwire_options={
137
+ "proxy": {
138
+ "https": "http://user:pass@proxy.example.com:8080",
139
+ "no_proxy": "localhost,127.0.0.1",
140
+ }
141
+ })
142
+ ```
143
+
144
+ | Proxy | How |
145
+ | --- | --- |
146
+ | HTTP or HTTPS, with or without user:pass | Chrome connects to it; netwire answers its login |
147
+ | SOCKS5 without a login | Chrome connects to it |
148
+ | SOCKS5 with user:pass | through netwire's relay (below) |
149
+ | `custom_authorization`, e.g. a Bearer token | through the relay |
150
+ | `HTTP_PROXY`, `HTTPS_PROXY`, `NO_PROXY` | read when no `proxy` option is given |
151
+
152
+ Chrome cannot log in to SOCKS proxies or change its proxy after starting. For
153
+ those, netwire starts a small relay on 127.0.0.1: Chrome uses it as a plain
154
+ SOCKS5 proxy and the relay connects through the real one. It only forwards
155
+ bytes; it does not decrypt anything.
156
+
157
+ To switch proxies while the driver runs, start with the relay on:
158
+
159
+ ```python
160
+ driver = webdriver.Chrome(netwire_options={"relay": True})
161
+ driver.proxy = {"https": "socks5://user:pass@proxy-1.example.com:1080"}
162
+ driver.get(...)
163
+ driver.proxy = {"https": "http://user:pass@proxy-2.example.com:8080"}
164
+ driver.get(...)
165
+ del driver.proxy # back to a direct connection
166
+ ```
167
+
168
+ Through the relay, HTTP proxies are used with `CONNECT` for every site,
169
+ `http://` ones included, so the proxy has to allow `CONNECT` to port 80.
170
+
171
+ ## What works where
172
+
173
+ | | Status |
174
+ | --- | --- |
175
+ | Chrome, Edge | supported |
176
+ | Requests in iframes, new tabs and popups | captured |
177
+ | Firefox | not yet |
178
+ | Remote WebDriver and Selenium Grid | not yet |
179
+ | selenium-wire's undetected-chromedriver integration | not yet |
180
+
181
+ ## Development
182
+
183
+ ```bash
184
+ uv sync
185
+ uv run pytest
186
+ ```
187
+
188
+ The tests start a real Chrome against local test servers and proxies.
189
+ `CHROME_BINARY` picks the browser and `NETWIRE_NO_SANDBOX=1` adds
190
+ `--no-sandbox` for containers.
191
+
192
+ ## License
193
+
194
+ MIT
@@ -0,0 +1,173 @@
1
+ # selenium-netwire
2
+
3
+ See and change the network traffic of a Selenium browser: requests, responses,
4
+ bodies, websocket messages, and proxies with a username and password.
5
+
6
+ It is a drop-in replacement for [selenium-wire](https://github.com/wkeeling/selenium-wire),
7
+ which was archived in January 2024. Same API, but built on the browser's
8
+ DevTools protocol instead of a man-in-the-middle proxy, so there are no
9
+ certificates to install and nothing sits between the browser and the site.
10
+
11
+ ```bash
12
+ pip install selenium-netwire
13
+ ```
14
+
15
+ ```python
16
+ from netwire import webdriver
17
+
18
+ driver = webdriver.Chrome()
19
+ driver.get("https://example.com")
20
+
21
+ for request in driver.requests:
22
+ if request.response:
23
+ print(request.method, request.url, request.response.status_code)
24
+ ```
25
+
26
+ ## Moving from selenium-wire
27
+
28
+ Change the import. Everything else stays the same, `seleniumwire_options`
29
+ included:
30
+
31
+ ```diff
32
+ - from seleniumwire import webdriver
33
+ + from netwire import webdriver
34
+ ```
35
+
36
+ Options that only configured selenium-wire's own proxy (`ca_cert`, `ca_key`,
37
+ `verify_ssl`, `port`, `addr`, `request_storage`, `disable_encoding` and so on)
38
+ are accepted and ignored.
39
+
40
+ ## Why not selenium-wire
41
+
42
+ selenium-wire sends all browser traffic through a proxy it runs inside your
43
+ Python process, and decrypts HTTPS with its own certificate. That is why it
44
+ needed certificates, broke when its dependencies moved on (`blinker._saferef`),
45
+ slowed pages down, and changed the browser's TLS fingerprint, which anti-bot
46
+ systems notice.
47
+
48
+ netwire asks the browser itself. Chrome reports every request over its
49
+ DevTools protocol and can pause, change or answer requests there. The traffic
50
+ goes from the browser to the site exactly as it would without netwire.
51
+
52
+ ## Why not Selenium's own network API
53
+
54
+ Selenium 4 has `driver.network` over WebDriver BiDi. Capturing works, but
55
+ changing requests does not mix with normal Selenium code yet: with a request
56
+ handler set, `driver.get()` hangs in Chrome, because ChromeDriver does not
57
+ process the "continue this request" command while `get()` is running
58
+ ([selenium#17373](https://github.com/SeleniumHQ/selenium/issues/17373),
59
+ [selenium#18116](https://github.com/SeleniumHQ/selenium/issues/18116)).
60
+ netwire talks to the browser's DevTools socket directly, next to
61
+ ChromeDriver, so `get()`, clicks and everything else keep working while
62
+ requests are being changed.
63
+
64
+ ## Capturing
65
+
66
+ ```python
67
+ driver.requests # every captured request, oldest first
68
+ driver.last_request
69
+ driver.iter_requests()
70
+ del driver.requests # clear
71
+
72
+ request = driver.wait_for_request("/api/products", timeout=10)
73
+ request.url, request.method, request.headers, request.body, request.params
74
+ request.response.status_code, request.response.headers, request.response.body
75
+ request.ws_messages # websocket frames, for websocket requests
76
+ request.cert # the server's TLS certificate details
77
+
78
+ driver.scopes = [".*example.com/api/.*"] # only capture these
79
+ driver.har # HAR 1.2 archive as JSON
80
+ ```
81
+
82
+ Response bodies are already decompressed. `netwire.utils.decode()` is there
83
+ for code written for selenium-wire and returns the body unchanged.
84
+
85
+ ## Changing requests and responses
86
+
87
+ ```python
88
+ def interceptor(request):
89
+ del request.headers["User-Agent"]
90
+ request.headers["User-Agent"] = "my-agent"
91
+ if request.path.endswith((".png", ".jpg")):
92
+ request.abort()
93
+ if request.url == "https://example.com/api/config":
94
+ request.create_response(200, {"Content-Type": "application/json"}, b'{"beta": true}')
95
+
96
+ driver.request_interceptor = interceptor
97
+
98
+
99
+ def response_interceptor(request, response):
100
+ if request.path == "/api/data":
101
+ response.body = b'{"value": 7}'
102
+
103
+ driver.response_interceptor = response_interceptor
104
+
105
+ del driver.request_interceptor # stop intercepting
106
+ ```
107
+
108
+ Headers behave like selenium-wire's: names are case-insensitive, setting a
109
+ header adds it, so delete it first to replace it, and a missing header reads
110
+ as `None`.
111
+
112
+ ## Proxies
113
+
114
+ ```python
115
+ driver = webdriver.Chrome(seleniumwire_options={
116
+ "proxy": {
117
+ "https": "http://user:pass@proxy.example.com:8080",
118
+ "no_proxy": "localhost,127.0.0.1",
119
+ }
120
+ })
121
+ ```
122
+
123
+ | Proxy | How |
124
+ | --- | --- |
125
+ | HTTP or HTTPS, with or without user:pass | Chrome connects to it; netwire answers its login |
126
+ | SOCKS5 without a login | Chrome connects to it |
127
+ | SOCKS5 with user:pass | through netwire's relay (below) |
128
+ | `custom_authorization`, e.g. a Bearer token | through the relay |
129
+ | `HTTP_PROXY`, `HTTPS_PROXY`, `NO_PROXY` | read when no `proxy` option is given |
130
+
131
+ Chrome cannot log in to SOCKS proxies or change its proxy after starting. For
132
+ those, netwire starts a small relay on 127.0.0.1: Chrome uses it as a plain
133
+ SOCKS5 proxy and the relay connects through the real one. It only forwards
134
+ bytes; it does not decrypt anything.
135
+
136
+ To switch proxies while the driver runs, start with the relay on:
137
+
138
+ ```python
139
+ driver = webdriver.Chrome(netwire_options={"relay": True})
140
+ driver.proxy = {"https": "socks5://user:pass@proxy-1.example.com:1080"}
141
+ driver.get(...)
142
+ driver.proxy = {"https": "http://user:pass@proxy-2.example.com:8080"}
143
+ driver.get(...)
144
+ del driver.proxy # back to a direct connection
145
+ ```
146
+
147
+ Through the relay, HTTP proxies are used with `CONNECT` for every site,
148
+ `http://` ones included, so the proxy has to allow `CONNECT` to port 80.
149
+
150
+ ## What works where
151
+
152
+ | | Status |
153
+ | --- | --- |
154
+ | Chrome, Edge | supported |
155
+ | Requests in iframes, new tabs and popups | captured |
156
+ | Firefox | not yet |
157
+ | Remote WebDriver and Selenium Grid | not yet |
158
+ | selenium-wire's undetected-chromedriver integration | not yet |
159
+
160
+ ## Development
161
+
162
+ ```bash
163
+ uv sync
164
+ uv run pytest
165
+ ```
166
+
167
+ The tests start a real Chrome against local test servers and proxies.
168
+ `CHROME_BINARY` picks the browser and `NETWIRE_NO_SANDBOX=1` adds
169
+ `--no-sandbox` for containers.
170
+
171
+ ## License
172
+
173
+ MIT
@@ -0,0 +1,38 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "selenium-netwire"
7
+ version = "0.1.0"
8
+ description = "Capture and modify the browser's network traffic in Selenium. A maintained, drop-in successor to selenium-wire, built on the browser's DevTools protocol instead of a proxy."
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ requires-python = ">=3.10"
12
+ authors = [{ name = "Tugay Abdullazade" }]
13
+ keywords = ["selenium", "selenium-wire", "network", "intercept", "proxy", "scraping", "cdp", "devtools"]
14
+ classifiers = [
15
+ "Development Status :: 3 - Alpha",
16
+ "Framework :: Pytest",
17
+ "Intended Audience :: Developers",
18
+ "Programming Language :: Python :: 3",
19
+ "Topic :: Internet :: WWW/HTTP :: Browsers",
20
+ "Topic :: Software Development :: Testing",
21
+ ]
22
+ dependencies = ["selenium>=4.20", "websocket-client>=1.6"]
23
+
24
+ [project.urls]
25
+ Homepage = "https://github.com/tugayabdulla/selenium-netwire"
26
+ Issues = "https://github.com/tugayabdulla/selenium-netwire/issues"
27
+
28
+ [tool.hatch.build.targets.wheel]
29
+ packages = ["src/netwire"]
30
+
31
+ [dependency-groups]
32
+ dev = [
33
+ "pytest>=8",
34
+ "websockets>=13",
35
+ ]
36
+
37
+ [tool.pytest.ini_options]
38
+ testpaths = ["tests"]
@@ -0,0 +1,17 @@
1
+ """Capture and modify the browser's network traffic in Selenium.
2
+
3
+ A drop-in successor to selenium-wire, built on the browser's DevTools protocol
4
+ instead of a man-in-the-middle proxy::
5
+
6
+ from netwire import webdriver
7
+
8
+ driver = webdriver.Chrome()
9
+ driver.get("https://example.com")
10
+ for request in driver.requests:
11
+ print(request.method, request.url, request.response.status_code)
12
+ """
13
+
14
+ from .request import HTTPHeaders, Request, Response, WebSocketMessage
15
+
16
+ __version__ = "0.1.0"
17
+ __all__ = ["HTTPHeaders", "Request", "Response", "WebSocketMessage", "__version__"]