From 39dedc68ec15b65c9cb3747dd49d9c0da8de80bf Mon Sep 17 00:00:00 2001 From: Zhihe Li Date: Wed, 10 Sep 2025 11:35:02 -0400 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Add=20better=20check=20fo?= =?UTF-8?q?r=20determining=20if=20we=20can=20use=20OPFS=20(#2996)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/api/addon/workers/sqlite-worker.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/addons/api/addon/workers/sqlite-worker.js b/addons/api/addon/workers/sqlite-worker.js index 4eaa2ad36..e64294460 100644 --- a/addons/api/addon/workers/sqlite-worker.js +++ b/addons/api/addon/workers/sqlite-worker.js @@ -27,7 +27,18 @@ const { promise: ready, resolve: readyResolve } = Promise.withResolvers(); // https://www.sqlite.org/limits.html const MAX_HOST_PARAMETERS = 32766; const SCHEMA_VERSION = 1; -const isSecure = self.isSecureContext; + +// Some browsers do not allow calling getDirectory in private browsing modes even +// if we're in a secure context. This will cause the SQLite setup to fail so we should +// check ahead of time to see if we're able to call the API. +let canCallGetDirectory; +try { + canCallGetDirectory = Boolean(await navigator.storage.getDirectory()); +} catch { + canCallGetDirectory = false; +} + +const isSecure = self.isSecureContext && canCallGetDirectory; // Error code for sqlite corruption errors. // See https://sqlite.org/rescode.html#corrupt