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
11
load-app.js
11
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}) => {
|
||||
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));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue