Chrome 无法在 WSL (Ubuntu 18.04) 中启动,并在 Chromedriver 下显示“DevToolsActivePort 文件不存在”

2024-02-08

我看到错误

Selenium::WebDriver::Error::UnknownError: unknown error: Chrome failed to start: crashed
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
#0 0x7f87e934a7a9 <unknown>

当尝试通过 Rails (5.2.3) 中的 Selenium::Chromedriver 与运行 Ubuntu 18.04 的 WSL(Linux 的 Windows 子系统)下的 Capybara 启动 Chrome headless 时,使用 Chrome 的选项:headless, disable-gpu, and single-process(除了尝试选项no-sandbox, proxy-server="direct://", disable-dev-shm-usage, and proxy-bypass-list="*",都没有效果)。

Gemfile.lock:

    GEM
  remote: https://rubygems.org/
  specs:
    actioncable (5.2.3)
      actionpack (= 5.2.3)
      nio4r (~> 2.0)
      websocket-driver (>= 0.6.1)
    actionmailer (5.2.3)
      actionpack (= 5.2.3)
      actionview (= 5.2.3)
      activejob (= 5.2.3)
      mail (~> 2.5, >= 2.5.4)
      rails-dom-testing (~> 2.0)
    actionpack (5.2.3)
      actionview (= 5.2.3)
      activesupport (= 5.2.3)
      rack (~> 2.0)
      rack-test (>= 0.6.3)
      rails-dom-testing (~> 2.0)
      rails-html-sanitizer (~> 1.0, >= 1.0.2)
    actionview (5.2.3)
      activesupport (= 5.2.3)
      builder (~> 3.1)
      erubi (~> 1.4)
      rails-dom-testing (~> 2.0)
      rails-html-sanitizer (~> 1.0, >= 1.0.3)
    activejob (5.2.3)
      activesupport (= 5.2.3)
      globalid (>= 0.3.6)
    activemodel (5.2.3)
      activesupport (= 5.2.3)
    activerecord (5.2.3)
      activemodel (= 5.2.3)
      activesupport (= 5.2.3)
      arel (>= 9.0)
    activestorage (5.2.3)
      actionpack (= 5.2.3)
      activerecord (= 5.2.3)
      marcel (~> 0.3.1)
    activesupport (5.2.3)
      concurrent-ruby (~> 1.0, >= 1.0.2)
      i18n (>= 0.7, < 2)
      minitest (~> 5.1)
      tzinfo (~> 1.1)
    addressable (2.6.0)
      public_suffix (>= 2.0.2, < 4.0)
    arel (9.0.0)
    backports (3.12.0)
    bootsnap (1.4.4)
      msgpack (~> 1.0)
    builder (3.2.3)
    byebug (11.0.1)
    capybara (3.14.0)
      addressable
      mini_mime (>= 0.1.3)
      nokogiri (~> 1.8)
      rack (>= 1.6.0)
      rack-test (>= 0.6.3)
      regexp_parser (~> 1.2)
      xpath (~> 3.2)
    childprocess (1.0.1)
      rake (< 13.0)
    coffee-rails (5.0.0)
      coffee-script (>= 2.2.0)
      railties (>= 5.2.0)
    coffee-script (2.4.1)
      coffee-script-source
      execjs
    coffee-script-source (1.12.2)
    concurrent-ruby (1.1.5)
    crass (1.0.4)
    cucumber (3.1.2)
      builder (>= 2.1.2)
      cucumber-core (~> 3.2.0)
      cucumber-expressions (~> 6.0.1)
      cucumber-wire (~> 0.0.1)
      diff-lcs (~> 1.3)
      gherkin (~> 5.1.0)
      multi_json (>= 1.7.5, < 2.0)
      multi_test (>= 0.1.2)
    cucumber-core (3.2.1)
      backports (>= 3.8.0)
      cucumber-tag_expressions (~> 1.1.0)
      gherkin (~> 5.0)
    cucumber-expressions (6.0.1)
    cucumber-rails (1.6.0)
      capybara (>= 1.1.2, < 4)
      cucumber (>= 3.0.2, < 4)
      mime-types (>= 1.17, < 4)
      nokogiri (~> 1.8)
      railties (>= 4, < 6)
    cucumber-tag_expressions (1.1.1)
    cucumber-wire (0.0.1)
    diff-lcs (1.3)
    domain_name (0.5.20180417)
      unf (>= 0.0.5, < 1.0.0)
    erubi (1.8.0)
    execjs (2.7.0)
    ffi (1.11.1)
    gherkin (5.1.0)
    globalid (0.4.2)
      activesupport (>= 4.2.0)
    haml (5.1.1)
      temple (>= 0.8.0)
      tilt
    http-cookie (1.0.3)
      domain_name (~> 0.5)
    i18n (1.6.0)
      concurrent-ruby (~> 1.0)
    jquery-rails (4.3.3)
      rails-dom-testing (>= 1, < 3)
      railties (>= 4.2.0)
      thor (>= 0.14, < 2.0)
    listen (3.1.5)
      rb-fsevent (~> 0.9, >= 0.9.4)
      rb-inotify (~> 0.9, >= 0.9.7)
      ruby_dep (~> 1.2)
    loofah (2.2.3)
      crass (~> 1.0.2)
      nokogiri (>= 1.5.9)
    mail (2.7.1)
      mini_mime (>= 0.1.1)
    marcel (0.3.3)
      mimemagic (~> 0.3.2)
    method_source (0.9.2)
    mime-types (3.2.2)
      mime-types-data (~> 3.2015)
    mime-types-data (3.2019.0331)
    mimemagic (0.3.3)
    mini_mime (1.0.1)
    mini_portile2 (2.4.0)
    minitest (5.11.3)
    msgpack (1.3.0)
    multi_json (1.13.1)
    multi_test (0.1.2)
    netrc (0.11.0)
    nio4r (2.3.1)
    nokogiri (1.10.3)
      mini_portile2 (~> 2.4.0)
    public_suffix (3.0.3)
    puma (3.12.1)
    rack (2.0.7)
    rack-test (1.1.0)
      rack (>= 1.0, < 3)
    rails (5.2.3)
      actioncable (= 5.2.3)
      actionmailer (= 5.2.3)
      actionpack (= 5.2.3)
      actionview (= 5.2.3)
      activejob (= 5.2.3)
      activemodel (= 5.2.3)
      activerecord (= 5.2.3)
      activestorage (= 5.2.3)
      activesupport (= 5.2.3)
      bundler (>= 1.3.0)
      railties (= 5.2.3)
      sprockets-rails (>= 2.0.0)
    rails-dom-testing (2.0.3)
      activesupport (>= 4.2.0)
      nokogiri (>= 1.6)
    rails-html-sanitizer (1.0.4)
      loofah (~> 2.2, >= 2.2.2)
    railties (5.2.3)
      actionpack (= 5.2.3)
      activesupport (= 5.2.3)
      method_source
      rake (>= 0.8.7)
      thor (>= 0.19.0, < 2.0)
    rake (12.3.2)
    rb-fsevent (0.10.3)
    rb-inotify (0.10.0)
      ffi (~> 1.0)
    regexp_parser (1.3.0)
    rest-client (2.0.2)
      http-cookie (>= 1.0.2, < 2.0)
      mime-types (>= 1.16, < 4.0)
      netrc (~> 0.8)
    rspec-core (3.8.0)
      rspec-support (~> 3.8.0)
    rspec-expectations (3.8.2)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.8.0)
    rspec-mocks (3.8.0)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.8.0)
    rspec-rails (3.8.2)
      actionpack (>= 3.0)
      activesupport (>= 3.0)
      railties (>= 3.0)
      rspec-core (~> 3.8.0)
      rspec-expectations (~> 3.8.0)
      rspec-mocks (~> 3.8.0)
      rspec-support (~> 3.8.0)
    rspec-support (3.8.0)
    ruby_dep (1.5.0)
    rubyzip (1.2.3)
    sassc (2.0.1)
      ffi (~> 1.9)
      rake
    sassc-rails (2.1.0)
      railties (>= 4.0.0)
      sassc (>= 2.0)
      sprockets (> 3.0)
      sprockets-rails
      tilt
    selenium-webdriver (3.142.3)
      childprocess (>= 0.5, < 2.0)
      rubyzip (~> 1.2, >= 1.2.2)
    spring (2.1.0)
    spring-watcher-listen (2.0.1)
      listen (>= 2.7, < 4.0)
      spring (>= 1.2, < 3.0)
    sprockets (3.7.2)
      concurrent-ruby (~> 1.0)
      rack (> 1, < 3)
    sprockets-rails (3.2.1)
      actionpack (>= 4.0)
      activesupport (>= 4.0)
      sprockets (>= 3.0.0)
    temple (0.8.1)
    thor (0.20.3)
    thread_safe (0.3.6)
    tilt (2.0.9)
    turbolinks (5.2.0)
      turbolinks-source (~> 5.2)
    turbolinks-source (5.2.0)
    tzinfo (1.2.5)
      thread_safe (~> 0.1)
    uglifier (4.1.20)
      execjs (>= 0.3.0, < 3)
    unf (0.1.4)
      unf_ext
    unf_ext (0.0.7.6)
    webdrivers (4.1.0)
      nokogiri (~> 1.6)
      rubyzip (~> 1.0)
      selenium-webdriver (>= 3.0, < 4.0)
    websocket-driver (0.7.1)
      websocket-extensions (>= 0.1.0)
    websocket-extensions (0.1.4)
    xpath (3.2.0)

  nokogiri (~> 1.8)

