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]: Unable to establish websocket connection to http://x.x.x.x:4444/session/${session}/se/cdp

See original GitHub issue

What happened?

My objective is: to retrieve information in a xhr response body, sent by a submitted filled in form

My approach is: to use DevTools.

  1. locally, my approach is working
  2. remotely, my approach isn’t working indeed i have this exception 14:29:12 org.openqa.selenium.remote.http.ConnectionFailedException: 14:29:12 Unable to establish websocket connection to http://x.x.x.x:4444/session/${session}/se/cdp 14:29:12 Build info: version: ‘4.0.0’, revision: ‘3a21814679’ 14:29:12 System info: host: ‘c54d6a2a855f’, ip: ‘10.0.5.6’, os.name: ‘Linux’, os.arch: ‘amd64’, os.version: ‘3.10.0-1160.45.1.el7.x86_64’, java.version: ‘11.0.12’ 14:29:12 Driver info: driver.version: unknown

How can we reproduce the issue?

**DevTools**
Code to use DevTools
-----------------------
        WebDriver augmentedDriver= new Augmenter().augment(WebDriverRunner.getWebDriver());
        DevTools devTools = ((ChromeDriver) augmentedDriver).getDevTools();
        devTools.createSession();
        devTools.send(Network.enable(Optional.of(100000000), Optional.empty(), Optional.empty()));
        final String[] textFromResponseBody= new String[1];
        devTools.addListener(Network.responseReceived(), responseReceived -> {
            if (responseReceived.getResponse()
                                .getUrl()
                                .contains(PATH_CONTEXT)) {
                textFromResponseBody[0] = devTools.send(Network.getResponseBody(responseReceived.getRequestId()))
                                                           .getBody();
            }
        });

after the filling in the form
-----------------------------
        log.info("clickOnSubmit " + SUBMIT_BUTTON);
        SUBMIT_BUTTON.should(enabled, visible)
                     .click();

confirmation of extracting the responseBody
-------------------------------------------
         log.info("Work request ID : {}", textFromResponseBody[0]);

**NetworkInterceptor**
        final String[] textFromResponseBody= new String[1];
        NetworkInterceptor interceptor = new NetworkInterceptor(
                (((ChromeDriver)new Augmenter().augment(WebDriverRunner.getWebDriver()))),
                (Filter) next -> req -> {
                    HttpResponse res = next.execute(req);
                    if ( req.getUri().contains(PATH_CONTEXT)) {
                        log.info(res.getContentString());
                        textFromResponseBody[0] = res.getContentString();
                    }
                    return res;
                }
        );

Relevant log output

