升级Chrome Driver至v89+后Python Selenium启动崩溃问题求助
Chrome v89+ 启动崩溃问题修复方案
问题概述
现有配置在Chrome/ChromeDriver v89以下版本可正常运行,但升级至v89及以上版本(如v90、v100、v110)后,Chrome启动崩溃,抛出错误:
Traceback (most recent call last): File "/opt/program/src/steps/start_browser_step.py", line 30, in handle browser = self.browser(options, service) File "/opt/program/src/steps/start_browser_step.py", line 105, in browser browser = ChromeBrowser(options=options, service=service) File "/opt/bitnami/python/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__ super().__init__( File "/opt/bitnami/python/lib/python3.8/site-packages/selenium/webdriver/chromium/webdriver.py", line 106, in __init__ super().__init__( File "/opt/bitnami/python/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 288, in __init__ self.start_session(capabilities, browser_profile) File "/opt/bitnami/python/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 381, in start_session response = self.execute(Command.NEW_SESSION, parameters) File "/opt/bitnami/python/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 444, in execute self.error_handler.check_response(response) File "/opt/bitnami/python/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 249, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed. (chrome not reachable) (The process started from chrome location /opt/program/bin/chrome-linux/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.) Stacktrace: #0 0x00400084a262 <unknown> #1 0x00400083b133 <unknown> #2 0x004000545ce1 <unknown> #3 0x00400056cf1c <unknown> #4 0x004000568c4e <unknown> #5 0x0040005ae38d <unknown> #6 0x0040005a4d83 <unknown> #7 0x004000573552 <unknown> #8 0x00400057478c <unknown> #9 0x0040007f33f6 <unknown> #10 0x004000809858 <unknown> #11 0x0040008090ff <unknown> #12 0x00400080a015 <unknown> #13 0x004000810cd3 <unknown> #14 0x00400080a39b <unknown> #15 0x0040007e51e7 <unknown> #16 0x004000827848 <unknown> #17 0x00400082798f <unknown> #18 0x004000835256 <unknown> #19 0x004002768fa3 start_thread #20 0x004002d244cf clone
尝试过webdriver-manager自动安装驱动,未解决问题。
修复方案
1. 移除冲突的启动参数
Chrome v89+对--single-process参数兼容性大幅下降,无头模式下该参数会直接导致进程崩溃;同时--start-maximized与--kiosk在无头模式下存在冲突,--kiosk已强制全屏,无需重复设置。
修改Python启动代码中的参数:
from selenium.webdriver import Chrome as ChromeBrowser from selenium.webdriver.chrome.options import Options as ChromeOptions from selenium.webdriver.chrome.service import Service as ChromeService options = ChromeOptions() options.binary_location = '/opt/program/bin/chrome-linux/chrome' user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/605.1.15 (KHTML, like Gecko) ' \ 'CriOS/85 Version/11.1.1 Safari/605.1.15' options.add_argument(f'user-agent={user_agent}') options.add_argument('--allow-running-insecure-content') options.add_argument('--ignore-certificate-errors') options.add_argument('--disable-gpu') options.add_argument('--hide-scrollbars') options.add_argument('--window-size=1400,1080') options.add_argument('--disable-cache') options.add_argument('--headless=new') # v96+推荐使用该参数替代旧版--headless options.add_argument('--no-sandbox') options.add_argument('--disable-dev-shm-usage') options.add_argument('--kiosk') service = ChromeService(executable_path='/opt/program/bin/chromedriver_linux64/chromedriver') browser = ChromeBrowser(options=options, service=service)
注:Chrome v96及以上版本推荐使用
--headless=new,比旧版--headless更稳定,功能更完整。
2. 补充高版本Chrome依赖库
在Dockerfile的apt-get install环节添加v89+所需的额外依赖:
RUN apt-get install -y libu2f-udev libvulkan1
3. 确保Chrome二进制文件权限
在Dockerfile中解压Chrome和ChromeDriver后,添加权限设置:
RUN chmod +x /opt/program/bin/chrome-linux/chrome RUN chmod +x /opt/program/bin/chromedriver_linux64/chromedriver
4. 升级Selenium至兼容版本
当前使用的Selenium 4.6.0虽支持高版本Chrome,但升级到最新稳定版可修复已知兼容性问题,修改requirements.txt:
selenium==4.15.0 # 替换为最新稳定版
5. 严格匹配Chrome与ChromeDriver版本
确认下载的Chrome和ChromeDriver版本完全一致,用户提供的1109227对应Chrome 111.x版本,需确保两者版本号严格对应,避免版本不匹配导致启动失败。
内容的提问来源于stack exchange,提问作者Scobee
相关产品推荐
相关产品推荐