PLATFORMS
  ruby

DEPENDENCIES
  bootsnap (>= 1.1.0)
  byebug
  coffee-rails
  cucumber-rails
  haml
  jquery-rails
  listen (>= 3.0.5, < 3.2)
  puma (~> 3.11)
  rails (~> 5.2.2)
  rest-client
  rspec-rails
  sassc-rails
  spring
  spring-watcher-listen (~> 2.0.0)
  turbolinks
  tzinfo-data
  uglifier
  webdrivers (~> 4.0)

RUBY VERSION
   ruby 2.6.1p33

BUNDLED WITH
   2.0.2

我尝试了各种其他途径来完成这项工作,包括允许 Chromedriver 尝试发现正在使用的 Chrome 版本(由于可能的相关原因而失败,但我不能完全确定),使用符号链接指向Chrome 的 Windows 可执行文件(在这种情况下,它不接受必要的标志,并且不会启动,我想这应该不足为奇)。

我得到了一组略有不同的回复google-chrome如果我在命令行中使用这些标志启动它,但它们归结为The GPU process has crashed (with --headless --no-sandbox --disable-gpu) and ERROR:browser_main_loop.cc(601)] Failed to put Xlib into threaded mode.(添加--single-process到该列表)。

由于我目前处于这个开发环境中,我很乐意接受任何建议或信息请求。


