Skip to content

feat(native): server-streamed preview browser in the right panel - #53

Merged
rynfar merged 5 commits into
nativefrom
nw/w17-preview
Nov 2, 2026
Merged

rynfar merged 5 commits into
nativefrom
nw/w17-preview

Conversation

@rynfar

@rynfar rynfar commented Nov 2, 2026

Copy link
Copy Markdown
Owner

Ports ledger row PN-PREVIEW (now partial): the web's server-streamed browser as a right panel tab, against the unmodified server (capabilities.serverBrowser, preview.open/adjust/close/list, subscribePreviewEvents, subscribeDiscoveredLocalServers, and the /api/preview-stream/ws socket authenticated with a media WebSocket ticket).

What shipped

  • Core (crates/core/src/preview.rs, preview/stream.rs, preview/address.rs, with tests): wire types; the per-thread session reducer from previewStateStore.ts (revision/epoch ordering, suppressed closes, newer-copy wins, reveal baselines); stream messages, input encoding, the controller gate, close codes, retry and refusal backoff, host setup; viewer geometry (pagePoint, placeAgentCursor, frame cap); keystroke to DOM key mapping; resolveAddressBarInput/normalizePreviewUrl; per-project recent history. right_panel.rs gains SurfaceKind::Preview (browser:<tab>/browser:new, the web's persisted shape), openBrowser and reconcileBrowserSurfaces.
  • Client (crates/client/src/preview_stream.rs): mints a media ticket per connect, acks every JPEG frame, keeps only the newest frame in a watch, sends input only while this viewer controls the tab, and reconnects with the web's backoff until the tab is gone, the host needs setup, or the upgrade is refused 3 times. examples/preview_probe.rs runs the whole path headless.
  • App (crates/app/src/preview/): "Browser" in the launcher and the add menu (disabled with the web's hint when the server has no browser or the device lacks preview:operate); the tab title follows the page; the chrome row (back, forward, refresh, address bar with search, open in system browser); the page drawn from frames decoded off the UI thread, repainting only the page view per frame; pointer, wheel (coalesced to ~16ms), key, paste and thumb-button input scaled to page px (HiDPI cap from the window scale); resize sync and frame cap growth; control bar with Take/Release control; agent cursor overlay and read-only watching when the agent drives; page dialogs; host setup and refused states; empty state with recently used addresses and discovered local servers; the unreachable page. Tabs follow the thread's sessions (agent-opened and popup tabs appear, forced reveals come to the front, server-closed sessions drop their tab); closing a tab closes its session. Keys: preview.toggle (mod+shift+j), and in the previewFocus context mod+r, mod+l, zoom in/out/reset (via preview.adjust). Only the active browser tab streams.

Evidence (offscreen snapshots against the smoke server, 1440x900 @2x)

  • Empty state with discovered servers: /private/tmp/claude-501/-Volumes-DevSSD-t3code/31a183a0-8354-4d43-b031-d9f81d50685d/scratchpad/w17/w17-empty.png
  • Live streamed tab (example.com), control granted, page resized to the panel: /private/tmp/claude-501/-Volumes-DevSSD-t3code/31a183a0-8354-4d43-b031-d9f81d50685d/scratchpad/w17/w17-live.png
  • Unreachable page: /private/tmp/claude-501/-Volumes-DevSSD-t3code/31a183a0-8354-4d43-b031-d9f81d50685d/scratchpad/w17/w17-unreachable.png

Probe transcript (smoke server; the session is closed at the end):

opened: tab=tab_1_… runtime=Some("server") status=Loading { url: "https://example.com/", title: "" }
preview event: revision=3 … Success { url: "https://example.com/", title: "Example Domain" }
event: Connected(true)
control: You have control (generation 1)
sent navigate http://127.0.0.1:14658/
message: Viewport(Viewport { width: 1280.0, height: 800.0 })
first frame: 139791 bytes, jpeg size Some((2560, 1600))
preview event: revision=4 … Loading { url: "http://127.0.0.1:14658/", title: "" }
ok: 2 frames
closed: tab=tab_1_…

Gates: cargo test --workspace, cargo clippy --workspace --all-targets -- -D warnings, gen-theme --check, parity/sync.test.ts, conformance --check all pass.

Unverified

  • Real-window interaction (clicks, typing, wheel, drag, Take/Release, dialogs): the snapshot tool can't drive input. The wire for navigate and control was checked by the probe.
  • Agent-driven tabs (agent cursor, "Agent has control", forced reveals): no agent run was started.

Not ported yet

Floating mini player / picture in picture, device toolbar and viewport presets, annotations and screenshots, recording, file chooser uploads and downloads, color scheme/hard reload menu, IME composition into the page, real favicons, reopening a closed browser tab with cmd-shift-t, the confirm before closing an agent-driven tab, the configured URLs from project scripts in discovery, and a search engine setting (DuckDuckGo is used, as the web defaults).

Model and harness: Opus 5.5 (Claude Code agent W17).

@rynfar

rynfar commented Nov 2, 2026

Copy link
Copy Markdown
Owner Author

Review fixes in 17f8d55, rebased onto native after #52. The only conflict was EnvironmentCapabilities, where I kept both sets of fields. All gates pass again.

Fixed (all four were real)

  1. Shifted digits and symbols were dropped. gpui_macos names Shift+1 "!". dom_key now maps both halves of each key to its physical code (! → Digit1, { → BracketLeft, : → Semicolon, …). A character the table doesn't know (such as ö) still goes out with its text and no key code, and the server derives the code. The tests now use the keystrokes GPUI actually emits, and the !/@/{/: cases fail on the old code.
  2. Dialog prompts lost their keys. Key forwarding now requires the page's own focus handle to be focused. The dialog card and the blocking overlays stop mouse-down, so clicking them no longer moves focus to the page.
  3. Overlays hid the control bar. The bar has a fixed 33px height, and the empty and unreachable overlays start below it whenever a stream view exists, so Take control stays reachable. Snapshot: w17-unreachable-bar.png.
  4. Stale tabs on background threads. A new sync_panel reconciles the browser tabs whenever a thread comes into view, and again after its list returns even when the list didn't change.

Dismissed: none.

@rynfar

rynfar commented Nov 2, 2026

Copy link
Copy Markdown
Owner Author

Added a test for fix 4 (d1705ca). The decision about what the shown thread's browser tabs need now lives in core as PreviewThreads, which Previews delegates to. The new a_thread_shown_again_catches_its_tabs_up_with_changes_made_while_hidden test covers a session closed by another client while its thread is hidden, and a list that changes nothing. It fails when the fix is reverted and passes with it. All gates pass.

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.

1 participant