Search code examples
rubycuprite

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


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.


Solution

  • 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