Skip to content

Handle iOS file downloads with WebKit’s native download API - #5508

Merged
ymichael merged 4 commits into
mainfrom
t3code/ios-file-downloads
Oct 14, 2026
Merged

ymichael merged 4 commits into
mainfrom
t3code/ios-file-downloads

Conversation

@ymichael

@ymichael ymichael commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

The bb iOS shell did not implement WebKit downloads. Download links could replace the app with raw file content, disappear silently, or open Safari without the WebView's authentication. React Native WebView's existing callback cancels an attachment response and reports its URL; downloading that URL separately also loses the original request context. Browser-created blobs cannot be fetched through a separate native HTTP client.

What changed

  • Extend the existing react-native-webview patch with WKDownload: download navigation actions and attachment/non-displayable responses become native WebKit downloads. WebKit retains the request and authentication context and writes directly to cache. There is no manual cookie forwarding, native HTTP refetch, base64 transfer protocol, or blob-size cap imposed by bb's bridge.
  • Native delegates sanitize destination paths, cap active downloads at four, report completed files/errors through the patched onFileDownload event, and cancel/remove partial downloads on reload or WebView teardown. Previous-process cache files are removed on the first download. React Native presents the share sheet and removes each completed download's directory after sharing, dismissal, or failure.
  • Query the installed binary with nativeDownloadsSupported() before enabling these handlers. New JavaScript on an older native binary retains its previous behavior. The optional page handshake field is nativeDownloads: true; the strict capabilities enum and bridge version remain unchanged.
  • Keep one saveFile helper and the experimental_saveFile plugin API for FilePreview, chat attachment fallback, voice recordings, and Tasks attachment cards. They click ordinary download anchors, including blob object URLs. The helper returns started or failed; download completion and share-sheet cancellation belong to the browser/native shell and are not reported to the page.
  • Convert server API target=_blank links into download anchors and allow page-local preview subframes on prefixed profiles.
  • Document the plugin API and native behavior, retain the SDK bump to 0.6.46, and add a reusable HttpOnly-cookie/blob/download-lifecycle fixture proxy with verification instructions in the mobile README.

The native approach replaces the custom transfer design proposed in the issue. Installing a rebuilt iOS binary is required; Metro or OTA updates alone cannot add native download support. Android retains its existing download behavior. The Tasks URL remains root-relative, matching the rest of the current web app; the QA prefix proxy forwards both root and prefixed paths. Existing SDK/CLI attachment downloads remain available. There are no server/daemon wire changes or CLI configuration changes.

How you verified

  • Turbo typechecks and lint passed for @bb/app, @bb/mobile, @bb/mobile-bridge, @get-bb/plugin-sdk, bb-plugin-tasks, bb-plugin-plugin-api-docs, and bb-plugin-bb-guide. Lint has zero errors; existing warnings remain.
  • Turbo tests passed: mobile 341 tests, bridge 38 tests, and 12 focused app save-file/native-shell tests. New coverage includes older-binary support detection, anchor behavior without bridge traffic, object-URL lifetime, and share-sheet failure/cancel/concurrent-file cleanup.
  • Built the web app through Turbo. Installed dependencies with the frozen lockfile to confirm the patch applies, regenerated CocoaPods/codegen, and compiled the patched simulator client with Xcode.
  • On iOS 26.4, authenticated HTTP and browser-created blob downloads opened the share sheet with the expected filenames. Their 1,536,000-byte cache files matched SHA-256 a736313d0ceea38f1c1f7b38f23c0d9a2ca357d7705fded82233a3b067e7d1dd. Authenticated requests had the fixture's HttpOnly cookie; the same endpoint returned 401 to curl without it.
  • Checked Tasks ZIP and PDF attachment downloads in the simulator and the same card in the collaborative desktop browser (normal 181-byte download). The fixture proxy preserves Host so plugin assets and WebSockets satisfy the server's origin checks.
  • Checked the actual FilePreview Download button: it opened the share sheet with the ZIP's real filename and 181-byte contents.
  • Checked root and /bb profiles, Save to Files with byte-identical output, share-sheet dismissal with an empty cache, a 404 error toast without replacing the page, and a target=_blank attachment opening the share sheet. Reloading a slow download closed its connection after partial delivery and removed its cache file.
  • Native download behavior is verified on the simulator, not on physical devices or older iOS versions. This pass did not exercise Android native builds or bb connect enrollment.

Fixes #5503

AGENT GENERATED

ymichael and others added 3 commits October 14, 2026 12:33
…he app

In the iOS app, every web download link navigated the WebView itself: on a
root-mounted server the app was replaced by the file's raw bytes with no way
back, and on a path-prefixed server Safari opened the URL without the app's
cookies. react-native-webview has no download support, and the bridge could
not carry a file.

