]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
check for null local/session storage
authorRigel Kent <sendmemail@rigelk.eu>
Fri, 6 Nov 2020 16:42:08 +0000 (17:42 +0100)
committerRigel Kent <sendmemail@rigelk.eu>
Fri, 6 Nov 2020 16:42:25 +0000 (17:42 +0100)
fixes #3156

client/src/root-helpers/peertube-web-storage.ts

index 0db1301bd4fa4846b1e6d3096e0417d49849c527..f29845443ab8207be9a017f44fb0418284f67c71 100644 (file)
@@ -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