# Desktop browser client — development preview

The optional browser client uses **WebTransport/HTTP/3 + WebCodecs**. The Host
captures and hardware-encodes video using its existing backend. A bundled Go
helper serves HTTPS assets, terminates QUIC, and forwards compressed media and
input over a bounded loopback connection. There is no decode/re-encode gateway.

This is an opt-in development preview. See the preview release notes for current
build/runtime verification; API support alone is not device qualification. The
native Maximizer Client remains a separate application.

For the login/settings layout, controls, accessibility guidance and UI acceptance
fixture, see [Browser login and stream settings](browser-interface.md).

The 2026-10-25 isolated Linux run passed Chromium148 and Firefox150 playback,
stereo audio, browser/native handoff, input transport, reconnect, receiver-side
loss recovery and helper/Host lifecycle checks. Native Client276 paired/launched/
resumed with browser support OFF and ON. Physical controllers/rumble, Windows/
macOS/Safari runtime, hardware encode/decode, WAN operation and input-to-photon
latency remain to be qualified.

## Current development scope

- Current desktop Chrome/Edge, Firefox, and Safari 26.4+ are the intended clients.
  Linux and Windows are the hosting targets; a Mac can be the browser device.
- Negotiated HEVC Main 10, HEVC Main 8-bit, AV1 Main 8-bit, or H.264 High,
  all 4:2:0; SDR presentation and stereo 48 kHz Opus with 5 ms audio packets.
  720p/1080p/1440p/4K and 30/60/120 FPS are requested settings, not certification
  that every browser/device/encoder can sustain those combinations.
- Keyboard, relative/absolute mouse, vertical wheel, up to four standard-mapped
  gamepads, and optional ordinary rumble. USB/Bluetooth mappings need physical
  tests. Non-standard controllers are reported but are not guessed/mis-mapped.
- One active native **or** browser session. A browser refuses a busy host; native
  launch/resume refuses a browser-owned capture. Closing the browser disconnects
  streaming and leaves the application available for a subsequent resume.
- Local apps on the connected Host. A Windows VM running its own Host can be a
  separate endpoint; parent-host VM launch/proxy management is not yet exposed.

Plain-text Client → Host clipboard paste is described in `browser-clipboard.md`.
HDR presentation, microphone forwarding, file transfer, Host-to-Client clipboard
reading, mobile qualification, custom controller remapping, motion
sensors/adaptive triggers/wheel force feedback are follow-up work. Resolution
stays fixed; bitrate reduction requires the explicit session checkbox on a
supported encoder.

## Profile negotiation (Browser Preview 7)

Automatic compatibility probes HEVC Main 10 → HEVC Main 8-bit → AV1 Main 8-bit →
H.264 High, then sends an ordered `supportedProfiles` list with `presentation:sdr`
on the authenticated start request. The Host intersects it with the current
encoder capabilities and acknowledges `videoProfile` and `bitDepth`. Main 8-bit
is eligible on both Main-only and Main10-capable HEVC encoders. AV1 uses its own
encoder and an elementary OBU stream, not a relabeled HEVC stream.

Each probe uses a full codec string and the selected dimensions. MediaCapabilities
receives bitrate **in bits/second** and framerate; WebCodecs receives coded width
and height, decoder preference and low-latency hint. WebCodecs has no decoder
bitrate/framerate fields. MediaCapabilities' MP4/file answer is retained as
diagnostic evidence, not a veto over a supported elementary WebCodecs path.
Both `hvc1` and `hev1` are probed. Hardware preference may fall back to browser or
software selection; capability hints never prove the active hardware backend.
There is no user-agent or operating-system sniffing.

