From d713c82568a096bc384d2d4f4e5f46fe662f4612 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Thu, 6 Jan 2022 11:46:07 +0100 Subject: [PATCH] Fixing WA crashing in Firefox private mode Due to the way we now handle the browser cache, previously ignored errors in the Cache API were now explicitly thrown, preventing the loading of Firefox in private mode. This commit fixes the issue and improves the stacktrace display of errors at the same time. --- front/src/Connexion/ConnectionManager.ts | 3 +++ front/src/Connexion/LocalUserStore.ts | 10 +++++++--- front/src/Phaser/Reconnecting/ErrorScene.ts | 3 +++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/front/src/Connexion/ConnectionManager.ts b/front/src/Connexion/ConnectionManager.ts index 9c81fb25..5fe3d029 100644 --- a/front/src/Connexion/ConnectionManager.ts +++ b/front/src/Connexion/ConnectionManager.ts @@ -168,6 +168,9 @@ class ConnectionManager { } } catch (err) { console.error(err); + if (err instanceof Error) { + console.error(err.stack); + } } } else { const query = urlParams.toString(); diff --git a/front/src/Connexion/LocalUserStore.ts b/front/src/Connexion/LocalUserStore.ts index cc84f043..24d4ab42 100644 --- a/front/src/Connexion/LocalUserStore.ts +++ b/front/src/Connexion/LocalUserStore.ts @@ -139,9 +139,13 @@ class LocalUserStore { async setLastRoomUrl(roomUrl: string): Promise { localStorage.setItem(lastRoomUrl, roomUrl.toString()); if ("caches" in window) { - const cache = await caches.open(cacheAPIIndex); - const stringResponse = new Response(JSON.stringify({ roomUrl })); - await cache.put(`/${lastRoomUrl}`, stringResponse); + try { + const cache = await caches.open(cacheAPIIndex); + const stringResponse = new Response(JSON.stringify({ roomUrl })); + await cache.put(`/${lastRoomUrl}`, stringResponse); + } catch (e) { + console.error("Could not store last room url in Browser cache. Are you using private browser mode?", e); + } } } getLastRoomUrl(): string { diff --git a/front/src/Phaser/Reconnecting/ErrorScene.ts b/front/src/Phaser/Reconnecting/ErrorScene.ts index 078bee71..ea593c45 100644 --- a/front/src/Phaser/Reconnecting/ErrorScene.ts +++ b/front/src/Phaser/Reconnecting/ErrorScene.ts @@ -78,6 +78,9 @@ export class ErrorScene extends Phaser.Scene { */ public static showError(error: unknown, scene: ScenePlugin): void { console.error(error); + if (error instanceof Error) { + console.error("Stacktrace: ", error.stack); + } console.trace(); if (typeof error === "string" || error instanceof String) {