hound icon indicating copy to clipboard operation
hound copied to clipboard

Headless Chrome sessions not starting on recent Chrome versions

Open michallepicki opened this issue 1 year ago • 6 comments

To fix the “invalid session id” we need to call:

Hound.start_session([additional_capabilities: %{browserName: "chrome"}])

michallepicki avatar Feb 07 '24 20:02 michallepicki

Thank you, Michał, for posting this. We hit the same issue, and your workaround worked nicely for us! Very much appreciated!

ScreenverseJames avatar Feb 21 '24 16:02 ScreenverseJames

Worked for us too! Thanks a bunch ❤️

agatheblues avatar Feb 28 '24 09:02 agatheblues

@michallepicki How did you conclude that? I tried your suggestion but it didn't work. Before I see this invalid session ID error, i see the following response for a POST /session call to the driver server.

%{
   "sessionId" => "e9796a5997cef178db3120e89d0f1f28",
   "status" => 33,
   "value" => %{
     "message" => "session not created: Chrome failed to start: exited normally.\n  (session not created: DevToolsActivePort file doesn't exist)\n  (The process started from chrome location /usr/lib/chromium/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)\n  (Driver info: chromedriver=121.0.6167.184 (057a8ae7deb3374d0f1b04b36304d236f0136188-refs/branch-heads/6167@{#1818}),platform=Linux 5.15.49-linuxkit-pr aarch64)"
   }
 }

Any idea?

HarshBalyan avatar Mar 11 '24 16:03 HarshBalyan

How did you conclude that?

I inspected responses from chromedriver somewhere in hound code, and there was an error about incorrect browser name. Unfortunately I am not familiar with the problem you're facing

michallepicki avatar Mar 11 '24 20:03 michallepicki

I finally solved it by overriding the chromeOptions that are set by default_capabilities for chrome_headless browser(I don't set user_agent in additional capabilities). I had to also set the browserName as an additional capability. My config

config :hound,
  driver: "chrome_driver",
  browser: "chrome_headless",
  host: System.get_env("HEADLESS_BROWSER_URL"),
  port: 9515

I started my hound_session/1 in test like

defmodule SomeTest do
  use ExUnit.Case
  use Hound.Helpers

  hound_session(additional_capabilities())

  # some tests
  
  defp additional_capabilities do
      [
        additional_capabilities: %{
          :"goog:chromeOptions" => %{
            "args" => [
              "--headless",
              "--disable-gpu",
              "--no-sandbox",
              "--disable-dev-shm-usage",
              "--disable-software-rasterizer"
            ]
          },
          browserName: "chrome"
        }
      ]
  end
end

I am using a flavour of this docker image for starting a chrome driver server.

HarshBalyan avatar Mar 12 '24 10:03 HarshBalyan

@HarshBalyan this shockingly worked for me as well. Thanks for the fix!

MikaAK avatar May 19 '24 04:05 MikaAK