]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Fix local/session storage polyfill
authorChocobozzz <me@florianbigard.com>
Fri, 8 Oct 2021 09:57:39 +0000 (11:57 +0200)
committerChocobozzz <me@florianbigard.com>
Mon, 11 Oct 2021 07:37:26 +0000 (09:37 +0200)
client/src/root-helpers/peertube-web-storage.ts
client/src/standalone/videos/test-embed.ts

index 68a2462de04837d5fa14ec080daa8397d4e5b87f..0bbe2c9fc8fac423771276006a8b1fd17f9c93ad 100644 (file)
@@ -6,19 +6,17 @@ function proxify (instance: MemoryStorage) {
   return new Proxy(instance, {
     set: function (obj, prop: string | symbol, value) {
       if (Object.prototype.hasOwnProperty.call(MemoryStorage, prop)) {
-        // FIXME: symbol typing issue https://github.com/microsoft/TypeScript/issues/1863
-        instance[prop as any] = value
+        instance[prop] = value
       } else {
         instance.setItem(prop, value)
       }
+
       return true
     },
     get: function (target, name: string | symbol | number) {
-      if (Object.prototype.hasOwnProperty.call(MemoryStorage, name)) {
-        // FIXME: symbol typing issue https://github.com/microsoft/TypeScript/issues/1863
-        return instance[name as any]
-      }
-      if (valuesMap.has(name)) {
+      if (typeof instance[name] === 'function') {
+        return instance[name]
+      } else if (valuesMap.has(name)) {
         return instance.getItem(name)
       }
     }
@@ -26,7 +24,7 @@ function proxify (instance: MemoryStorage) {
 }
 
 class MemoryStorage implements Storage {
-  [key: string]: any
+  [key: string | symbol]: any
 
   getItem (key: any) {
     const stringKey = String(key)
@@ -83,7 +81,7 @@ try {
 }
 
 // support Brave and other browsers using null rather than an exception
-if (peertubeLocalStorage === null || peertubeSessionStorage === null) {
+if (!peertubeLocalStorage || !peertubeSessionStorage) {
   reinitStorage()
 }
 
index 301c95d7b56b1dd2347a6a8fcf762de33ace9517..a28a83cc15015ff378d372dec969e56c256272da 100644 (file)
@@ -15,6 +15,8 @@ window.addEventListener('load', async () => {
     ? `/video-playlists/embed/${elementId}?api=1`
     : `/videos/embed/${elementId}?api=1`
 
+  iframe.sandbox.add('allow-same-origin', 'allow-scripts', 'allow-popups')
+
   const mainElement = document.querySelector('#host')
   mainElement.appendChild(iframe)