Probe levels account for frame size, sample rate and bitrate. In particular,
3840×2160 at 60 FPS needs H.264 Level **5.2** (`avc1.640034`), not 5.1. HEVC
Main-tier Level 5.1 is suitable at 4K60/40 Mbps; higher bitrates need higher
levels. AV1 levels use its own sequence-level index. These are admission probes,
not promises that every driver emits identical headers: the receiver parses the
actual SPS/AV1 sequence header and probes the emitted profile/level again, with
the real HEVC `hvcC` description. It never rewrites a codec string to claim that
an unsupported high-level stream is a lower-level one.

If actual-header/configuration admission fails before the first displayed frame,
the browser closes that attempt, cancels its exact ticket and waits for Host
capture release, then requests the next supported profile. Each profile gets at
most one attempt. Disconnect/logout aborts the sequence; stale results cannot
attach to a new session. Network errors are not treated as profile failures.
Active-session switching after playback begins is not implemented in this v1.

The renderer is explicitly an **8-bit sRGB SDR canvas**. Main10 can be used for
SDR encoding without claiming 10-bit/HDR display output. Before forwarding video,
the Host checks the encoder's actual HDR state (independently of HDR metadata
retrieval). HDR output is rejected with a structured profile error, causing an
8-bit SDR retry through the Host's existing SDR capture/conversion path. Decoded
PQ/HLG frames are also rejected before drawing. No new HDR tone mapper or physical
HDR display qualification is claimed.

When no profile is mutual, the error names the rejected actual codec when known,
lists Host profiles, offers **Request compatible stream (8-bit/H.264)** and links
the native client. Resolution/FPS/bitrate settings are preserved across retries.
Updating both the Host and its matching bundled helper is required; legacy
`videoFormat` requests remain accepted by the new Host.

## Build a single Host package with the helper

Install a Go **1.26+** build toolchain in addition to the normal Host prerequisites.
The runtime helper is self-contained: users do not install Go, Node, or another
streaming server. The frontend is embedded in the helper executable.

```sh
cmake -S . -B build-browser -DSUNSHINE_BUILD_BROWSER=ON -DWITH_AUTH_SQLITE=ON
cmake --build build-browser --parallel 2
```

`cmake/BrowserClient.cmake` builds the locked `browser/go.mod` / `go.sum` graph
with `CGO_ENABLED=0`, installs the helper in `assets/browser`, and makes the Host
target depend on it. Existing build profiles default this packaging option OFF.
Use it explicitly in a browser-preview build. The `browser-preview-*` tag workflow
builds a browser-enabled Linux DEB; stable build profiles retain their defaults.

Dependencies are pinned to webtransport-go 0.13.0 / quic-go 0.62.0. This revision
includes the HTTP/3 settings needed by recent Safari WebTransport implementations.

## Configure

Preview2's input/latency changes and diagnostic guidance are described in
[Browser latency](browser-latency.md). Reload an existing browser tab after upgrading.

Create a streaming account in the Host **Users** page. This is the SQLite
streaming-account store, not the separate administrative Web UI password.
Set `auth_method=both` (retains PIN pairing) or `password`.

In the Linux browser-enabled DEB, open **Configuration → Network → Desktop Browser
Client**, enable streaming, choose **Automatic Let’s Encrypt**, explicitly accept
the Subscriber Agreement, then **Save and Apply while idle**. The Host detects its
public IP, issues a trusted certificate, derives all paths and the HTTPS address,
and renews while running. No enrollment JSON, service/timer setup or certificate
commands are needed. Wait for **Browser HTTPS: ready** and open its client link.

See [automatic HTTPS and network prerequisites](browser-certificates.md).
TCP80 must reach the Host for validation/renewal, and TCP+UDP on the browser port
must reach it for streaming. Public-IPv4 detection uses `api.ipify.org`; a stable
IPv4/IPv6 override and contact email are optional. Existing manual certificate
deployments retain their paths, account state and renewal jobs on upgrade.

For a certificate you already manage (including Windows), choose **manual** and
configure the following in the same page, or `sunshine.conf`:

```ini
browser_enable = enabled
browser_tls_mode = manual
browser_port = 8443
browser_origin = https://203.0.113.10:8443
browser_tls_cert = /absolute/path/fullchain.pem
browser_tls_key = /absolute/path/privkey.pem
```

