Compare commits
3 Commits
6048398c1e
...
52ce84c579
| Author | SHA1 | Date | |
|---|---|---|---|
| 52ce84c579 | |||
| 613f03993a | |||
| c480ff113a |
45
HANDOFF.md
Normal file
45
HANDOFF.md
Normal file
@@ -0,0 +1,45 @@
|
||||
# Handoff: issue #20 (save writes a 0-byte file)
|
||||
|
||||
Written 2026-11-23. Read `OVERVIEW.md` first for the app itself. This file covers only the open problem.
|
||||
|
||||
## The problem
|
||||
|
||||
Issue #20 (https://gitea.ericthered.tech/eric/final-wishes/issues/20), a follow-up to #19 (`?reset=1`).
|
||||
|
||||
After unlocking, adding `#reset=1` and erasing the secrets, the Save button (Chrome) creates a 0-byte file. The status line shows:
|
||||
|
||||
> Save failed: Failed to execute 'createWritable' on 'FileSystemFileHandle': The request is not allowed by the user agent or the platform in the current context.
|
||||
|
||||
## What is established
|
||||
|
||||
- It is **not** caused by reset. Save after reset uses the same `save()` path as any edit (`src/app.js`, `async function save`). The user has not yet tried a plain save without `#reset=1` on the SSD.
|
||||
- The picker succeeds and Chrome creates the empty file. Then `state.handle.createWritable()` throws `NotAllowedError`. Nothing is written.
|
||||
- Headless Chrome with a stubbed `showSaveFilePicker` (OPFS) wrote a full file, so assemble/encrypt is fine. A real picker can't be driven headless.
|
||||
- The user says **saving to a thumbdrive works fine**, while every SSD location tried fails. This contradicts the theory that Chrome blocks the `file://` site as a whole (`chrome://settings/content/filesystem`). Treat that theory as unlikely.
|
||||
|
||||
## What was changed (commit 613f039, not pushed)
|
||||
|
||||
`save()` now catches `NotAllowedError`/`SecurityError` on the write, clears `state.handle`, downloads `final-wishes.html` as a fallback and sets an explanatory status. `docs/MAINTENANCE.md` has a matching line. Tests pass (63 pass, 1 skipped). This is a workaround, not a diagnosis. Issue #20 is still open.
|
||||
|
||||
Also committed this session: `c480ff1` (OVERVIEW.md refresh for `?reset=1`). Neither commit is pushed.
|
||||
|
||||
## Open hypotheses (why the SSD fails and the thumbdrive works)
|
||||
|
||||
1. Overwriting an existing file (thumbdrive, probably) versus creating a new one (SSD).
|
||||
2. Real filesystem permissions: a folder the user doesn't own, or a read-only or odd mount. Chrome can report OS "permission denied" as this same `NotAllowedError`.
|
||||
3. Chrome's blocked-folder list on Linux (home folder itself, system or config folders).
|
||||
|
||||
## Next steps
|
||||
|
||||
1. Ask the user for the **exact SSD path** tried, and whether it was a new filename or an existing file. Check ownership and mount options (`ls -ld`, `findmnt`, `stat`).
|
||||
2. Have the user try a **new filename on the thumbdrive**. If that fails too, the problem is creating new files, not the location.
|
||||
3. Have the user try a plain save (no reset) on the SSD, and check the DevTools console.
|
||||
4. If the cause stays unclear, add a small diagnostic that shows the exact error name and `location.href` in the status line.
|
||||
5. Fallback the user may prefer: always download instead of saving in place. A download is Chrome writing the file, so it is allowed by default. The cost is that the old file is not overwritten.
|
||||
6. The user must **rebuild and carry their data across** to get the fallback. A saved file keeps the code it was saved with. Run `npm run build` (done, `dist/final-wishes.html`), then use "Open your existing Final Wishes file" on the start screen.
|
||||
|
||||
## Housekeeping
|
||||
|
||||
- Issue tooling: `gt` is not installed. Use `tea` (`tea issues create`, `tea comment N "..."`).
|
||||
- Scratch files from this session are in the session scratchpad: `d.json` (plaintext test data), `fw.html` and `t.mjs` (the CDP test script). Delete `d.json` when done. None are in the repo.
|
||||
- Close #20 only after the user confirms a real Chrome save works or the download fallback behaves.
|
||||
@@ -15,7 +15,7 @@ The owner keeps accounts, documents, contacts, wind-down steps and similar life-
|
||||
| Crypto | WebCrypto: PBKDF2-SHA256 (600,000 iterations) into AES-256-GCM |
|
||||
| Build | `build.js`: concatenates `src/*.js`, no bundler, no dependencies |
|
||||
| Tests | `node --test` (built-in runner). Browser behavior was checked by hand with headless Chromium over CDP, which is not part of the repo. |
|
||||
| Hosting / issues | Gitea (`gitea.ericthered.tech`), `gt` CLI. Issues #1–#18 track the work. |
|
||||
| Hosting / issues | Gitea (`gitea.ericthered.tech`), `gt` CLI. Issues #1–#19 track the work. |
|
||||
|
||||
There are no npm dependencies and no CDN or network calls at runtime.
|
||||
|
||||
@@ -30,7 +30,7 @@ src/
|
||||
crypto.js encrypt / decrypt / passphrase rules (blob format below)
|
||||
model.js document schema, validate(), section/record/field/sequence kinds
|
||||
ops.js pure edit helpers: add/move/remove, header, images, sequences, sub-tabs,
|
||||
revert-to-saved (Cancel), delete-section message
|
||||
revert-to-saved (Cancel), delete-section message, clearSecrets
|
||||
print.js pure print helpers: secret masking, header layout, frame rules, secret count
|
||||
images.js image helpers (PNG/JPEG sniffing, sizing, data URLs) + browser import pipeline
|
||||
template.js assemble(): the HTML skeleton shared by build.js and in-page Save
|
||||
@@ -65,6 +65,8 @@ A **visual sequence** (`kind: 'sequence'`, numbered `frames` of image + text wit
|
||||
- **Sub-tabs:** `ops.js` holds the pure logic (`tabsOf`, `entriesInTab`, `moveToTab`, `moveWithin`, `removeSubsection`, `printGroups`). The records stay in one array, and the tab bar filters them. The shown tab is in `state.tabs` (not saved). Up/down moves a record past its nearest neighbour in the same tab. Deleting a tab sends its records to General. Print writes one sub-heading per non-empty tab.
|
||||
- **Images:** drag and drop, clipboard paste and file picker all feed `importFiles()`. Files are sniffed by their first bytes, downscaled to at most 1600 px and re-encoded, which strips metadata, and stored as data URLs with a limit of about 3 MB each.
|
||||
|
||||
- **Reset (`?reset=1`):** opening the file with `?reset=1` or `#reset=1` shows a banner after unlock offering to erase every secret-flagged field value and secret frame (`clearSecrets()` in `ops.js`, count from `countSecrets`). Labels, structure and flags stay. It is read live (`resetRequested()`), with a `hashchange` listener to re-offer, and `state.resetOffered` dismisses it. Nothing is written until Save, so make a Backup copy first. It's meant for working on layout on a less safe machine.
|
||||
|
||||
**Save.** Uses the File System Access API (`showSaveFilePicker`, handle reused) where available, otherwise a Blob download. `assemble()` rebuilds the full HTML from the page's own CSS and JS plus a fresh encrypted payload. "Backup copy" downloads `final-wishes-YYYYMMDD.html`.
|
||||
|
||||
**Upgrading app code, keeping data.** A file runs the code it was saved with. On the start screen, "Open your existing Final Wishes file" extracts the `#payload` from an older `.html`, unlocks it with the passphrase, and Save then writes it out with the newer code.
|
||||
|
||||
@@ -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**.
|
||||
2. Change things, **Done editing**, **Save** (or Ctrl/Cmd+S).
|
||||
- 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
|
||||
old one on the drive.
|
||||
- **Cancel** (next to Save, edit mode only) throws away the unsaved
|
||||
|
||||
17
src/app.js
17
src/app.js
@@ -703,10 +703,19 @@
|
||||
if (!state.handle) {
|
||||
state.handle = await window.showSaveFilePicker({ suggestedName: 'final-wishes.html', types: [{ description: 'Final Wishes', accept: { 'text/html': ['.html'] } }] });
|
||||
}
|
||||
const w = await state.handle.createWritable();
|
||||
await w.write(html);
|
||||
await w.close();
|
||||
state.status = 'Saved to ' + state.handle.name + '.';
|
||||
try {
|
||||
const w = await state.handle.createWritable();
|
||||
await w.write(html);
|
||||
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;
|
||||
snapshot();
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user