Deal with errors using OPFS
In private mode, storage.getDirectory gives a security error. Any errors using OPFS are now silently ignored.
This commit is contained in:
parent
fe963ec2db
commit
6b02b73b9b
1 changed files with 14 additions and 5 deletions
19
load-app.js
19
load-app.js
|
@ -132,7 +132,12 @@ class LeafletElement extends HTMLElement {
|
||||||
}
|
}
|
||||||
customElements.define('leaflet-map', LeafletElement);
|
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() {
|
async function init_app() {
|
||||||
const compilation_error = await show_error;
|
const compilation_error = await show_error;
|
||||||
|
@ -180,10 +185,14 @@ async function init_app() {
|
||||||
|
|
||||||
const send_value_handlers = {
|
const send_value_handlers = {
|
||||||
save: async ({markers}) => {
|
save: async ({markers}) => {
|
||||||
const f = await opfs.getFileHandle(`markers-${map_id}.json`, {create:true});
|
try {
|
||||||
const w = await f.createWritable();
|
const f = await opfs.getFileHandle(`markers-${map_id}.json`, {create:true});
|
||||||
await w.write(JSON.stringify(markers));
|
const w = await f.createWritable();
|
||||||
await w.close();
|
await w.write(JSON.stringify(markers));
|
||||||
|
await w.close();
|
||||||
|
} catch(e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
const fd = new FormData();
|
const fd = new FormData();
|
||||||
fd.set('content', JSON.stringify(markers));
|
fd.set('content', JSON.stringify(markers));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue