mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
chore: log when websockets are proactively closed (#23689)
Closes https://github.com/microsoft/playwright/issues/23566 n.b., while that issue describes a fairly specific "use case", this logging is simple and generic. It seems very plausible that it can help diagnose all sorts of issues. Cheers - V
This commit is contained in:
parent
0f9f863183
commit
380209af37
@ -125,10 +125,20 @@ export class WebSocketTransport implements ConnectionTransport {
|
|||||||
|
|
||||||
this._ws.addEventListener('message', event => {
|
this._ws.addEventListener('message', event => {
|
||||||
messageWrap(() => {
|
messageWrap(() => {
|
||||||
|
const eventData = event.data as string;
|
||||||
|
let parsedJson;
|
||||||
|
try {
|
||||||
|
parsedJson = JSON.parse(eventData);
|
||||||
|
} catch (e) {
|
||||||
|
this._progress?.log(`<closing ws> Closing websocket due to malformed JSON. eventData=${eventData} e=${e?.message}`);
|
||||||
|
this._ws.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
if (this.onmessage)
|
if (this.onmessage)
|
||||||
this.onmessage.call(null, JSON.parse(event.data as string));
|
this.onmessage.call(null, parsedJson);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
this._progress?.log(`<closing ws> Closing websocket due to failed onmessage callback. eventData=${eventData} e=${e?.message}`);
|
||||||
this._ws.close();
|
this._ws.close();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user