How to resolve the org.openqa.selenium.remote.http.WebSocket$Listener onError issue in Selenium?
When running a simple Selenium script to open Chrome, the console logs show a WebSocket$Listener onError warning followed by a java.net.SocketException: Connection reset.
Here’s the sample code:
import org.openqa.selenium.chrome.*;
public class Testt {
static {
System.setProperty("webdriver.chrome.driver","./driver/chromedriver.exe");
}
public static void main(String[] args) {
ChromeDriver driver = new ChromeDriver();
driver.close();
}
}
Output log shows:
org.openqa.selenium.remote.http.WebSocket$Listener onError
WARNING: Connection reset
java.net.SocketException: Connection reset
...
Although ChromeDriver starts successfully, this error appears frequently.
How can you prevent or handle the WebSocket$Listener onError warning in Selenium, and what causes this issue when using newer versions of ChromeDriver or Selenium?
This message shows up because Selenium 4+ communicates with Chrome using the Chrome DevTools Protocol (CDP), which runs over a WebSocket connection.
What usually happens is: when you call driver.close() or driver.quit(), ChromeDriver shuts down a little too quickly, and Selenium doesn’t get a chance to gracefully close the underlying WebSocket.
So the socket abruptly resets, and you see:
org.openqa.selenium.remote.http.WebSocket$Listener onError
WARNING: Connection reset
java.net.SocketException: Connection reset
Simple Fix
Use driver.quit() instead of driver.close(), or add a tiny delay before shutting down the browser.
ChromeDriver driver = new ChromeDriver();
driver.get("https://example.com");
driver.quit(); // lets Selenium close the WebSocket cleanly
Why You Don’t Need to Panic
This doesn’t break anything. Your tests still run fine, it’s just an annoying log entry because the WebSocket closed too quickly.
Good breakdown, @ian-partridge
To add to that. this error becomes much more frequent when ChromeDriver and Chrome versions don’t perfectly match.
Because CDP is version-sensitive, even a small mismatch means the WebSocket session becomes unstable and resets before Selenium is done with it.
What to Check
Make sure these versions are aligned:
Fix
Keep Chrome + ChromeDriver in sync, and upgrade Selenium to the latest version:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.24.0</version>
</dependency>
Even if the error is harmless, staying up-to-date dramatically reduces these log spikes.”
Great points from both of you.
Now, for teams who can’t upgrade immediately or just want cleaner logs, you can silence this WebSocket noise without affecting anything important.
Option 1 - Switch HTTP client (reduces WebSocket spam)
Add this JVM flag:
Dwebdriver.http.factory=jdk-http-client
This uses Java’s built-in HTTP client instead of Selenium’s default Netty implementation, and it tends to produce fewer WebSocket warnings.