Fix snap chromium path collapsing to /usr/bin/snap

readlink/realpath of /snap/bin/chromium becomes /usr/bin/snap, which is
not a browser and breaks DrissionPage launch. Keep the snap wrapper path,
reject snap host basenames, and prefer real deb chromium binaries.
This commit is contained in:
chaos committed 2026-07-12 00:49:45 +08:00
1 parent a790a371a8
commit 767516745e
5 files changed
+289 -70

No files matched your search

+33 -3
View File
@@ -182,18 +182,48 @@ def save_account(email: str, password: str, sso: str = ""):
f.write(f"{email}----{password}----{sso}\n")
print(f"[+] Saved: {email}")
def _normalize_browser_path(path: str | None) -> str | None:
"""Keep /snap/bin/chromium; never collapse to /usr/bin/snap."""
if not path:
return None
path = str(path).strip()
if not path:
return None
if not (os.path.isfile(path) or os.path.islink(path) or os.path.exists(path)):
return None
base = os.path.basename(path)
if base in ("snap", "snap-confine", "snapd", "env", "bash", "sh"):
return None
low = path.replace("\\", "/").lower()
if "chromium" not in low and "chrome" not in low:
return None
if path.startswith("/snap/bin/"):
return path
try:
real = os.path.realpath(path)
if os.path.basename(real) in ("snap", "snap-confine", "snapd"):
return path if ("chromium" in low or "chrome" in low) else None
if "chromium" in real.lower() or "chrome" in real.lower():
return real
except Exception:
pass
return path
def resolve_browser_path() -> str | None:
# Prefer Chromium: Google Chrome blocks --load-extension (turnstilePatch).
# Chrome-first order often leaves Turnstile token=0 on Xvfb servers.
# Never use realpath of /snap/bin/chromium → /usr/bin/snap (breaks launch).
for cand in (
"/usr/bin/chromium",
"/usr/bin/chromium-browser",
"/usr/lib/chromium/chromium",
"/snap/bin/chromium",
"/usr/bin/google-chrome-stable",
"/usr/bin/google-chrome",
):
if os.path.isfile(cand) or os.path.islink(cand):
return cand
norm = _normalize_browser_path(cand)
if norm:
return norm
return None