From 36f63c87b89f0a285ee6321657b285e5ae73b415 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Wed, 18 Aug 2021 13:30:42 +0300 Subject: [PATCH] Fix loading when localStorage is not available --- apps/common/main/lib/util/htmlutils.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/apps/common/main/lib/util/htmlutils.js b/apps/common/main/lib/util/htmlutils.js index ab885cfaf..5b511ce8f 100644 --- a/apps/common/main/lib/util/htmlutils.js +++ b/apps/common/main/lib/util/htmlutils.js @@ -42,7 +42,17 @@ var params = (function() { return urlParams; })(); -if ( !!params.uitheme && !localStorage.getItem("ui-theme-id") ) { +var checkLocalStorage = (function () { + try { + var storage = window['localStorage']; + return true; + } + catch(e) { + return false; + } +})(); + +if ( !!params.uitheme && checkLocalStorage && !localStorage.getItem("ui-theme-id") ) { // const _t = params.uitheme.match(/([\w-]+)/g); if ( params.uitheme == 'default-dark' ) @@ -54,11 +64,11 @@ if ( !!params.uitheme && !localStorage.getItem("ui-theme-id") ) { localStorage.setItem("ui-theme-id", params.uitheme); } -var ui_theme_name = localStorage.getItem("ui-theme-id"); +var ui_theme_name = checkLocalStorage ? localStorage.getItem("ui-theme-id") : undefined; if ( !ui_theme_name ) { if ( window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ) { ui_theme_name = 'theme-dark'; - localStorage.setItem("ui-theme-id", ui_theme_name); + checkLocalStorage && localStorage.setItem("ui-theme-id", ui_theme_name); } } if ( !!ui_theme_name ) {