From 4c75a855186c6b2a78b62fcaea0bcbc974689220 Mon Sep 17 00:00:00 2001 From: SXP-Simon Date: Fri, 10 Oct 2025 17:12:50 +0800 Subject: [PATCH] =?UTF-8?q?[debug]=20=E8=B0=83=E8=AF=95=20pyppeteer=20?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=20chromium?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/pdf_utils.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/utils/pdf_utils.py b/src/utils/pdf_utils.py index e9f82ac..62ffb8a 100644 --- a/src/utils/pdf_utils.py +++ b/src/utils/pdf_utils.py @@ -89,9 +89,34 @@ class PDFInstaller: # 尝试启动浏览器,这会触发自动下载 logger.info("启动 pyppeteer 浏览器以触发 Chromium 自动下载...") + + # 根据操作系统设置不同的参数 + import platform + system = platform.system().lower() + + if system == "linux": + # Linux 环境下需要更多参数来避免权限问题 + browser_args = [ + '--no-sandbox', + '--disable-setuid-sandbox', + '--disable-dev-shm-usage', + '--disable-accelerated-2d-canvas', + '--no-first-run', + '--no-zygote', + '--single-process', + '--disable-gpu' + ] + else: + # Windows/macOS 环境下的标准参数 + browser_args = [ + '--no-sandbox', + '--disable-setuid-sandbox', + '--disable-gpu' + ] + browser = await launch( headless=True, - args=['--no-sandbox', '--disable-setuid-sandbox'] + args=browser_args ) # 获取 Chromium 路径