diff --git a/src/client/Main.ts b/src/client/Main.ts index 88fe223f4..98414eca7 100644 --- a/src/client/Main.ts +++ b/src/client/Main.ts @@ -868,6 +868,12 @@ class Client { this.gameStop(); this.gameStop = null; + try { + history.replaceState(null, "", "/"); + } catch (e) { + console.warn("Failed to restore URL on leave:", e); + } + document.body.classList.remove("in-game"); crazyGamesSDK.gameplayStop(); diff --git a/src/client/Transport.ts b/src/client/Transport.ts index 1f35131a4..d370c6ba8 100644 --- a/src/client/Transport.ts +++ b/src/client/Transport.ts @@ -725,10 +725,18 @@ export class Transport { this.socket.onclose = null; this.socket.onerror = null; - // Close the connection if it's still open - if (this.socket.readyState === WebSocket.OPEN) { - this.socket.close(); + // Close the connection if it's still open or still connecting + try { + if ( + this.socket.readyState === WebSocket.OPEN || + this.socket.readyState === WebSocket.CONNECTING + ) { + this.socket.close(); + } + } catch (e) { + console.warn("Error while closing WebSocket:", e); } + this.socket = null; } }