Version
1.57.0
Steps to reproduce
TODO a test repo
Steps to reproduce:
- Set up a WebSocket route handler using page.routeWebSocket()
- Have the WebSocket receive a message that triggers a page navigation/redirect
- The redirect closes the page while the WebSocket handler is still processing
Expected behavior
The WebSocket connection should close gracefully when the page redirects, without throwing exceptions.
Actual behavior
Actual behavior:
A NullPointerException is thrown in WebSocketRouteImpl.java at int code = params.get("code").getAsInt(); because code and reason are null when the connection is closed due to page navigation.
Additional context
Analysis:
The JavaScript implementation doesn't send this data:
https://github.com/microsoft/playwright/blob/main/packages/playwright-core/src/server/dispatchers/webSocketRouteDispatcher.ts#L93
The Java implementation doesn't have null guards:
https://github.com/microsoft/playwright-java/blob/main/playwright/src/main/java/com/microsoft/playwright/impl/WebSocketRouteImpl.java#L163-L165
Suggested fix:
Add null checks or default values for code and reason in the close handler.
Environment
- We use the docker image
- OS: Linux
- Java 21
- All browsers