Clipboard on http: copy and paste work without the Clipboard API

Over plain http on a tailnet address the page is not a secure context and
navigator.clipboard is undefined, so the web engine refused every copy.
ClipboardReportingMessenger now answers clipboard calls through the
browser's legacy clipboard when the API is missing (web only, conditional
import): copy uses execCommand('copy') with a one-shot copy-event listener
(no focus or selection change); a paste key's Clipboard.getData takes the
browser's own paste event, the key reported not-handled so the browser
still fires it. A Paste button/menu says to use Ctrl+V or the https address.
Secure pages keep the engine path. Capture kit: --insecure and clipboard=.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-29 19:06:58 +00:00
parent 3d739c3bfc
commit 18807b8ac2
14 changed files with 714 additions and 26 deletions
+49
View File
@@ -68,3 +68,52 @@ chord is covered both ways); text fields when the browser reports Ctrl and
Meta together (the browser's native paste may not run then). With Flutter
semantics enabled, copying the transcript after typing in the composer did
not copy before or after this change (semantics off works); not addressed.
## Copy and paste on an insecure (http) page
Operator report: over plain http on the tailnet address the page is not a
secure context, `navigator.clipboard` is undefined, and Flutter's web engine
refused every `Clipboard.setData`/`getData` ("Could not copy: Clipboard is
not available in the context."), so no copy worked.
`ClipboardReportingMessenger` now takes an `InsecureClipboard`
(`lib/application/insecure_clipboard.dart`; browser side
`insecure_clipboard_host_web.dart`, conditional import, null on VM/native),
which answers clipboard calls only when the Clipboard API is missing:
- `Clipboard.setData`: `document.execCommand('copy')` with a one-shot
capture `copy` listener that puts the text on the event's clipboardData.
No textarea is focused or selected, so the Flutter text-editing element
keeps focus, caret and any IME composition. Needs user activation (keys
and clicks give it). Every caller (keys, menus, buttons, terminal) goes
through it.
- `Clipboard.getData` during a key event (the terminal's Ctrl+V,
Ctrl+Shift+V, Shift+Insert, the injected Super+V): the `flutter/keyevent`
reply is rewritten to not-handled so the engine does not
`preventDefault` the key; the browser then fires `paste`, which a capture
listener on window consumes (preventDefault + stopImmediatePropagation, so
no double insertion) and returns as the clipboard text.
- `Clipboard.getData` outside a key event (terminal menu/toolbar Paste) has
no paste event: the reply is an error the messenger shows as "Could not
paste: this page isn't secure (http), ... Paste with Ctrl+V, or open the
https address." (Cmd+V on Apple). A refused copy says the same for copy.
- Secure pages: nothing is answered here; engine path unchanged.
Text fields (composer) already paste natively; the browser context menu's
Copy on a transcript selection is the browser's own copy (no Clipboard API).
Evidence (headless Chromium, `--insecure true`, clipboard read back from a
loopback scratch page): `tool/capture/examples/clipboard-insecure-chat.json`
(code-block and message copy buttons; composer Ctrl+V once) and
`clipboard-insecure-terminal.json` (Ctrl+V, Shift+Insert, Ctrl+Shift+V each
paste once; Ctrl+Shift+C and menu Copy copy; typing after a copy still
reaches the terminal; menu Paste shows the message). The super-c chat keys
(physical Ctrl+C, Super+C both flag forms, Ctrl+Insert) copy "Answer 19";
the same steps on a build without the handler leave the clipboard
unchanged. Secure-page examples (`clipboard-super-c-*`, `-super-v-composer`,
`-copy-refused`) behave as before. Tests: `test/application/
insecure_clipboard_test.dart`.
Not verified: Firefox/Safari; the browser's native context menu (headless
cannot drive it); a copy issued long after its click (an awaited network
call first, e.g. artifact URL copy) may outlive the user activation.