Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

check for null local/session storage

Rigel Kent61379e431115
diff --git a/client/src/root-helpers/peertube-web-storage.ts b/client/src/root-helpers/peertube-web-storage.ts
index 0db1301bd4..f29845443a 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