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

Selenium::Chrome启动报错:unknown error: DevToolsActivePort file doesn't exist

Chrome无法启动,Selenium创建会话失败

我的Perl代码

#!/usr/bin/perl -w0

use Selenium::Chrome;

$|++;
print "PATH: $ENV{PATH}\n\n";

my $chrome = Selenium::Chrome->new(
     browser_name       => 'chrome',
     extra_capabilities => {
       chromeOptions    => {
         args           => [ 'window-size=1920,1080',
                             'headless',
                             'no-sandbox',
                             'disable-dev-shm-usage',
                           ]}});

$chrome->get('http://www.google.com');

代码输出的PATH

PATH: /root/.local/bin:/root/bin:/home/admin/.local/bin:/home/admin/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/admin/.selenium

报错信息

无法创建新会话:未知错误:Chrome启动失败:异常退出。
(未知错误:DevToolsActivePort文件不存在)
(从路径/usr/bin/google-chrome启动的进程已停止运行,因此ChromeDriver认为Chrome已崩溃。)

环境信息

  • Chrome版本:Google Chrome 124.0.6367.118(路径:/usr/bin/google-chrome)
  • ChromeDriver版本:ChromeDriver 114.0.5735.90(路径:/home/admin/.selenium/)
  • Selenium Server版本:3.9.1(路径:/home/admin/.selenium/selenium-server-standalone.jar)

解决方法

  1. 修复版本不兼容问题:Chrome与ChromeDriver版本必须严格匹配,当前Chrome为124版本,ChromeDriver为114版本,版本差距过大是启动失败的核心原因。下载与Chrome 124.0.6367.118对应的ChromeDriver版本(版本号前三位需与Chrome一致),替换/home/admin/.selenium/下的chromedriver文件,执行chmod +x /home/admin/.selenium/chromedriver赋予可执行权限。

  2. 解决DevToolsActivePort文件不存在问题:在ChromeOptions的参数列表中添加remote-debugging-port=9222,指定调试端口,修改后的代码片段如下:

my $chrome = Selenium::Chrome->new(
     browser_name       => 'chrome',
     extra_capabilities => {
       chromeOptions    => {
         args           => [ 'window-size=1920,1080',
                             'headless',
                             'no-sandbox',
                             'disable-dev-shm-usage',
                             'remote-debugging-port=9222'
                           ]}});
  1. 升级Selenium Server:当前使用的Selenium Server 3.9.1版本过旧,建议升级至4.x系列,避免与新版Chrome、ChromeDriver出现兼容性冲突。

内容的提问来源于stack exchange,提问作者Ωmega

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.24 12:22:05