我发现最好的解决方案是不要从 WSL 运行 headless,而是从 Windows 启动 chrome。在完成这两种方法之后,我非常喜欢这个选项,因为:

  1. 测试更加一致。在 Ubuntu 中运行 headless chrome,我 失败时有发生。这个问题消失了 在 Windows 中全神贯注地运行。
  2. 如果您使用的话,您可以看到详细的日志chromedriver --verbose
  3. 如果您在测试期间暂停执行,您可以看到该页面并进行调试。
  4. 我花了很长时间摆弄无头镀铬选项来获得我的 要运行的测试;然后在升级到 Chrome 版本 79 后再次出现。 使用 chromedriver,我不需要任何选项。
  5. 看到您的测试运行真是太酷了!

去做这个:

  1. 下载适用于 Windows 的 Chrome 驱动程序 https://chromedriver.chromium.org/downloads。确保您获得 与您的 Chrome 版本匹配的版本。将其解压到某处。我用的是c:\dev
  2. 转到 Windows 命令提示符并启动 chromedriverC:\dev\chromedriver> chromedriver。它会告诉你它所在的端口 使用。您在下一步中将需要它。我的显示Starting ChromeDriver 79.0.3945.36 (...) on port 9515
  3. 在你的rails_helper.rb中
Capybara.register_driver :windows_chrome do |app|
  capabilities = Selenium::WebDriver::Remote::Capabilities.chrome()
  puts 'Current driver (windows_chrome) requires chromedriver to be launched from windows (C:\dev\chromedriver>chromedriver)'
  Capybara::Selenium::Driver.new(app,browser: :chrome, url: 'http://localhost:9515',
                                     desired_capabilities: capabilities)
