Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome doesn't start in WSL (Ubuntu 18.04) with "DevToolsActivePort file doesn't exist" under Chromedriver

I see the error

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>

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

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).

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.

like image 672
Derrell Durrett Avatar asked Dec 06 '22 09:12

Derrell Durrett


1 Answers

I found that the best solution was to not run headless from WSL and instead launch chrome from windows. After doing it both ways, I strongly prefer this option because:

  1. Tests are much more consistent. Running headless chrome in Ubuntu, I had failures that would come and go. This problem disappeared running headfull in Windows.
  2. You can see detailed logs if you use chromedriver --verbose
  3. If you pause execution during a test you can see the page and debug.
  4. I spent a long time fiddling with headless chrome options to get my tests to run; and then again after upgrading to Chrome version 79. With chromedriver, I didn't need any options.
  5. It's cool to see your tests run!

To do this:

  1. Download Chromedriver for Windows. Make sure you get the version that matches your version of Chrome. Unzip it somewhere. I used c:\dev
  2. Go to a windows command prompt and launch chromedriver C:\dev\chromedriver> chromedriver. It will tell you the port it's using. You'll need that in the next step. Mine showed Starting ChromeDriver 79.0.3945.36 (...) on port 9515
  3. In your 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
like image 131
Marcos Galigarcia Avatar answered Dec 07 '22 23:12

Marcos Galigarcia