From 7afa8bf5ec8b2b09a7630e50edccc215825f8482 Mon Sep 17 00:00:00 2001 From: hjq <770690987@qq.com> Date: Tue, 23 Jun 2026 16:20:15 +0800 Subject: [PATCH] =?UTF-8?q?BOM=E5=8F=91=E6=96=99=E5=AF=B9=E6=AF=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- browser_login/login.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/browser_login/login.py b/browser_login/login.py index ea904e1..ab53067 100644 --- a/browser_login/login.py +++ b/browser_login/login.py @@ -143,17 +143,28 @@ def resolve_browser_path() -> str: def cleanup_debug_port(address: str) -> None: - """按实际 DevTools 端口清理僵尸浏览器进程。""" + """按实际 DevTools 端口清理僵尸浏览器进程及残留的锁文件。""" if not address or ":" not in address: return debug_port = address.rsplit(":", 1)[-1] + + # 1. 杀掉占用端口的僵尸进程 subprocess.run( f"lsof -ti tcp:{debug_port} | xargs -r kill -9", shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, ) + + # 2. 如果在 Linux 环境,彻底清理残留的 DrissionPage 锁文件,防止 "Failed to create SingletonLock" + if is_linux_env(): + subprocess.run( + "rm -rf /tmp/DrissionPage* /tmp/.org.chromium.*", + shell=True, + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + ) def clear_drission_singletons() -> None: @@ -241,6 +252,10 @@ def get_page(headless: bool = False, port: int = 9222) -> ChromiumPage: co.set_argument("--headless=new") co.set_argument("--disable-gpu") + # 针对 Linux 环境下的 SingletonLock 僵尸进程导致 Chrome 静默崩溃的问题 + if is_linux_env(): + co.set_argument("--disable-features=ProcessSingleton") + co.set_argument("--disable-blink-features=AutomationControlled") co.set_argument("--no-sandbox") co.set_argument("--disable-dev-shm-usage")