Skip to content

Latest commit

 

History

History
65 lines (51 loc) · 3.29 KB

File metadata and controls

65 lines (51 loc) · 3.29 KB

Playwright Java WebSocket Bug Reproduction

Reproduction case for microsoft/playwright-java#1882.

The Bug

A NullPointerException occurs in WebSocket routing when a connection closes due to page navigation. The code and reason parameters passed to onClose are null, but the Java implementation doesn't handle this case.

Setup

Requires Nix with flakes support.

mvn test

Project Structure

├── shell.nix           # Nix shell with JDK 21, Maven, Playwright browsers
├── pom.xml             # Maven config with Playwright 1.50.0
└── src/test/java/com/example/
    └── WebSocketBugTest.java

Expected Behavior

The onClose handler should gracefully handle null code and reason values.

Actual Behavior

java.lang.NullPointerException: Cannot invoke "com.google.gson.JsonElement.getAsInt()" because the return value of "com.google.gson.JsonObject.get(String)" is null

	at com.microsoft.playwright.impl.WebSocketRouteImpl.handleEvent(WebSocketRouteImpl.java:160)
	at com.microsoft.playwright.impl.Connection.dispatch(Connection.java:292)
	at com.microsoft.playwright.impl.Connection.processOneMessage(Connection.java:211)
	at com.microsoft.playwright.impl.ChannelOwner.runUntil(ChannelOwner.java:130)
	at com.microsoft.playwright.impl.FrameImpl.waitForNavigationImpl(FrameImpl.java:1041)
	at com.microsoft.playwright.impl.FrameImpl.waitForURLImpl(FrameImpl.java:1110)
	at com.microsoft.playwright.impl.PageImpl.lambda$waitForURL$98(PageImpl.java:1624)
	at com.microsoft.playwright.impl.WaitForEventLogger.lambda$get$0(WaitForEventLogger.java:50)
	at com.microsoft.playwright.impl.LoggingSupport.withLogging(LoggingSupport.java:47)
	at com.microsoft.playwright.impl.ChannelOwner.withLogging(ChannelOwner.java:97)
	at com.microsoft.playwright.impl.WaitForEventLogger.get(WaitForEventLogger.java:41)
	at com.microsoft.playwright.impl.ChannelOwner.withWaitLogging(ChannelOwner.java:87)
	at com.microsoft.playwright.impl.PageImpl.waitForURL(PageImpl.java:1623)
	at com.microsoft.playwright.impl.PageImpl.waitForURL(PageImpl.java:1609)
	at com.example.WebSocketBugTest.testWebSocketRouteCloseOnNavigation(WebSocketBugTest.java:93)
	at java.base/java.lang.reflect.Method.invoke(Method.java:565)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1604)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1604)
	Suppressed: java.lang.NullPointerException: Cannot invoke "com.google.gson.JsonElement.getAsInt()" because the return value of "com.google.gson.JsonObject.get(String)" is null
		at com.microsoft.playwright.impl.WebSocketRouteImpl.handleEvent(WebSocketRouteImpl.java:173)
		at com.microsoft.playwright.impl.Connection.dispatch(Connection.java:292)
		at com.microsoft.playwright.impl.Connection.processOneMessage(Connection.java:211)
		at com.microsoft.playwright.impl.ChannelOwner.runUntil(ChannelOwner.java:130)
		at com.microsoft.playwright.impl.Connection.sendMessage(Connection.java:130)
		at com.microsoft.playwright.impl.ChannelOwner.sendMessage(ChannelOwner.java:118)
		at com.microsoft.playwright.impl.TracingImpl.stopChunkImpl(TracingImpl.java:59)
		at com.microsoft.playwright.impl.TracingImpl.stop(TracingImpl.java:144)
		at com.example.WebSocketBugTest.closeContext(WebSocketBugTest.java:47)
		... 3 more