From: Rigel Kent Date: Fri, 6 Nov 2020 16:42:08 +0000 (+0100) Subject: check for null local/session storage X-Git-Tag: v3.0.0-rc.1~435 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=61379e431115ab9d7c200852afcccf6ab94064d5;hp=a5c9fa1051c9b658ddc0bf6bd9e7979364316c91;p=github%2FChocobozzz%2FPeerTube.git check for null local/session storage fixes #3156 --- diff --git a/client/src/root-helpers/peertube-web-storage.ts b/client/src/root-helpers/peertube-web-storage.ts index 0db1301bd..f29845443 100644 --- a/client/src/root-helpers/peertube-web-storage.ts +++ b/client/src/root-helpers/peertube-web-storage.ts @@ -64,10 +64,8 @@ class MemoryStorage { let peertubeLocalStorage: Storage let peertubeSessionStorage: Storage -try { - peertubeLocalStorage = localStorage - peertubeSessionStorage = sessionStorage -} catch (err) { + +function reinitStorage () { const instanceLocalStorage = new MemoryStorage() const instanceSessionStorage = new MemoryStorage() @@ -75,6 +73,19 @@ try { peertubeSessionStorage = proxify(instanceSessionStorage) } +try { + peertubeLocalStorage = localStorage + peertubeSessionStorage = sessionStorage +} catch (err) { + // support Firefox and other browsers using an exception rather than null + reinitStorage() +} + +// support Brave and other browsers using null rather than an exception +if (peertubeLocalStorage === null || peertubeSessionStorage === null) { + reinitStorage() +} + export { peertubeLocalStorage, peertubeSessionStorage