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