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:
vemv 2023-06-19 20:12:02 +02:00 коммит произвёл GitHub
Родитель 0f9f863183
Коммит 380209af37
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 11 добавлений и 1 удалений

Просмотреть файл

@ -125,10 +125,20 @@ export class WebSocketTransport implements ConnectionTransport {
this._ws.addEventListener('message', event => {
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 {
if (this.onmessage)
this.onmessage.call(null, JSON.parse(event.data as string));
this.onmessage.call(null, parsedJson);
} catch (e) {
this._progress?.log(`<closing ws> Closing websocket due to failed onmessage callback. eventData=${eventData} e=${e?.message}`);
this._ws.close();
}
});