Giter Site home page Giter Site logo

Comments (9)

pdgonzalez872 avatar pdgonzalez872 commented on August 29, 2024 17

Turns out that you need the version of Chrome to be the same as the version of Chromedriver. That solved our problem.

from hound.

formido avatar formido commented on August 29, 2024 1

You may want to load hound as a local dependency and put some IO.puts on the requests and responses. I was getting the same error message as you, and when hound made a call to http://localhost:9515/session the result was:

{"sessionId":"d6187f3aee07899a2f7773ffcd967ff6","status":33,"value":{"message":"session not created: This version of ChromeDriver only supports Chrome version 77\n  (Driver info: chromedriver=77.0.3865.10 (bc3579f611bbc73331171afe020ec7a45e6ccc55-refs/branch-heads/3865@{#93}),platform=Linu\
x 3.13.0-24-generic x86_64)"}}

I didn't investigate further, but you can see that there's a sessionId that hound probably tries to use again, but according to the embedded message (session not created: This version of ChromeDriver only supports Chrome version 77) it's not valid.

Would love to see this error surfaced cos I just spent 3 hours tracking it down. 💯

It makes me think that libraries that wrap http apis should have a simple debug toggle so you can see all requests and responses, cos something in those usually seems to be the problem. Maybe they do and I just missed it.

Love that hound exists, it's crucial! 🥇

from hound.

mimimalizam avatar mimimalizam commented on August 29, 2024

Hi @edwinthinks,

I experienced the same error locally in earlier today and installing google-chrome-stable helped in my case. Maybe CI environment is also missing one of the dependencies. Thought to share it in case it might help someone else.

My Vagrant box with Ubuntu 18 inludes Google Chrome 75.0.3770.80 and ChromeDriver 75.0.3770.8.

from hound.

pdgonzalez872 avatar pdgonzalez872 commented on August 29, 2024

Having a similar issue, macOS Mojave.

@edwinthinks have you solved this?

@mimimalizam. How did you install google-chrome-stable? Any difference in the workflow? If so, could you please post them here?

Thank you!

from hound.

edwinthinks avatar edwinthinks commented on August 29, 2024

@pdgonzalez872 hey there; I didn't end up getting any solution :( I haven't had much time with using hound lately and left it as is. Hope you find a solution :)!

from hound.

pdgonzalez872 avatar pdgonzalez872 commented on August 29, 2024

Can we close this issue @edwinthinks?

from hound.

edwinthinks avatar edwinthinks commented on August 29, 2024

@pdgonzalez872 sure although I haven't been actively working with hound. If its reported working I can close this and only reopen if there is still an issue. Thanks @pdgonzalez872 !

from hound.

Sebisnow avatar Sebisnow commented on August 29, 2024

Problem Statement

I have the same problem collecting performance metrics from a company-internal website.
I do not have the problem with the first session, that works perfectly, but if I try to asynchronously start another session I get the following error and both sessions crash (Browser windows open and the first session already navigated to the website):

