title: Chromedriver remote-debugging-port with Selenium
body: <p>I am using Capybara Selenium to run headless Chrome, which works great, except I cannot figure out how to use remote debugging.  When I add <code>--remote-debugging-port=4444</code> or <code>--remote-debugging-port=9222</code> or <code>--remote-debugging-port=9521</code>, Selenium no longer connects to the browser to run the test.</p>
  
  <p>How do I get remote debugging to work?  Here is my code for reference:</p>
  
  <pre><code>Capybara.register_driver :selenium do |app|
    # from https://github.com/SeleniumHQ/selenium/issues/3738
    capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(loggingPrefs: {browser: 'ALL'})
    options = Selenium::WebDriver::Chrome::Options.new
    options.add_argument '--disable-infobars' # hide info bar about chrome automating test
    # if we don't use this flag, every selenium test will die with the error:
    # "unknown error: Chrome failed to start: exited abnormally"
    options.add_argument '--no-sandbox'
    # BREAKS THINGS if uncommented
    # options.add_argument '--remote-debugging-port=4444'
    options.add_argument '--headless'
    options.add_argument '--window-size=1600,2400'
    options.add_preference('profile.default_content_settings.popups', 0)
    options.add_preference('download.default_directory', DownloadHelpers::PATH.to_s)
    Capybara::Selenium::Driver.new(
      app,
      clear_local_storage: true,
      clear_session_storage: true,
      browser: :chrome,
      options: options,
      desired_capabilities: capabilities,
    )
  end
  </code></pre>