Replace the documentation IP with the Host's assigned public IP. The optional
operator-managed method in the certificate guide remains available; use its
combined PEM for both certificate/key paths. No per-customer DNS record is needed.

The origin must exactly match the URL opened in the browser, without a path or
trailing slash. Use a publicly trusted certificate matching that IP or hostname.
Renewed files are hot-reloaded within five seconds on both HTTPS and HTTP/3;
active streams are retained. Ordinary HTTPS trust in a private CA does not necessarily enable
HTTP/3 under a browser's local-root policy. The
normal native-client self-signed certificate/pinning workflow is separate.
On Windows use absolute Windows paths to the certificate/key readable by the
Host service account. The helper binds both TCP and UDP on `browser_port`; allow
both through the cloud firewall/NAT. A TCP-only reverse proxy does not carry the
HTTP/3 session. No firewall/router changes are made automatically.

Save and Apply while idle, open the ready HTTPS origin, sign in, choose an
application, and Start streaming. A page click resumes browser audio. Click the
windowed picture for desktop input or use Capture mouse for relative game input.
Browser Preview 9 adds automatic mouse capture on the player's Fullscreen
action, in-fullscreen release/recapture controls and opt-in saved stream
preferences. See [Browser login and stream settings](browser-interface.md)
for availability, shortcuts and persistence scope. Ctrl+Alt+Shift+Q disconnects;
some OS/browser-reserved shortcuts remain local. Press a button on a connected
gamepad to expose it to the page.

For an uninstalled development build, `browser_executable` may point to the
matching built helper. Production packages use the bundled location by default.
Disabling `browser_enable` and restarting removes the helper and loopback listener.

## Session and wire design

- A loopback-only listener is allocated on an ephemeral port only when enabled.
  The Host launches/owns the helper; shutdown or helper failure retires its session.
- HTTPS login validates existing bcrypt hashes. In-memory login tokens expire in
  15 minutes. Single-use attach tickets expire in 15 seconds. Authentication data
  and tickets are never logged. New sessions recheck the account; active sessions
  recheck account deletion/password rotation every ten seconds.
- The public helper accepts an exact configured Origin, bounded POST JSON API
  messages, and a ticket-authenticated WebTransport connection. It never exposes
  the Host's administrative APIs or accepts a browser-selected upstream address.
- Capture reservations participate in native session counts, display matching and
  GPU/VM admission. The browser owner probes before capturing while holding the
  existing capture-operation lease. Native encoder defaults remain the defaults.
- Private encoded queues avoid consuming native packets. Browser keyframes own
  their SPS replacement data across encoder teardown. Actual-header validation and
  bounded profile retries follow the negotiation described above.
- Local records use a four-byte big-endian length. Media has a 24-byte `MX`,
  version-1 header (type, flags, frame sequence, microsecond timestamp, length).
- Network media uses 32-byte headers and 960-byte data fragments. An XOR parity
  fragment per group of eight recovers one loss in that group. The last short
  group uses its actual length, avoiding large padding on 5 ms Opus packets.
  Reassembly also accepts the original full-length parity form, validates lengths, bounds memory, rejects
  completed duplicates and expires incomplete frames after 40 ms.
- Video decoding preserves reference order. Missing dependencies request a new
  keyframe; decode backlog triggers resynchronization instead of growing latency.
  QUIC's own datagram queue is also bounded; sender frame deadlines are checked
  between sends, not a guarantee about an in-progress congestion-blocked send.
- Audio uses a worker decoder and an AudioWorklet ring, short startup buffering,
  silence for bounded losses, and a cap on accumulated playback backlog. Rendering
  is immediate rather than a broadcast-style scheduled timeline. Tight A/V sync,
  drift behavior and actual device output delay require runtime measurement.
