From fd7dc2e2346efd98a986f022f3d5f547ee173c6e Mon Sep 17 00:00:00 2001 From: "Robert (Jamie) Munro" Date: Wed, 19 Mar 2025 11:07:40 +0000 Subject: [PATCH 1/2] =?UTF-8?q?Safari=20doesn=E2=80=99t=20support=20OPFS?= =?UTF-8?q?=20createWritable=20method?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit So we have to use a Synchronous write method, which is only available if we are running in a web worker. Put a warning to console if we are not, and don’t leave behind an empty file. --- src/opfs.ts | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/opfs.ts b/src/opfs.ts index 2bb73b6..884ffe9 100644 --- a/src/opfs.ts +++ b/src/opfs.ts @@ -9,9 +9,25 @@ export async function writeBlob(url: string, blob: Blob): Promise { const path = url.split('/').at(-1)!; const file = await dir.getFileHandle(path, { create: true }); - const writable = await file.createWritable(); - await writable.write(blob); - await writable.close(); + if (file.createWritable) { + const writable = await file.createWritable(); + await writable.write(blob); + await writable.close(); + } else if (self.WorkerGlobalScope) { + console.log( + 'createWritable not supported, trying syncronous API with createSyncAccessHandle as we are a worker', + ); + // use the synchronous write API to write to the file. Only works in web workers + const writer = await file.createSyncAccessHandle(); + writer.write(await blob.arrayBuffer()); + writer.close(); + } else { + console.error( + "Cannot write to OPFS file using createWritable and we are not a worker, so can't use createSyncAccessHandle", + ); + // Remove the empty file + await dir.removeEntry(path); + } } catch (e) { console.error(e); } From 0d8f92a6a279bd5f98e49d650df1e96625ba7588 Mon Sep 17 00:00:00 2001 From: "Robert (Jamie) Munro" Date: Wed, 19 Mar 2025 11:25:37 +0000 Subject: [PATCH 2/2] Add a prepare script for use directly from GitHub This means you can use a line in package.json like: "@diffusionstudio/vits-web": "git@github.com: diffusionstudio/vits-web.git#[SHA]", to test a specific SHA version in another project before it's released. --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 6914a5a..91d45e3 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "scripts": { "dev": "vite", "build": "rm -r -f ./dist && tsc && vite build", + "prepare": "npm run build", "preview": "vite preview", "format": "npx @biomejs/biome format --write ./src", "test": "npx playwright test --project=chromium"