Chrome无法在WSL(Ubuntu 18.04)中以"DevToolsActivePort文件不存在"启动.在Chromedriver下 [英] Chrome doesn't start in WSL (Ubuntu 18.04) with "DevToolsActivePort file doesn't exist" under Chromedriver

本文介绍了Chrome无法在WSL(Ubuntu 18.04)中以"DevToolsActivePort文件不存在"启动.在Chromedriver下的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到错误

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>

当尝试在WSL(适用于Linux的Windows子系统)的WSL下,通过Capybara在Rails(5.2.3)中通过Selenium :: Chromedriver启动无头Chrome时,该操作系统使用Ubuntu选项:headlessdisable-gpusingle-process(除了尝试使用选项no-sandboxproxy-server="direct://"disable-dev-shm-usageproxy-bypass-list="*"之外,所有选项均无效).

when trying to launch Chrome headless via Selenium::Chromedriver in Rails (5.2.3) with Capybara under WSL (Windows Subsystem for Linux) that's running Ubuntu 18.04 using the options to Chrome: headless, disable-gpu, and single-process (in addition to trying the options no-sandbox, proxy-server="direct://", disable-dev-shm-usage, and proxy-bypass-list="*", all to no effect).

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可执行文件(在这种情况下,它不接受必要的标志,也不会启动,我想这并不奇怪).

I tried a variety of other avenues to make this work, including permitting Chromedriver to attempt to discover the version of Chrome in use (this fails for likely related reasons, but I can't be entirely sure), using a symlink to point to the Windows executable for Chrome (in this case, it doesn't accept the necessary flags, and doesn't launch, which shouldn't be a surprise, I guess).

如果我在命令行中使用这些标志启动它,我将得到与google-chrome稍有不同的响应集,但它们归结为The GPU process has crashed(带有--headless --no-sandbox --disable-gpu)和ERROR:browser_main_loop.cc(601)] Failed to put Xlib into threaded mode.(添加--single-process)到该列表).

I get a slightly different set of responses from google-chrome if I launch it with these flags at the command line, but they boil down to 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. (adding --single-process to that list).

由于我暂时停留在此开发环境中,因此很乐意接受任何建议或要求提供信息.

As I'm stuck in this development environment for the moment, I'd gladly take any suggestions or requests for information.

推荐答案

我花了几个小时,但是@Samuel的答案和@twistezo的修改才是关键.这是我完整的解决方案:

I spent hours on this, but the answer by @Samuel with the modification by @twistezo were the key. Here is my complete solution:

请注意,按照@Samuel将chromeOptions修改为'goog:chromeOptions'.我不必在Windows中安装任何东西,但确实在Linux分区中安装了chrome.

Notice that chromeOptions is modified to 'goog:chromeOptions' as per @Samuel. I didn't have to install anything in windows, but I did install chrome in the Linux partition.

# spec/rails_helper.rb
Capybara.register_driver :headless_chrome do |app|
  capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
      'goog:chromeOptions': { args: %w(no-sandbox headless disable-gpu window-size=1280,1024 disable-features=VizDisplayCompositor) } )

  Capybara::Selenium::Driver.new(app, browser: :chrome, desired_capabilities: capabilities)
end

然后进行相关测试:

        describe 'the tests that need javascript', js: true do
          before(:all) do
            # Selenium::WebDriver.logger.level = :debug
            Capybara.current_driver = :headless_chrome
            Capybara.javascript_driver = :headless_chrome
          end

          after(:all) do
            Capybara.use_default_driver
          end

          it 'is reachable with javascript enabled' do
            visit root_path
            expect(page.current_path).to eq(root_path)
            assert page.evaluate_script('jQuery.active').zero?
          end
        end

更新到Google Chrome 79.0.3945.88

After updating to Google Chrome 79.0.3945.88

args: %w(headless window-size=1280,1024 no-sandbox enable-features=NetworkService,NetworkServiceInProcess  disable-features=VizDisplayCompositor)

这篇关于Chrome无法在WSL(Ubuntu 18.04)中以"DevToolsActivePort文件不存在"启动.在Chromedriver下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