From 6b02b73b9ba1d7896f98610cdbc59b69012a013e Mon Sep 17 00:00:00 2001 From: Christian Lawson-Perfect Date: Mon, 10 Feb 2025 11:56:37 +0000 Subject: [PATCH] Deal with errors using OPFS In private mode, storage.getDirectory gives a security error. Any errors using OPFS are now silently ignored. --- load-app.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/load-app.js b/load-app.js index 899f73a..09a71e0 100644 --- a/load-app.js +++ b/load-app.js @@ -132,7 +132,12 @@ class LeafletElement extends HTMLElement { } customElements.define('leaflet-map', LeafletElement); -let opfs = await navigator.storage.getDirectory(); +let opfs; +try { + opfs = await navigator.storage.getDirectory(); +} catch(e) { + +} async function init_app() { const compilation_error = await show_error; @@ -180,10 +185,14 @@ async function init_app() { const send_value_handlers = { save: async ({markers}) => { - const f = await opfs.getFileHandle(`markers-${map_id}.json`, {create:true}); - const w = await f.createWritable(); - await w.write(JSON.stringify(markers)); - await w.close(); + try { + const f = await opfs.getFileHandle(`markers-${map_id}.json`, {create:true}); + const w = await f.createWritable(); + await w.write(JSON.stringify(markers)); + await w.close(); + } catch(e) { + + } const fd = new FormData(); fd.set('content', JSON.stringify(markers));