The web app now saves through one saveFile helper, also exposed to plugins
as experimental_saveFile. Browsers and Desktop keep anchor downloads. In an
iOS shell that advertises the new optional saveFile handshake field, server
URLs go to a save-file bridge request that the shell downloads with the
WebView's cookies, and page bytes go in bounded base64 chunks; the shell then
presents the share sheet and cleans up its cache. Older shells keep today's
behavior. The shell also saves stray attachment responses (onFileDownload)
and new-window server files (onOpenWindow), and lets subframes load blob:,
data:, about: and same-origin URLs.

Fixes #5503

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael ymichael changed the title Save files through the iOS share sheet instead of loading them over the app Handle iOS file downloads with WebKit’s native download API Oct 14, 2026
@ymichael
ymichael merged commit a2a9be5 into main Oct 14, 2026
48 checks passed
@ymichael
ymichael deleted the t3code/ios-file-downloads branch October 14, 2026 21:42
ariofrio added a commit to ariofrio/bb that referenced this pull request Oct 16, 2026
Takes upstream's post-get-bb#5590 voice files, since get-bb#5590 applies on top of 0.46.1, and keeps 0.46.1's plugin SDK version and API audit doc, which already include get-bb#5508.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael added a commit that referenced this pull request Nov 3, 2026
## Human comments

## What was wrong

The iOS shell's WebView never set `originWhitelist`, so
react-native-webview 13.16.1 used its default (`about:blank`,
`http://*`, `https://*`). Its `createOnShouldStartLoadWithRequest`
cancels any load that misses the whitelist before it calls the app's
`onShouldStartLoadWithRequest`. inline-vis renders into `<iframe
srcDoc>`, which loads `about:srcdoc`, so every inline-vis page in the
iOS app stayed a blank 224px frame. The `about:`/`blob:`/`data:`
subframe allowance from #5508 (`allowsSubframeLoad`) was never reached.
Details and reproduction in #5986.

## What changed

- `apps/mobile/src/lib/shell/shell-save-file.ts`: export
`SHELL_ORIGIN_WHITELIST`, http(s) plus the page-local protocols
`allowsSubframeLoad` already accepts, built from the same
`SUBFRAME_LOCAL_PROTOCOLS` set.
- `ProfileWebViewScreen` passes it as `originWhitelist`, so those loads
reach the existing `onShouldStartLoadWithRequest`, which still decides
what loads. Top-frame `about:`/`blob:`/`data:` navigations now reach
that handler too instead of react-native-webview's `Linking.canOpenURL`
fallback. The handler returns false for them, as before.

## How you verified

- `shell-save-file.test.ts`: every URL `allowsSubframeLoad` accepts
(`about:srcdoc`, `blob:`, `data:`, same-origin https) passes
react-native-webview's whitelist matching with `SHELL_ORIGIN_WHITELIST`,
and `about:srcdoc` fails it with the default list. The new tests do not
compile or pass without the change.
- `pnpm exec turbo run test --filter=@bb/mobile` on this branch: 46
files, 343 tests pass. `turbo run test typecheck lint
--filter=@bb/mobile` passed with the same change on an older base
(5b34962ab6). On this branch `typecheck` could not run locally because
`tsrs` is not installed in my checkout. `lint` has no errors, and `oxfmt
--check` is clean for the changed files.
- iOS Simulator (iPhone 17 Pro, iOS 26.4), Release build (`npx expo
run:ios --configuration Release --no-bundler`) connected to a local
server. Before the change, a fenced `inline-vis` block and a
thread-storage `::inline-vis` directive were blank 224px frames. After
it, both render inside the message. I did not run the Maestro flows.

Fixes #5986

> AGENT GENERATED

---------

