web/storage: make opfs check more robust

This commit is contained in:
jj 2025-04-30 17:18:25 +00:00
parent 893c6edde7
commit 1058014c96
No known key found for this signature in database

View File

@ -44,7 +44,10 @@ export class OPFSStorage {
}
static isAvailable() {
return !!navigator.storage?.getDirectory;
if (typeof navigator === 'undefined')
return false;
return 'storage' in navigator && 'getDirectory' in navigator.storage;
}
}
@ -55,7 +58,7 @@ export const removeFromFileStorage = async (filename: string) => {
}
export const clearFileStorage = async () => {
if (navigator.storage.getDirectory) {
if (OPFSStorage.isAvailable()) {
const root = await navigator.storage.getDirectory();
try {
await root.removeEntry(COBALT_PROCESSING_DIR, { recursive: true });