end

#Capybara.default_driver = :windows_chrome
Capybara.javascript_driver = :windows_chrome
Capybara.default_max_wait_time = 5 # Seconds
#Selenium::WebDriver.logger.level = :debug
# Webdrivers.logger.level = :DEBUG
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Chrome 无法在 WSL (Ubuntu 18.04) 中启动,并在 Chromedriver 下显示“DevToolsActivePort 文件不存在” 的相关文章

  • 在浏览器刷新中刷新检票面板

    我正在开发一个付费角色系统 一旦用户刷新浏览器 我就需要刷新该页面中可用的统计信息 统计信息应该从数据库中获取并显示 但现在它不能正常工作 因为在页面刷新中 java代码不会被调用 而是使用以前的数据加载缓存的页面 我尝试添加以下代码来修复
  • Internet Explorer 9 是否会因数组和对象文字末尾的额外逗号而卡住?

    现代浏览器和 Node js 等环境允许您说 a 1 b 2 或 1 2 3 这在历史上一直是 Internet Explorer 的问题 Internet Explorer 9 中修复了此问题吗 对此有两种不同的答案 一种是对象初始值设定
  • 洪水填充优化:尝试使用队列

    我正在尝试创建一种填充方法 该方法采用用户指定的初始坐标 检查字符 然后根据需要更改它 这样做之后 它会检查相邻的方块并重复该过程 经过一番研究 我遇到了洪水填充算法并尝试了该算法 它可以工作 但无法满足我对 250 x 250 个字符的数
  • iOS 电池监控 Swift

    我已将监控设置为启用 但模拟器和设备中的电池电量仍然为 1 UIDevice currentDevice batteryMonitoringEnabled true var level UIDevice currentDevice batt
  • Angular Libraries Monorepo:是否可以为每个库使用不同的版本?

    只是一个简单的问题 我似乎找不到答案 我正在尝试构建一个应该能够使用 angular cli v8 的 monorepo 但仍然能够编译和构建为 v2 v3 v4 等制作的库 主要是组件和服务 版本之间发生了很多变化 所以让我们举个例子 V
  • tkinter:打开一个带有按钮提示的新窗口[关闭]

    Closed 这个问题需要调试细节 help minimal reproducible example 目前不接受答案 用户如何按下 tkinter GUI 中的按钮来打开新窗口 我只需要非常简单的解决方案 如果代码也能被解释那就太好了 这
  • Azure函数版本2.0-应用程序blobTrigger不工作

    我有一个工作功能应用程序 它有一个 blob 输入和一个事件中心输出 在测试版中工作 随着最新的更改 我的功能不再起作用 我尝试根据发行说明更新 host json 文件 但它没有引用 blob 触发器 version 2 0 extens
  • 从输入类型编号获取无效值

    我正在使用输入类型数字 当它无效时 我如何从中获取值 例如 使用类型编号并仅打印 e 这本身是无效的 我正在使用 React 但我认为这个问题非常普遍 onChange event console log event target valu
  • 从类模板参数为 asm 生成唯一的字符串文字

    我有一个非常特殊的情况 我需要为类模板中声明的变量生成唯一的汇编程序名称 我需要该名称对于类模板的每个实例都是唯一的 并且我需要将其传递给asm关键字 see here https gcc gnu org onlinedocs gcc 12
  • 无法使用 HTML 设置未定义 jQuery UI 自动完成的属性“_renderItem”

    我使用以下代码将 jQuery UI 自动完成项呈现为 HTML 这些项目在自动完成控件中正确呈现 但我不断收到此 JavaScript 错误并且无法移动过去 Firefox 无法转换 JavaScript 参数 Chrome 无法设置未定
  • 如何确定母版页中正在显示哪个子页?

    我正在母版页上编写代码 我需要知道正在显示哪个子 内容 页面 我怎样才能以编程方式做到这一点 我用这个 string pageName this ContentPlaceHolder1 Page GetType FullName 它以 AS
  • 如何绘制大时间序列(数千次给药次数/药物剂量)?

    我正在尝试绘制医院中如何开出单一药物的图解 在这个虚拟数据库中 我在 2017 年 1 月 1 日之后遇到了 1000 名患者 绘图的目的是了解该药物的给药模式 在接近入院 出院或患者住院期间是否更频繁 高剂量给药 Get random d
  • python 中的 after() 与 update()

    我是 python 新手 开始使用 tkinter 作为画布 到目前为止 我使用 update 来更新我的画布 但还有一个 after 方法 谁能给我解释一下这个函数 请举个例子 两者之间有什么区别 root after integer c
  • 如何在 Erlang 中将数字转换为单词?

    我发现了一个关于将数字转换为 单词 的有趣问题 代码高尔夫 数字到单词 https stackoverflow com questions 309884 code golf number to words 我真的很想看看你如何在 Erlan
  • Angularjs:两种方式的数据绑定和控制器重新加载

    如果使用路由和控制器 则模型不会在控制器重新加载之间保存其状态 Angular 在每个路由负载上创建控制器实例和新范围 例如 我在输入中键入具有 ng model something 的内容 转到另一条路线 然后返回第一条路线 我输入的所有
  • 在java中使用多个bufferedImage

    我正在 java 小程序中制作游戏 并且正在尝试优化我的代码以减少闪烁 我已经实现了双缓冲 因此我尝试使用另一个 BufferedImage 来存储不改变的游戏背景元素的图片 这是我的代码的相关部分 public class QuizApp
  • 设置/覆盖 UICollectionView 中单元格之间的填充

    我有一个 UICollectionView 但在获取单元格之间的填充时遇到了问题 理论上 我应该能够将屏幕除以 4 并且我可以获得包含 4 个图像的单元格大小 完美地占据屏幕宽度 但是 它选择不这样做 相反 它会创建 3 个具有巨大填充的图
  • Prolog:子句在源文件中不在一起

    我有这段代码 Family tree female pen male tom male bob female liz female pat female ann male jim parent pam bob parent tom bob
  • 文件修改时间检查的成本

    对于Linux下包含少量字节的文件 我只需要处理自上次处理以来发生更改的时间 我通过调用 PHP 检查文件是否被更改clearstatcache filemtime 定期 由于整个文件总是很小 因此删除对 filemtime 的调用并通过将
  • 如何创建向后兼容 Windows 7 的缩放和尺寸更改每显示器 DPI 感知应用程序?

    我是 WPF 和 DPI 感知 API 的新手 正在编写一个在 Windows 7 8 1 和 10 中运行的应用程序 我使用具有不同每个显示器 DPI 设置的多个显示器 并且有兴趣将我的应用程序制作为跨桌面配置尽可能兼容 我已经知道可以将

随机推荐