question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[🐛 Bug]: Can't use DevTools features with Selenium Grid on Docker

See original GitHub issue

What happened?

Not sure if this is strictly a bug, but at least the documentation regarding this issue is missing.

I managed to work with DevTools features in Selenium 4 locally, but when I tried to use it on Selenium Grid, it didn’t work.

In order to investigate it, I installed a local grid with one Chrome node using docker-compose and I got the same error:

OpenQA.Selenium.WebDriverException : Unexpected error creating WebSocket DevTools session.
  ----> System.Net.WebSockets.WebSocketException : Unable to connect to the remote server
  ----> System.Net.Http.HttpRequestException : A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (172.18.0.3:4444)
  ----> System.Net.Sockets.SocketException : A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

Where 172.18.0.3 is the private IP of chrome-node container.

I guess that the main reason is that I don’t have access to that IP from the host, and that’s probably a docker configuration matter, on which I’m not an expert. But that wasn’t the only problem.

Using the debugger, I was able to track that the driver tries to use this address due to the following capability that is returned from the driver after creation: "se:cdp": "ws://172.18.0.3:4444/session/2c519f679e1060cdc926ca74e63e222f/se/cdp". I then tweaked this value (in the debugger, before trying to create the connection to the DevTools protocol) to use localhost instead of the private IP, and then I got the following error: IOException: The response ended prematurely..

What do I need to do in order to use the DevTools features of Selenium through Selenium Grid (and docker)?

PS: also posted this question on StackOverflow here.

How can we reproduce the issue?

Docker-compose:

# To execute this docker-compose yml file use `docker-compose -f docker-compose-v3.yml up`
# Add the `-d` flag at the end for detached execution
# To stop the execution, hit Ctrl+C, and then `docker-compose -f docker-compose-v3.yml down`
version: "3"
services:
  chrome:
    image: selenium/node-chrome:4.4.0-20220831
    shm_size: 2gb
    depends_on:
      - selenium-hub
    environment:
      - SE_EVENT_BUS_HOST=selenium-hub
      - SE_EVENT_BUS_PUBLISH_PORT=4442
      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443
    ports:
      - "4444:4444"

  selenium-hub:
    image: selenium/hub:4.4.0-20220831
    container_name: selenium-hub
    ports:
      - "4442:4442"
      - "4443:4443"
      - "4445:4444"

(Note: I exposed port 4444 from the node-chrome container and redirected the hub’s 4444 to 4445, so that both will be accessible from the host)

public class MyTestClass
{
        [Test]
        public void ConnectToRemoteDevTools()
        {
            var chromeOptions = new ChromeOptions();
            using var driver = new RemoteWebDriver(new Uri("http://localhost:4445/"), chromeOptions.ToCapabilities(), TimeSpan.FromMinutes(10));

            // This line throws the exception:
            var devTools = driver.GetDevToolsSession(104);
        }
}

Relevant log output

N/A

Operating System

Windows 10

Selenium version

4.4.0

What are the browser(s) and version(s) where you see this issue?

Chrome v105.0

What are the browser driver(s) and version(s) where you see this issue?

selenium/node-chrome:4.4.0-20220831

Are you using Selenium Grid?

selenium/hub:4.4.0-20220831 (revision e5c75ed026a)

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
diemolcommented, Oct 11, 2022

That is actually part of the README: https://github.com/SeleniumHQ/docker-selenium#grid-url-and-session-timeout

It is not a bug because the way Docker works, it reports the internal IP from the container. Using SE_NODE_GRID_URL is a way to circumvent that.

0reactions
github-actions[bot]commented, Nov 11, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using DevTools features with Selenium Grid on Docker
In order to investigate it, I installed a local grid with one Chrome node using docker-compose and I got the same error: OpenQA.Selenium....
Read more >
How to Integrate Selenium Grid with Docker
This Docker Selenium Tutorial will explain to you more about what a Docker is and how we download, install, and integrate it with...
Read more >
What's New In Selenium 4? - Automated Visual Testing
Grid makes it possible to distribute and run your tests across more than just one machine. Let us dive in and take a...
Read more >
neotys/docker-selenium - Docker Image
selenium server grid with 2 nodes (chrome & firefox); mp4 video recording; VNC access (useful for debugging the container); google-chrome-stable ...
Read more >
Setting up your own Grid 3 - Selenium
To use Selenium Grid, you need to maintain your own infrastructure for the nodes. As this can be a cumbersome and time intense...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found