# Browser plain-text clipboard paste

This local implementation adds the native app's **Client → Host** clipboard
behavior to the browser. It does not claim Host-to-Client clipboard reading:
there is no existing native Host clipboard-read protocol to reuse.

## User behavior

- **Paste text** in More, **Ctrl+Alt+Shift+V**, and the fullscreen control start
  one clipboard operation when Host keyboard input is enabled. The shortcut is
  handled locally and is not forwarded as an ordinary Host key chord.
- Clipboard text is read only after an explicit action while the page is focused.
  Nothing is read in the background, written to saved preferences, or exposed in
  recovery technical details.
- If `navigator.clipboard.readText()` is unavailable or denied, an explicit
  **Paste text manually** disclosure opens. The user can edit or paste text into
  the field and choose **Use this text**. No further clipboard read is attempted.
- A paste gesture is synthesized only after an authenticated **ready** receipt.
  The Host can select Ctrl+V, Ctrl+Shift+V, or Shift+Insert. Other status values,
  malformed receipts, stale sessions, timeouts and cancellations never paste.
- Modifiers are sent as a separate reliable key-state transition before V or
  Insert, and the action key releases before the modifiers. Key arrays are sets
  at the Host: ordering entries within one array does not order native events.
  Both left- and right-hand shortcut modifiers are supported. Ordinary key-up
  events are intercepted only while releasing an active clipboard shortcut.
- **Paste sent to Host** means the text was published and the paste gesture was
  sent, not that the application acknowledged insertion. Manual fallback typing
  remains local even when stream keyboard/pointer capture is active.
- Focus loss, intervening input, disconnect, session replacement, or an eight
  second deadline cancels pending browser work without an automatic retry. No
  paste gesture is synthesized after cancellation. Physical input is reset before
  the returned gesture, so it cannot remain stuck.

## Protocol and ownership

Each browser stream generates a fresh random 16-byte stream key and 16-byte
clipboard session ID. The Host activates clipboard publication only for that
owning stream and revokes it during stream cleanup. Session keys are not written
to browser storage or logged. The public ready message removes the stream key
before it reaches the main page.

The worker derives separate HMAC-SHA256 request and response keys and uses
AES-256-GCM with the native header as additional authenticated data. Random binary
session IDs remain bytes throughout key derivation; they are never decoded as
UTF-8. Envelopes retain the native `MCB1` request and `MCA1` receipt format,
including strict UTF-8 text, sequence, session ID, tag, status and gesture checks.
Maximum text is 1 MiB and maximum request envelope is 1,048,632 bytes.

The dedicated same-origin `/clipboard` route requires an active ticket and exact
`application/octet-stream` content type. It validates the native binary magic and
exact size, then preserves the envelope over the existing authenticated loopback
bridge. No native-port or manual HTTPS trust changes are introduced. Ordinary
JSON commands remain limited to 8 KiB; only this operation has a separate 2.1 MB
maximum command envelope. Native completion is bounded to eight seconds and late
receipts cannot affect a replacement stream.

## Verification scope

Unit tests cover WebCrypto round trips, wrong keys, tampering, malformed receipts,
non-ready status values, Unicode, embedded NUL, unpaired surrogates and maximum
size. Go tests cover exact forwarding, origin/ticket/content admission, native
failure mapping, malformed receipts and scoped size limits. Chrome scenarios
cover button/shortcut success, permission-denial fallback, chord release,
intervening-input cancellation (including analog noise versus deliberate gamepad
input) and disconnect without a late gesture. Native C++/WebCrypto round trips
also cover arbitrary binary session IDs and forward-byte hex decoding.

A private real-backend Chrome/X11 acceptance additionally verified the exact
Unicode text and an exact 1 MiB selection through the actual native clipboard
backend, six media/audio sessions, and rejection of the retired clipboard ticket
with HTTP 403 after disconnect. The installed Host was not replaced or restarted.

The initial Preview 15 acceptance above checked selection contents, not insertion
into a focused application. A user-reported failure exposed that gap: the original
gesture sent V before its modifiers and typed a literal `v` in an actual GTK text
editor even though selection transfer passed. A fresh private reproduction with
the exact published binary confirmed button, shortcut and manual-fallback failures.
The frontend correction passes those actual editor-content checks with ASCII,
multiline Unicode and the real browser clipboard API. The test redirects the
published Host/inputtino evdev output to private XTest; it does not create a kernel
input device or qualify every physical input backend. This correction ships in
the complete Browser Preview 16 package; reload the page after upgrading.

These are protocol and synthetic-interface checks, not a claim of universal
physical clipboard manager support. Actual backend behavior depends on the
Host's existing native clipboard support and the focused application. X11,
Wayland and Windows retain their existing native implementations and gesture
selection; macOS remains unsupported.
