From d72b26df790875ffede17273ef0b62c0e2fb543a Mon Sep 17 00:00:00 2001 From: borre Date: Mon, 26 Jun 2023 10:37:09 +0900 Subject: [PATCH] fix: fix error when accessing window.localStorage --- .../src/browser/lib/localStorage.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/misc/keyvaluestorage/src/browser/lib/localStorage.js b/misc/keyvaluestorage/src/browser/lib/localStorage.js index e8a5ddd0..fbba62f6 100644 --- a/misc/keyvaluestorage/src/browser/lib/localStorage.js +++ b/misc/keyvaluestorage/src/browser/lib/localStorage.js @@ -44,11 +44,16 @@ return Object.keys(this).length; }); - if (typeof global !== "undefined" && global.localStorage) { - module.exports = global.localStorage; - } else if (typeof window !== "undefined" && window.localStorage) { - module.exports = window.localStorage; - } else { + try { + if (typeof global !== "undefined" && global.localStorage) { + module.exports = global.localStorage; + } else if (typeof window !== "undefined" && window.localStorage) { + module.exports = window.localStorage; + } else { + module.exports = new LocalStorage(); + } + } catch { + // In Incognito mode, accessing window.localStorage may thorw an error module.exports = new LocalStorage(); } })();