Files
final-wishes/HANDOFF.md
2026-11-24 07:53:30 -05:00

47 lines
4.6 KiB
Markdown

# Handoff: issue #20 (save writes a 0-byte file)
Written 2026-11-23, updated 2026-11-24. 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, pushed)
`save()` now catches `NotAllowedError`/`SecurityError` on the write, clears `state.handle`, downloads `final-wishes.html` as a fallback and sets an explanatory status. `README.md` (the owner's guide) 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`). Both are pushed to origin/master, along with the first version of this file (52ce84c).
## Findings since (the app is not at fault)
- Tried `~/Documents/final-wishes.html`: still a 0-byte file and the same error.
- A bare test page with no app code (a button calling `showSaveFilePicker`, then `createWritable`/`write`/`close`) **fails the same way on both `http://localhost` and `file://`**, even for a tiny text file. So Chrome or the desktop refuses the write; Final Wishes is not involved. (The test page lived in the session scratchpad and is gone; it is about 20 lines to rebuild.)
- Ruled out on this machine: file ownership and mounts (`~`, `~/Documents`, `~/Downloads` and the project folder are all owned by the user and writable; root is read-write ext4; no external drive was mounted), Chrome snap/flatpak sandboxing (it is the normal `.deb`, `/opt/google/chrome`, v157), enterprise policy (`/etc/opt/chrome/policies` does not exist), and stored Chrome settings (`file_system_write_guard` and `file_system_read_guard` are empty in both profiles).
- Unusual: the desktop is **COSMIC on Wayland**, and the save dialog goes through the COSMIC and GTK xdg-desktop-portal services. Best guess, **unconfirmed**: the portal-based dialog hands Chrome a file it will not let the page write to.
- Still unexplained: the user says saving to a thumbdrive works. It has not been checked how (same dialog? overwriting an existing file?) and no drive was mounted when checked.
## Decision pending (the user is thinking it over)
1. **Make download the default save.** Chrome writes the file itself, which works here. Cost: no silent overwrite, so the user replaces the old copy by hand. Chrome's "Ask where to save each file" (`chrome://settings/downloads`) lets them choose the SSD folder. Keep save-in-place only as an opt-in, so a failed in-place save does not leave a stray 0-byte file.
2. Keep the current behaviour: try in place, and on `NotAllowedError` fall back to a download (already shipped in 613f039). Cost: each failed save leaves an empty file behind.
3. Investigate more first: another browser (Firefox and Safari already use the download path), and repeat the test page on the thumbdrive with a new filename and with an existing file.
If option 1 is chosen: change `save()` in `src/app.js`, update `README.md` (the Chrome/Edge bullet in "Updating" and the "Backups" wording), update `OVERVIEW.md` (the Save paragraph), and add a test only if the logic can be isolated. Then close #20.
## 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.