You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker环境Chrome升级至128+后WebDriver会话创建失败求助

问题:Docker中Chrome 128+版本无法启动Webdriver.io会话

我在Docker容器中使用webdriver.io运行测试,Chrome 127版本时测试正常,但升级至128及以上版本后,出现WebDriverError: session not created错误。

我的Webdriver.io能力配置

capabilities: [{
    'wdio:maxInstances': 1,
    'wdio:enforceWebDriverClassic': true,  
    browserName: 'chrome',
    acceptInsecureCerts: true,
    'goog:chromeOptions': {
        args: [
            '--headless',
            '--no-sandbox',
            '--disable-gpu',
            '--disable-dev-shm-usage',
            '--disable-infobars',
            '--disable-search-engine-choice-screen',
            '--window-size=1920,1200']
    }
  }]

我的Dockerfile

FROM node:22

RUN apt-get update \
    && apt-get -y install sudo \
    && apt-get install -y unzip \
    # See https://crbug.com/795759
    && apt-get install -yq libgconf-2-4 \
    && apt-get install gnupg -y \
    && apt-get install -y wget --no-install-recommends \
    && apt-get install iputils-ping -y \
    && apt-get install libpci-dev -y \
    && wget --quiet --output-document=- https://dl-ssl.google.com/linux/linux_signing_key.pub | gpg --dearmor > /etc/apt/trusted.gpg.d/google-archive.gpg \
    && sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'


RUN  apt-get update \
     && apt-get install -y google-chrome-stable --no-install-recommends \
     && rm -rf /var/lib/apt/lists/*

RUN echo "node    ALL=(ALL)       NOPASSWD: ALL" > /etc/sudoers.d/node

wdio输出

...
16:12:35 [0-0] 2024-11-06T15:12:35.177Z INFO @wdio/utils: Started Chromedriver v130.0.6723.116 with params --port=43274 --allowed-origins=* --allowed-ips=0.0.0.0 in 105ms on port 43274
16:12:35 [0-0] 2024-11-06T15:12:35.182Z INFO webdriver: [POST] http://localhost:43274/session
16:12:35 [0-0] 2024-11-06T15:12:35.182Z INFO webdriver: DATA {
16:12:35 [0-0]   capabilities: {
16:12:35 [0-0]     alwaysMatch: {
16:12:35 [0-0]       'wdio:maxInstances': 1,
16:12:35 [0-0]       'wdio:enforceWebDriverClassic': true,
16:12:35 [0-0]       browserName: 'chrome',
16:12:35 [0-0]       acceptInsecureCerts: true,
16:12:35 [0-0]       'goog:chromeOptions': [Object]
16:12:35 [0-0]     },
16:12:35 [0-0]     firstMatch: [ {} ]
16:12:35 [0-0]   }
16:12:35 [0-0] }
16:12:35 [0-0] 2024-11-06T15:12:35.356Z DEBUG webdriver: request failed due to response error: session not created
16:12:35 [0-0] 2024-11-06T15:12:35.357Z WARN webdriver: WebDriverError: session not created: Chrome failed to start: exited normally.
16:12:35 [0-0]   (session not created: DevToolsActivePort file doesn't exist)
16:12:35 [0-0]   (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.) when running "http://localhost:43274/session" with method "POST" and args "{"capabilities":{"alwaysMatch":{"wdio:maxInstances":1,"wdio:enforceWebDriverClassic":true,"browserName":"chrome","acceptInsecureCerts":true,"goog:chromeOptions":{"binary":"/usr/bin/google-chrome","args":["--headless","--no-sandbox","--disable-gpu","--disable-dev-shm-usage","--disable-infobars","--disable-search-engine-choice-screen","--window-size=1920,1200"]}},"firstMatch":[{}]}}"

已尝试的解决方法

  • 添加--remote-debugging-port=9222参数后,不再出现DevToolsActivePort file doesn't exist错误,但仍提示"chrome not reachable",无法创建会话:
16:44:59 [0-2] 2024-11-06T15:44:59.757Z INFO chromedriver: ChromeDriver was started successfully on port 46617.
16:44:59 [0-2] 2024-11-06T15:44:59.758Z INFO @wdio/utils: Started Chromedriver v130.0.6723.116 with params --port=46617 --allowed-origins=* --allowed-ips=0.0.0.0 in 116ms on port 46617
16:44:59 [0-2] 2024-11-06T15:44:59.761Z INFO webdriver: [POST] http://localhost:46617/session
16:44:59 [0-2] 2024-11-06T15:44:59.762Z INFO webdriver: DATA {
16:44:59 [0-2]   capabilities: {
16:44:59 [0-2]     alwaysMatch: {
16:44:59 [0-2]       'wdio:maxInstances': 1,
16:44:59 [0-2]       'wdio:enforceWebDriverClassic': true,
16:44:59 [0-2]       browserName: 'chrome',
16:44:59 [0-2]       acceptInsecureCerts: true,
16:44:59 [0-2]       'goog:chromeOptions': [Object]
16:44:59 [0-2]     },
16:44:59 [0-2]     firstMatch: [ {} ]
16:44:59 [0-2]   }
16:44:59 [0-2] }
16:45:00 [0-2] 2024-11-06T15:45:00.893Z DEBUG webdriver: request failed due to response error: session not created
16:45:00 [0-2] 2024-11-06T15:45:00.895Z WARN webdriver: WebDriverError: session not created: Chrome failed to start: exited normally.
16:45:00 [0-2]   (chrome not reachable)
16:45:00 [0-2]   (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.) when running "http://localhost:46617/session" with method "POST" and args "{"capabilities":{"alwaysMatch":{"wdio:maxInstances":1,"wdio:enforceWebDriverClassic":true,"browserName":"chrome","acceptInsecureCerts":true,"goog:chromeOptions":{"binary":"/usr/bin/google-chrome","args":["--remote-debugging-port=9222","--headless","--no-sandbox"]}},"firstMatch":[{}]}}"
  • 在能力配置中添加browserVersion: '128',让WebdriverIO自动下载对应版本,问题依旧;指定browserVersion: '127'则正常。

解决思路

  • 更新无头模式参数:Chrome 128+废弃了旧的--headless参数,改用--headless=new。这是新版Chrome启动失败的常见原因,旧参数会导致浏览器启动异常。
  • 严格匹配Chrome与ChromeDriver版本:确保ChromeDriver版本和Chrome版本完全一致,WebdriverIO自动下载可能出现版本不匹配,可手动指定对应版本的ChromeDriver,或检查@wdio/chromedriver-service的配置。
  • 补充系统依赖:Chrome 128+可能新增了依赖,在Dockerfile的apt-get install步骤中添加以下包:libnss3 libatk1.0-0 libatk-bridge2.0-0 libcups2 libdrm2 libxkbcommon0 libxcomposite1 libxdamage1 libxrandr2 gb18030 libgbm1 libasound2。
  • 切换普通用户运行:避免用root用户启动Chrome,在Dockerfile中创建普通用户并切换:
    RUN useradd -m -s /bin/bash testuser
    USER testuser
    
  • 清理无效参数:移除新版Chrome中不再需要的参数,比如--disable-gpu在无头模式下已无需配置,简化启动参数列表。

内容的提问来源于stack exchange,提问作者nathalie cossement

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 11:50:53