Co-authored-by: Michael Yong <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
smsunarto added a commit to smsunarto/bb-plugins that referenced this pull request Nov 19, 2026
…3) (#187)

* fix(scott-tasks): return a saved comment before agent delivery finishes

Port of upstream get-bb/bb#4679. The app's createComment waited for the
thread lookup and send before answering, so a slow or stuck worker
held the composer. The app now returns the saved comment at once and
delivers in the background; the CLI still waits so it can report the
notified count.

* feat(scott-tasks): move a task and its sub-tasks to another project

Port of the server and CLI half of upstream get-bb/bb#4100. A moved
task gets a fresh number in the target project, lands at the end of its
status column, and keeps its old key as an alias, so mentions and agent
instructions that name the old key still resolve. Labels are remapped
by name and created when missing. A sub-task moved on its own leaves
its parent. New: moveTaskToProject RPC and bb tasks move.

* feat(scott-tasks): move tasks from the detail page and the list's context menu

The UI half of upstream get-bb/bb#4100. The properties rail and inline
chips get a project picker, and a list row's context menu gets Move to
project. Opening a task by a key it had before a move asks the server
and follows the task to its current key.

* feat(scott-tasks): keep New task drafts and cap the dialog's height

The dialog half of upstream get-bb/bb#4100. Title, description and
attributes save to localStorage as they change, so an outside click,
Escape or reload no longer throws a long task away; Discard draft
clears it. The dialog is capped at 85dvh with the description
scrolling, so Create task stays reachable.

* fix(scott-tasks): port upstream touch, embed and download fixes

- get-bb/bb#5097: label and preset row actions stay visible on screens
  without hover, such as a 13-inch iPad.
- get-bb/bb#5157: a narrow desktop pane keeps the compact topbar; only
  touch screens get the taller one.
- get-bb/bb#5903: the whole task embed card opens the task, and a
  loading card no longer highlights on hover.
- get-bb/bb#5508: attachment downloads go through bb's saveFile, which
  the iOS shell implements with WebKit's native download.

* docs(scott-tasks): document bb tasks move; drop unused hono and cron-parser

hono 4.11.9 was a vulnerable pin that nothing imports; cron-parser is unused too.

* feat(scott-tasks): delegate as a child thread from a chosen base branch

bb tasks delegate takes --parent-thread, --parent-notifications auto|stuck|off and --base-branch, passed to threads.spawn. An orchestrating agent dispatches its crew as children so bb reports their turns to it, and starts each worktree from its own branch. --base-branch always means a new worktree, whatever the preset names, and leaves the preset unchanged.

* fix(scott-tasks): let the attachment preview's img own its object URL

Attachment chips set state in an effect to hold the preview URL; the <img> ref callback now creates and revokes it. Clears a react(set-state-in-effect) lint error.

* feat(scott-tasks): owned fields, crew snapshot and parent wakes for Captain

- defineField/setField: typed fields only the owning plugin may write; a write
  bumps the task's updated_at.
- crewSnapshot({threadIds, changedSince}): one read of task, parent, fields,
  preset, live status and the last notifying comment with its delivery state.
- bb tasks comment --notify-parent sends a one-line wake to the commenting
  thread's parent and retries from the database (1, 2, 5, 15 min; 6 attempts),
  then marks it undeliverable; --attach puts files on the comment first.
- delegate takes reportContract and drops its built-in contract under stuck;
  taskThreadsAttach keeps presetName; plugin callers may author comments.
- Task threads get an archived live status that unarchive reverses.

* perf(scott-tasks): drop unused toolbar and command exports

Cuts 10 KB of app.css that Tailwind generated for components nothing imports.

* fix(scott-tasks): let the list's empty state fill the scroller

Port of get-bb/bb#7613's Tasks part: the list's size container moves inside the scroller, and the empty state grows to fill it.

* fix(scott-tasks): resolve CLI file paths with the target host's path rules

Port of get-bb/bb#6760: file flags resolve with the SDK's host-path parser, so Windows drive and UNC paths from a remote thread resolve on that machine instead of with the server's node:path.

* refactor(scott-tasks): drop store inputs nothing passes

Port of the Tasks part of get-bb/bb#4606: create inputs no longer take an id, comment updates take only notifiedCount, attachment updates only blobPath, and new comments rely on the column's 0 default. The tie-break test sets its ids with SQL, as upstream's does. Skipped: upstream blanking the is_image migration (it already ran here), and displayWidth and the description saver's schedule option, which fork tests still use.

* test(scott-tasks): cover list scope switches while reads are pending

Ports get-bb/bb#7056's regression tests. Upstream fixed a list stuck behind placeholders when it switched scope to a cached list; the fork's collection-backed list already passes them, so no code change was needed. All shows every task the shared collection holds, so the All step checks no absent row.

* fix(scott-tasks): apply resize-measured layout in the resize frame

Port of get-bb/bb#7635's Tasks part. The board-width check and the list's row window read their size in a shared ResizeObserver and write it inside flushSync, so a resize never paints one frame of the old layout. lib/shared-resize-observer.ts is vendored from upstream's registry, which the desktop-v0.49.0 pin predates. The row window measures through a plain function of the element so the mount read stays a ref-derived layout measurement.

* docs(scott-tasks): record the upstream sync to get-bb/bb 48c3a78

Names the new upstream base and every change the fork holds, with the reason for each.

* fix(scott-tasks): settle the list's scroll scope during render, not from a ref

ListView read settledScope.current during render, the one oxlint error left in scott-tasks (react(refs)), so bunx oxlint on the plugin failed. The settled scope is now state set during render, like the saved preference above it, and settles in the same render its rows finish loading.

* fix(scott-tasks): stop an expired wake attempt from sending after a retry

Promise.race ended the 30s wait but not the attempt, so a stalled thread lookup could resume after a retry had delivered and wake the parent twice. The deadline now aborts the attempt's signal, and the attempt re-checks right before threads.send (and before recording a target) that it is unexpired and still the latest claim on a pending record. Review's deterministic repro is the regression test; it fails on the old code.

* chore(scripts): prune the resolved scott-tasks list refs baseline entry
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.

iOS app: file downloads replace the app with raw file bytes (root mount) or open Safari without cookies (prefixed mount)

1 participant