fix: reinit player safely

This commit is contained in:
2026-05-26 22:20:26 +02:00
parent 6da80df655
commit 30441c3e1f
8 changed files with 96 additions and 30 deletions

40
static/player/storage.ts Normal file
View File

@@ -0,0 +1,40 @@
export type StorageLike = Pick<Storage, 'getItem' | 'setItem' | 'removeItem'>;
const getLocalStorage = (): StorageLike | null => {
try {
return window.localStorage;
} catch {
return null;
}
};
export const safeLocalStorage = {
getItem(key: string): string | null {
const storage = getLocalStorage();
if (!storage) return null;
try {
return storage.getItem(key);
} catch {
return null;
}
},
setItem(key: string, value: string): void {
const storage = getLocalStorage();
if (!storage) return;
try {
storage.setItem(key, value);
} catch {
// ignore
}
},
removeItem(key: string): void {
const storage = getLocalStorage();
if (!storage) return;
try {
storage.removeItem(key);
} catch {
// ignore
}
},
};