From 7b62535c39bebc2a7cfb5ce7b09cfb02a1c77ac2 Mon Sep 17 00:00:00 2001 From: Lars Johansson Date: Mon, 25 Sep 2023 16:34:05 +0200 Subject: [PATCH] fix: undefined window throwing error on websocket close --- source/simple_socketio.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/simple_socketio.ts b/source/simple_socketio.ts index 939ce17..430514a 100644 --- a/source/simple_socketio.ts +++ b/source/simple_socketio.ts @@ -250,7 +250,7 @@ export default class SimpleSocketIOClient { this.reconnecting = false; this.webSocket?.close(); this.webSocket = undefined; - if (window?.addEventListener) { + if (typeof window === "object" && window.addEventListener) { window.addEventListener("online", this.attemptReconnect.bind(this), { once: true, });