How to fix "Chrome process did not produce websocket url within 2 seconds" when running chrome headless in Docker

1.7k Views Asked by At

I'm using Cuprite driver for Capybara in my Ruby feature specs.

The specs run fine locally but fail with the error, Chrome process did not produce websocket url within 2 seconds, when the specs are run on our CI server. The CI server runs the specs within a Docker container.

The Docker image installs a recent version of Chrome, 77.0, from the Google PPA.

3

There are 3 best solutions below

0
Kris On BEST ANSWER

The driver needs to be configured to pass the --no-sandbox option to Chrome:

Capybara.register_driver :cuprite do |app|
  browser_options = {}.tap do |opts|
    opts['no-sandbox'] = nil if ENV['CI']
  end

  Capybara::Cuprite::Driver.new(app, browser_options: browser_options)
end
0
ndbroadbent On

I was just struggling with this issue on GitHub Actions. It turns out that the default process_timeout of 1 second is just too short, so Chrome didn't have time to start on the CI servers. It now works for me after extending process_timeout to a much larger value (20 seconds.) Here's the full code for my Capybara :cuprite driver:

  Capybara.register_driver(:cuprite) do |app|
    browser_options = {}
    browser_options['no-sandbox'] = nil if ENV['CI']
    headless = !ENV['SHOW_BROWSER']
    Capybara::Cuprite::Driver.new(
      app,
      browser_options: browser_options,
      headless: headless,
      process_timeout: 20
    )
  end
  Capybara.javascript_driver = :cuprite
0
stwienert On

In our case, the problem was wrong permissions on the /tmp/Crashpad directory, which Chrome will create on first run.

Make sure the directory is writable by the current unix/linux user.

So e.g.:

sudo chmod -R go+rwX /tmp/Crashpad

to make the directory and all the contents writable by everyone.