Skip to content

web: fall back to Blob download without showSaveFilePicker and survive picker cancel - #206

Merged
bradfitz merged 1 commit into
tailscale:mainfrom
mlubbad:fix/web-save-fallback-and-bidi
Dec 2, 2026
Merged

bradfitz merged 1 commit into
tailscale:mainfrom
mlubbad:fix/web-save-fallback-and-bidi

Conversation

@mlubbad

@mlubbad mlubbad commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Problem

In the web/ WebAssembly app (https://tailscale.github.io/tailcat/), clicking Save incoming file… unconditionally called showSaveFilePicker(), causing two issues:

  1. Safari (macOS & iOS) and Firefox compatibility: Neither Safari nor Firefox implements the WICG File System Access showSaveFilePicker API. Clicking Save incoming file… threw ReferenceError: showSaveFilePicker is not defined, entered catch (err), closed conn, left both buttons permanently disabled, and lost the incoming stream.
  2. Save-dialog cancel (AbortError) before reading: On Chromium browsers, showSaveFilePicker() runs before conn.read() pulls any bytes (while the sender stalls on TCP backpressure). Dismissing/canceling the file picker threw AbortError, which closed conn and kept both buttons disabled instead of letting the user retry Save incoming file… or choose Show as text.
  3. RTL text direction: #send-text and .recv-text rendered right-to-left scripts (Arabic, Hebrew, etc.) forced left-to-right without dir="auto".

Changes

  • web/app.js:
    • When typeof globalThis.showSaveFilePicker === "function", catch AbortError from showSaveFilePicker() before conn.read() starts, re-enable the action buttons, and leave conn intact.
    • When showSaveFilePicker is unavailable (Safari, Firefox), read the incoming stream into a Blob and trigger a temporary <a download="tailcat-download"> object URL.
    • Set box.dir = "auto" on .recv-text.
  • web/index.html: Add dir="auto" to <textarea id="send-text">.
  • web/wasm_test.go: Add TestBrowserSaveFileCancelAndFallback verifying both AbortError recovery and the Blob fallback SHA-256 integrity end-to-end over a local DERP relay.

Verification

  • GOOS=js GOARCH=wasm go build ./web
  • go test ./web/ -v -count=1 -timeout 300s --run-headless-browser-tests (5/5 passing, including TestBrowserSaveFileCancelAndFallback)
  • go vet ./... and make tidy clean

…e picker cancel

Clicking "Save incoming file…" in the browser app unconditionally called
showSaveFilePicker, which caused two issues:

1. Safari (macOS/iOS) and Firefox do not implement showSaveFilePicker,
   so clicking "Save incoming file…" threw ReferenceError, closed conn,
   left both action buttons disabled, and lost the incoming transfer.
   Fall back to buffering the stream into a Blob and triggering an
   <a download="tailcat-download"> when showSaveFilePicker is absent.

2. Where showSaveFilePicker is supported, canceling the save dialog
   throws AbortError before any bytes have been read from conn (while
   the sender is still stalled on TCP backpressure), yet the catch
   handler closed conn and left the buttons disabled. Re-enable the
   buttons and keep conn open on AbortError so the user can retry or
   choose "Show as text".

Also set dir="auto" on #send-text and .recv-text so right-to-left text
renders with natural paragraph direction.

Updates tailscale#4

Signed-off-by: Dr. Mohammed Lubbad <engmlubbad@gmail.com>
@bradfitz
bradfitz merged commit 9245129 into tailscale:main Dec 2, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants