[🐛 Bug]: Can't use DevTools features with Selenium Grid on Docker
See original GitHub issueWhat 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:
- Created a year ago
- Comments:6 (3 by maintainers)

Top Related StackOverflow Question
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_URLis a way to circumvent that.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.