13:13:25.005 [error] Task #PID<0.274.0> started from #PID<0.269.0> terminating
** (RuntimeError) invalid session id
    (hound) lib/hound/request_utils.ex:52: Hound.RequestUtils.handle_response/3
    (hound_playground) lib/hound_playground.ex:56: HoundPlayground.collect_performance_metrics/2
    (elixir) lib/task/supervised.ex:90: Task.Supervised.invoke_mfa/2
    (elixir) lib/task/supervised.ex:35: Task.Supervised.reply/5
    (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Function: #Function<0.22341430/0 in HoundPlayground.async_pisa_test/2>

Both chromedriver and chromium have the same version:

sc1se@VM-65220044-Linux:~$ chromium-browser --version
  Chromium 77.0.3865.90 Built on Ubuntu , running on Ubuntu 18.04
sc1se@VM-65220044-Linux:~$ chromedriver --version
  ChromeDriver 77.0.3865.90 (58c425ba843df2918d9d4b409331972646c393dd-refs/branch-heads/3865@{#830})

I initialize each session with the following:

@chrome_prefs %{"protocol_handler" => %{"excluded_schemes" => %{"psadims" => false}}}

def start_new_session() do
    args =
    if System.get_env("browser") == "headless" do
      ["user-data-dir=/home/sc1se/.chromedriver", "headless"]
    else
      ["user-data-dir=/home/sc1se/.chromedriver"]
    end

    Hound.start_session(
      metadata: %{pid: self(), safe: false},
      driver: %{
        chromeOptions: %{
          "args" => args,
          "prefs" => @chrome_prefs
        }
      },
      browser: "chrome_driver"
    )
  end

The error also occurred when I used google-chrome (same major-, minor- and patch-version, only the build was a different one) instead of chromium.
Therefore this error is not only due to version differences in chromedriver and chrome. Any ideas why I get an invalid id error?

Solution

My problem was the my user-data-dir was the same for both sessions. Now I just appended the user-data-dir with a randomlz generaed character string e.g.: :crypto.strong_rand_bytes(5) |> Base.url_encode64() |> binary_part(0, 5).

I only found the problem thanks to @formido. I recompiled the Hound dependency with the following simple changes in the file deps/hound/lib/hound/request_utils.ex in the sending and receiving functions. I added a puts function before the request is sent to chromedriver and after the response is received.

 defp send_req(type, path, params, options) do
    url = get_url(path)
    has_body = params != %{} && type == :post
    {headers, body} = cond do
       has_body && options[:json_encode] != false ->
        {[{"Content-Type", "text/json"}], Jason.encode!(params)}
      has_body ->
        {[], params}
      true ->
        {[], ""}
    end

    IO.puts("the params #{inspect params}, the options #{inspect options}") # Here the request to chromedriver
    :hackney.request(type, url, headers, body, [:with_body | http_options()])
    |> handle_response({url, path, type}, options)
  end

  defp handle_response({:ok, code, headers, body}, {url, path, type}, options) do
    IO.puts("the params #{inspect body}, the code #{inspect code} the options #{inspect options}") # Here the response from chromedriver
    case Hound.ResponseParser.parse(response_parser(), path, code, headers, body) do
      :error ->
        raise """
        Webdriver call status code #{code} for #{type} request #{url}.
        Check if webdriver server is running. Make sure it supports the feature being requested.
        """
      {:error, err} = value ->
        if options[:safe],
          do: value,
          else: raise err
      response -> response
    end
  end

Thus I get the following logging:

the params %{desiredCapabilities: %{browserName: "chrome_driver", chromeOptions: %{"args" => ["user-data-dir=/home/sc1se/.chromedriver"], "prefs" => %{"protocol_handler" => %{"excluded_schemes" => %{"psadims" => false}}}}, cssSelectorsEnabled: true, javascriptEnabled: false, nativeEvents: false, platform: "ANY", rotatable: false, takesScreenshot: true, version: ""}}, the options %{}
the params "{\"sessionId\":\"e3332b47e7527c99dadb17d4d85ffc1e\",\"status\":61,\"value\":{\"message\":\"invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir\\n  (Driver info: chromedriver=77.0.3865.90 (58c425ba843df2918d9d4b409331972646c393dd-refs/branch-heads/3865@{#830}),platform=Linux 5.0.0-31-generic x86_64)\"}}", the code 200 the options %{}
the params %{url: "https://pisasales.elobau.de:9443/pisatest/pisasales"}, the options %{}
the params "{\"value\":{\"error\":\"invalid session id\",\"message\":\"invalid session id\",\"stacktrace\":\"#0 0x558b42a125c9 \\u003Cunknown>\\n\"}}", the code 404 the options %{}

Telling me I should not use user-data-dir again as it is already locked by another session.

I love hound but I suggest to improve the accuracy of the returned error. The error message only states the result but not what caused it.

from hound.

linomp avatar linomp commented on August 29, 2024

Turns out that you need the version of Chrome to be the same as the version of Chromedriver. That solved our problem.

Confirmed, same here. Windows 10.

from hound.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.