Skip to content

Commit 6c3ddae

Browse files
committed
chore: update nodriver to 0.50.6 and drop the obsolete encoding patch
1 parent 8614eee commit 6c3ddae

3 files changed

Lines changed: 15 additions & 53 deletions

File tree

‎pdm.lock‎

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ dependencies = [
4141
"certifi",
4242
"colorama",
4343
"jaraco.text", # required by pkg_resources during runtime
44-
"nodriver==0.50.3",
44+
"nodriver==0.50.6",
4545
"platformdirs>=2.1.0",
4646
"pydantic>=2.11.0",
4747
"ruamel.yaml",

‎scripts/fix_nodriver.py‎

Lines changed: 10 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,16 @@
33
# SPDX-ArtifactOfProjectHomePage: https://github.com/Second-Hand-Friends/kleinanzeigen-bot/
44
"""Post-install fixes for installed nodriver.
55
6-
1. **Encoding fix** — ``cdp/network.py`` contains a lone ISO-8859-1 ``±``
7-
byte (0xb1) without an encoding declaration. Python 3.12+ rejects this
8-
at import time. The fix adds a ``# -*- coding: utf-8 -*-`` header and
9-
replaces the byte with proper UTF-8.
10-
11-
2. **Flat-mode session retry** — nodriver 0.50.3+ uses flat-mode CDP
12-
(browser-level WebSocket + per-target ``sessionId``). Chromium 148+
13-
rejects ``DOM.enable`` when sent to the browser target without a
14-
``sessionId``, and rejects stale-session commands with ``-32601``.
15-
Wraps ``Connection.send`` to re-attach and retry once on that code,
16-
switching ``_attach=True`` commands to include ``sessionId``.
17-
18-
Designed as a PDM ``post_install`` hook. All patches are idempotent.
6+
**Flat-mode session retry** — nodriver 0.50.3+ uses flat-mode CDP
7+
(browser-level WebSocket + per-target ``sessionId``). Chromium 148+
8+
rejects ``DOM.enable`` when sent to the browser target without a
9+
``sessionId``, and rejects stale-session commands with ``-32601``.
10+
Wraps ``Connection.send`` to re-attach and retry once on that code,
11+
switching ``_attach=True`` commands to include ``sessionId``.
12+
13+
The former ``cdp/network.py`` encoding fix is obsolete since nodriver 0.50.6.
14+
15+
Designed as a PDM ``post_install`` hook. The patch is idempotent.
1916
"""
2017

2118
from __future__ import annotations
@@ -39,40 +36,6 @@ def _locate_file(relative:str) -> Path | None:
3936
return site_packages / relative
4037

4138

42-
# ── network.py encoding fix ────────────────────────────────────────────────
43-
44-
def _fix_network_encoding(path:Path) -> str:
45-
try:
46-
raw = path.read_bytes()
47-
except OSError as exc:
48-
print(f"fix_nodriver: cannot read {path}: {exc}", file = sys.stderr)
49-
sys.exit(1)
50-
51-
bad = b"(\xb1Inf)"
52-
if bad not in raw:
53-
try:
54-
raw.decode("utf-8")
55-
return "already-ok"
56-
except UnicodeDecodeError as exc:
57-
print(
58-
f"fix_nodriver: {path}: unexpected content: {exc}",
59-
file = sys.stderr,
60-
)
61-
sys.exit(1)
62-
63-
fixed = raw.replace(bad, b"(\xc2\xb1Inf)")
64-
if not fixed.startswith(b"# -*- coding: utf-8 -*-"):
65-
fixed = b"# -*- coding: utf-8 -*-\n" + fixed
66-
fixed = fixed.replace(b"\r\n", b"\n")
67-
try:
68-
fixed.decode("utf-8")
69-
except UnicodeDecodeError as exc:
70-
print(f"fix_nodriver: {path}: invalid UTF-8: {exc}", file = sys.stderr)
71-
sys.exit(1)
72-
path.write_bytes(fixed)
73-
return "fixed"
74-
75-
7639
# ── connection.py flat-mode session retry ──────────────────────────────────
7740

7841
# Keep this marker and guidance in sync with the CLI runtime guard in
@@ -190,7 +153,6 @@ def _fix_connection_send(path:Path) -> str:
190153

191154
def main() -> int:
192155
for rel, fix in [
193-
("nodriver/cdp/network.py", _fix_network_encoding),
194156
("nodriver/core/connection.py", _fix_connection_send),
195157
]:
196158
path = _locate_file(rel)

0 commit comments

Comments
 (0)