From cb8cf631932cb4fd249d600ae0b5200208cbde8f Mon Sep 17 00:00:00 2001 From: Peter Hedenskog Date: Thu, 22 Jun 2023 09:03:32 +0200 Subject: [PATCH] Catch id local and session storage is not accessible (#101) * Catch id local and session storage is not accessible * fix --- lib/dom/info/localStorageSize.js | 7 +++++-- lib/dom/info/sessionStorageSize.js | 6 +++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/dom/info/localStorageSize.js b/lib/dom/info/localStorageSize.js index 379a4df..dffa888 100644 --- a/lib/dom/info/localStorageSize.js +++ b/lib/dom/info/localStorageSize.js @@ -17,6 +17,9 @@ return 0; } } - - return storageSize(window.localStorage); + try { + return storageSize(window.localStorage); + } catch (error) { + return 'Could not access localStorage.'; + } })(); diff --git a/lib/dom/info/sessionStorageSize.js b/lib/dom/info/sessionStorageSize.js index 42b732c..b42eb5a 100644 --- a/lib/dom/info/sessionStorageSize.js +++ b/lib/dom/info/sessionStorageSize.js @@ -13,5 +13,9 @@ return bytes; } - return storageSize(window.sessionStorage); + try { + return storageSize(window.sessionStorage); + } catch (error) { + return 'Could not access sessionStorage'; + } })();