14:29:11  Dec 07, 2021 1:28:54 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
14:29:11  INFO: Found exact CDP implementation for version 95
14:29:11  Dec 07, 2021 1:29:04 PM org.openqa.selenium.remote.http.netty.NettyWebSocket lambda$new$0
14:29:11  WARNING: connection timed out: /x.x.x.x:4444
14:29:11  java.net.ConnectException: connection timed out: /x.x.x.x:4444
14:29:11  	at org.asynchttpclient.netty.channel.NettyConnectListener.onFailure(NettyConnectListener.java:179)
14:29:11  	at org.asynchttpclient.netty.channel.NettyChannelConnector$1.onFailure(NettyChannelConnector.java:108)
14:29:11  	at org.asynchttpclient.netty.SimpleChannelFutureListener.operationComplete(SimpleChannelFutureListener.java:28)
14:29:11  	at org.asynchttpclient.netty.SimpleChannelFutureListener.operationComplete(SimpleChannelFutureListener.java:20)
14:29:11  	at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:578)
14:29:11  	at io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:571)
14:29:11  	at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:550)
14:29:11  	at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:491)
14:29:11  	at io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:616)
14:29:11  	at io.netty.util.concurrent.DefaultPromise.setFailure0(DefaultPromise.java:609)
14:29:11  	at io.netty.util.concurrent.DefaultPromise.tryFailure(DefaultPromise.java:117)
14:29:11  	at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe$1.run(AbstractNioChannel.java:262)
14:29:11  	at io.netty.util.concurrent.PromiseTask.runTask(PromiseTask.java:98)
14:29:11  	at io.netty.util.concurrent.ScheduledFutureTask.run(ScheduledFutureTask.java:170)
14:29:11  	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
14:29:11  	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:469)
14:29:11  	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
14:29:11  	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
14:29:11  	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
14:29:11  	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
14:29:11  	at java.base/java.lang.Thread.run(Thread.java:866)
14:29:11  Caused by: io.netty.channel.ConnectTimeoutException: connection timed out: /10.42.2.196:4444
14:29:11  	at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe$1.run(AbstractNioChannel.java:261)
14:29:11  	... 9 more
14:29:11  
14:29:11  Dec 07, 2021 1:29:04 PM org.openqa.selenium.remote.http.WebSocket$Listener onError
14:29:11  WARNING: connection timed out: /x.x.x.x:4444
14:29:11  java.net.ConnectException: connection timed out: /x.x.x.x:4444
14:29:11  	at org.asynchttpclient.netty.channel.NettyConnectListener.onFailure(NettyConnectListener.java:179)
14:29:11  	at org.asynchttpclient.netty.channel.NettyChannelConnector$1.onFailure(NettyChannelConnector.java:108)
14:29:11  	at org.asynchttpclient.netty.SimpleChannelFutureListener.operationComplete(SimpleChannelFutureListener.java:28)
14:29:11  	at org.asynchttpclient.netty.SimpleChannelFutureListener.operationComplete(SimpleChannelFutureListener.java:20)
14:29:11  	at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:578)
14:29:11  	at io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:571)
14:29:11  	at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:550)
14:29:11  	at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:491)
14:29:11  	at io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:616)
14:29:11  	at io.netty.util.concurrent.DefaultPromise.setFailure0(DefaultPromise.java:609)
14:29:11  	at io.netty.util.concurrent.DefaultPromise.tryFailure(DefaultPromise.java:117)
14:29:11  	at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe$1.run(AbstractNioChannel.java:262)
14:29:11  	at io.netty.util.concurrent.PromiseTask.runTask(PromiseTask.java:98)
14:29:11  	at io.netty.util.concurrent.ScheduledFutureTask.run(ScheduledFutureTask.java:170)
14:29:11  	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
14:29:11  	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:469)
14:29:11  	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
14:29:11  	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
14:29:11  	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
14:29:11  	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
14:29:11  	at java.base/java.lang.Thread.run(Thread.java:866)
14:29:11  Caused by: io.netty.channel.ConnectTimeoutException: connection timed out: /10.42.2.196:4444
14:29:11  	at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe$1.run(AbstractNioChannel.java:261)
14:29:11  	... 9 more
14:29:11  
...
...
14:29:12  [ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 51.575 s <<< FAILURE! - in TestSuite
14:29:12  [ERROR] ...  Time elapsed: 46.934 s  <<< FAILURE!
14:29:12  org.openqa.selenium.remote.http.ConnectionFailedException: 
14:29:12  Unable to establish websocket connection to http://x.x.x.x:4444/session/${session}/se/cdp
14:29:12  Build info: version: '4.0.0', revision: '3a21814679'
14:29:12  System info: host: 'c54d6a2a855f', ip: '10.0.5.6', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-1160.45.1.el7.x86_64', java.version: '11.0.12'
14:29:12  Driver info: driver.version: unknown
14:29:12  	at ...
14:29:12  
14:29:12  [INFO]

Operating System

Docker Debian GNU/Linux 11 (bullseye)

Selenium version

openjdk 11.0.13 2021-10-19

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

Chrome 95

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

ChromeDriver 95 via Selenide / WebDriverManager

Are you using Selenium Grid?

Selenium Grid 4.1.0 (revision aea69daa1c)

my comments

i see we want to connect to a websocket but the protocol is http …

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:22 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
diemolcommented, Dec 17, 2021

Well, a Grid should not be exposed to the internet… There is a way to set a user and a password https://www.selenium.dev/documentation/grid/configuration/cli_options/#router

1reaction
diemolcommented, Dec 16, 2021

After reading again, the issue is that the connection to the websocket cannot be done because it is attempted with the internal docker container IP. To avoid that, please check how to set the Grid url in docker-selenium.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can I catch the "can't establish a connection" error for a failed ...
Adding try {} catch(e) {} to my code, both when connecting the socket and closing it - no change. Any ideas on how...
Read more >
How to resolve the error: "Could not open websocket connection
log messages fail to show. The issue is seen when WebSocket requests are not passed correctly by a reverse proxy or a load...
Read more >
Error with WebSocket - Microsoft Q&A
Hello I get the error: WebSocket connection to 'wss://localhost:54970/Dashboard.Server/' failed: Error in connection establishment: ...
Read more >
FAQ — websocket-client 1.4.2 documentation
This error is caused when you receive a character that is not a UTF-8 character, so the UTF-8 decoding fails. You can set...
Read more >
WebSocket connection fails in WatchOS9 - Apple Developer
2022-09-16 09:41:54.432645-0400 watchOS9Websockets Watch App[968:637613] Error getting network data status Error Domain=NSPOSIXErrorDomain Code=19 ...
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