From c1488fa3532f312c351f5ba41a0a53232fc59187 Mon Sep 17 00:00:00 2001 From: David Luzar Date: Fri, 17 Jul 2020 18:39:23 +0200 Subject: [PATCH] try/catch localStorage access (#1932) --- src/components/App.tsx | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/components/App.tsx b/src/components/App.tsx index 870ab0d5..5c8c0df8 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -417,9 +417,14 @@ class App extends React.Component { if (!roomMatch) { return false; } - const collabForceLoadFlag = localStorage.getItem( - LOCAL_STORAGE_KEY_COLLAB_FORCE_FLAG, - ); + + let collabForceLoadFlag; + try { + collabForceLoadFlag = localStorage?.getItem( + LOCAL_STORAGE_KEY_COLLAB_FORCE_FLAG, + ); + } catch {} + if (collabForceLoadFlag) { try { const { @@ -619,13 +624,15 @@ class App extends React.Component { private beforeUnload = withBatchedUpdates((event: BeforeUnloadEvent) => { if (this.state.isCollaborating && this.portal.roomID) { - localStorage.setItem( - LOCAL_STORAGE_KEY_COLLAB_FORCE_FLAG, - JSON.stringify({ - timestamp: Date.now(), - room: this.portal.roomID, - }), - ); + try { + localStorage?.setItem( + LOCAL_STORAGE_KEY_COLLAB_FORCE_FLAG, + JSON.stringify({ + timestamp: Date.now(), + room: this.portal.roomID, + }), + ); + } catch {} } if ( this.state.isCollaborating &&