Fall back to download when Chrome refuses createWritable (Refs #20)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-23 21:49:07 -05:00
parent c480ff113a
commit 613f03993a
2 changed files with 14 additions and 4 deletions

View File

@@ -38,6 +38,7 @@ After sealing, `data/seed.json` is still plaintext. Delete it (and see
1. Open `final-wishes.html` from the drive, unlock, click **Edit**. 1. Open `final-wishes.html` from the drive, unlock, click **Edit**.
2. Change things, **Done editing**, **Save** (or Ctrl/Cmd+S). 2. Change things, **Done editing**, **Save** (or Ctrl/Cmd+S).
- Chrome/Edge: pick the drive file once; later saves overwrite silently. - Chrome/Edge: pick the drive file once; later saves overwrite silently.
- If Chrome refuses to write to the place you picked (a protected folder such as Downloads, Documents or your home folder), Save downloads the file instead and says so. Delete the empty file it left behind. Pick a subfolder you made, or the thumbdrive, to save in place.
- Firefox/Safari: a new `final-wishes.html` downloads. Copy it over the - Firefox/Safari: a new `final-wishes.html` downloads. Copy it over the
old one on the drive. old one on the drive.
- **Cancel** (next to Save, edit mode only) throws away the unsaved - **Cancel** (next to Save, edit mode only) throws away the unsaved

View File

@@ -703,10 +703,19 @@
if (!state.handle) { if (!state.handle) {
state.handle = await window.showSaveFilePicker({ suggestedName: 'final-wishes.html', types: [{ description: 'Final Wishes', accept: { 'text/html': ['.html'] } }] }); state.handle = await window.showSaveFilePicker({ suggestedName: 'final-wishes.html', types: [{ description: 'Final Wishes', accept: { 'text/html': ['.html'] } }] });
} }
const w = await state.handle.createWritable(); try {
await w.write(html); const w = await state.handle.createWritable();
await w.close(); await w.write(html);
state.status = 'Saved to ' + state.handle.name + '.'; await w.close();
state.status = 'Saved to ' + state.handle.name + '.';
} catch (e) {
if (!e || (e.name !== 'NotAllowedError' && e.name !== 'SecurityError')) throw e;
// Chrome created the (empty) file but refuses to write it, e.g. a protected folder.
// Forget the handle so the next Save asks again, and hand over a download instead.
state.handle = null;
downloadFile(html, 'final-wishes.html');
state.status = 'Chrome would not let this page write to the chosen location, so final-wishes.html was downloaded instead. Delete the empty file it left behind and replace your old copy with the download.';
}
state.dirty = false; state.dirty = false;
snapshot(); snapshot();
} else { } else {