Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(wk websocket): do not send messages to a closing websocket (#593)

Dmitry Gozman24f5f1f95239
diff --git a/src/server/wkPlaywright.ts b/src/server/wkPlaywright.ts
index 598840cddc..44166a9f6b 100644
--- a/src/server/wkPlaywright.ts
+++ b/src/server/wkPlaywright.ts
@@ -283,7 +283,12 @@ function wrapTransportWithWebSocket(transport: ConnectionTransport) {
}
socket = s;
s.on('message', message => transport.send(Buffer.from(message).toString()));
- transport.onmessage = message => s.send(message);
+ transport.onmessage = message => {
+ // We are not notified when socket starts closing, and sending messages to a closing
+ // socket throws an error.
+ if (s.readyState !== ws.CLOSING)
+ s.send(message);
+ };
s.on('close', () => {
socket = undefined;
transport.onmessage = undefined;