From c388045c681129408954ffda7f347f05e486c322 Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Wed, 3 Dec 2025 13:59:55 +0500 Subject: [PATCH] web: fix file uploading not working in safari --- apps/web/src/interfaces/nncrypto.ts | 6 +++++- apps/web/src/utils/feature-check.ts | 22 +++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/apps/web/src/interfaces/nncrypto.ts b/apps/web/src/interfaces/nncrypto.ts index 924a81532..17e3a39c9 100644 --- a/apps/web/src/interfaces/nncrypto.ts +++ b/apps/web/src/interfaces/nncrypto.ts @@ -20,8 +20,12 @@ along with this program. If not, see . import { INNCrypto } from "@notesnook/crypto"; import CryptoWorker from "./nncrypto.worker?worker"; import { wrap } from "comlink"; +import { NNCrypto as NNCryptoSync } from "@notesnook/crypto"; +import { isTransferableStreamsSupported } from "../utils/feature-check"; -export const NNCrypto = wrap(new CryptoWorker()) as INNCrypto; +export const NNCrypto = isTransferableStreamsSupported() + ? (wrap(new CryptoWorker()) as INNCrypto) + : new NNCryptoSync(); // TODO: disable until we fix the `pull failed` errors for good. // IS_DESKTOP_APP && window.NativeNNCrypto // ? new window.NativeNNCrypto() diff --git a/apps/web/src/utils/feature-check.ts b/apps/web/src/utils/feature-check.ts index 821e10173..116413874 100644 --- a/apps/web/src/utils/feature-check.ts +++ b/apps/web/src/utils/feature-check.ts @@ -22,9 +22,28 @@ const FEATURE_CHECKS = { cache: false, indexedDB: false, clonableCryptoKey: false, - applePaySupported: false + applePaySupported: false, + transferableStreams: false }; +export function isTransferableStreamsSupported() { + try { + const readable = new ReadableStream({ + pull(controller) { + controller.enqueue(new Uint8Array([1, 2, 3])); + controller.close(); + } + }); + window.postMessage(readable, [readable]); + FEATURE_CHECKS.transferableStreams = true; + return true; + } catch { + console.log("Transferable streams not supported"); + FEATURE_CHECKS.transferableStreams = false; + return false; + } +} + async function isApplePaySupported() { try { FEATURE_CHECKS.applePaySupported = @@ -99,6 +118,7 @@ async function isCryptoKeyClonable() { export async function initializeFeatureChecks() { await Promise.allSettled([ + isTransferableStreamsSupported(), isOPFSSupported(), isCacheSupported(), isIndexedDBSupported(),