- Reliable ordered digital snapshots preserve short button edges. Motion uses
  its own datagram sequence space and cumulative relative deltas. A newer motion
  datagram never supersedes a reliable button transition. Focus loss/disconnect
  neutralizes controls; the Host independently neutralizes after 500 ms without
  input and ends a session after five seconds without a client heartbeat.
- An attach ticket is single-use, but remains available for authenticated,
  exact-ticket cancellation of its active session. The cancellation reply reports
  whether capture is released. Old or mismatched tickets cannot stop a new stream.

## Verification

Run tests only on the project's authorized runtime target. Compile-only commands
are appropriate while that server is unavailable:

```sh
cmake -S tests/browser -B build-browser-protocol
cmake --build build-browser-protocol
# On the permitted runtime system:
ctest --test-dir build-browser-protocol --output-on-failure
```

From `browser/`, `go test ./...` covers framing, origin admission, fragmentation,
parity and a real encrypted QUIC/WebTransport exchange with a synthetic host.
`go test -c` only compiles these tests. `node --test tests/*.test.js` covers
reordering, missing fragments, memory bounds, duplicate parity, SPS negotiation,
control framing and standard gamepad/key mappings. The profile/worker suites cover
full-string probes, `hev1`, software AV1 eligibility, resolution-specific levels,
actual-header fallback, exact-ticket teardown ordering, cancellation, bounded
exhaustion, and PQ/HLG rejection before SDR presentation. AV1 parser fixtures use
the native Client's genuine Main8/Main10 sequence headers.

Profile negotiation must be qualified before shipping on Linux Chrome with AMD
and Intel VA-API, Windows Chrome, macOS Chrome and Safari. On each platform test
Main10, Main8, AV1 and H.264 Host capabilities, a deliberately unsupported actual
header, a software-only path, no mutual profile and the compatibility button,
disconnect during fallback, HDR capture to SDR request, and 4K60 dropped-frame
statistics. Synthetic capability responses verify decision logic, not platform
support. `chrome://media-internals` may have no WebCodecs players; then use scoped
Chromium decoder logging to confirm the implementation actually instantiated.
An enabled GPU feature or `prefer-hardware` is not active-decoder proof.

The 2026-10-28 development run on Chrome 156 / RX 7900 XTX passed nine private
loopback cases: Main10, Main8, AV1, H.264, deliberate actual Main10 rejection with
automatic Main8 retry, software-preferred AV1, no-capability then one-click H.264,
four rejected profiles with bounded termination, and a software AV1 trace.
The eight functional cases were repeated after the final matching-ticket gateway
release guard; retry waits for both capture and the WebTransport slot to retire.
Successful streams stayed 3840×2160/60 FPS and ended near 60 FPS with zero
presentation drops in this short synthetic-content run. AV1's measured payload
was about 0.6 Mbps despite a 60 Mbps target; this was not a 60 Mbps AV1 stress test.
Decoder logs recorded VAAPI for hardware cases; the software trace recorded
`Dav1dVideoDecoder` with the 3840×2160 AV1 configuration and decoded-frame events.
76 JavaScript checks, Go normal/race/vet, C++ protocol checks, a private Linux Host
build and Linux/Windows helper builds passed. Linux Intel, Chrome 155 Flatpak,
Windows Chrome, macOS Chrome/Safari, physical HDR capture-to-SDR fidelity and
published-package qualification remain separate. Preview 7 is an opt-in pilot for
user testing while the broader platform matrix remains pending.

Before publication, qualify real Chrome/Edge/Firefox/Safari sessions, actual H.264
and Opus decoding, stereo audio, input/rumble, disconnect/reconnect, tab closure,
native↔browser handoff, busy/startup races, account revocation, helper crashes,
packet loss/jitter/bandwidth limits and long-duration bounded resource use.
Compare native pairing/launch/resume/input/audio with the option OFF and ON.
Measure median/p95 input-to-photon latency on matched hardware/settings rather
than treating decoder counters or a compile pass as latency proof.
