Repository navigation
fix(terminal): make copy work in the HTTP web client - #10534
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📥 CommitsReviewing files that changed from the base of the PR and between ef8806226a02d1cc8b512a51824f26059b5c292e and c8f6561bc7e0d545e4d1fcb9baee1a9574c893f2. 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a textarea-based 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 53fbc930-e3af-4069-b7db-2b7633f94c36
📥 Commits
Reviewing files that changed from the base of the PR and between d8e0f11 and ef8806226a02d1cc8b512a51824f26059b5c292e.
📒 Files selected for processing (4)
src/renderer/src/web/web-clipboard-copy-fallback.test.tssrc/renderer/src/web/web-clipboard-copy-fallback.tssrc/renderer/src/web/web-preload-api.test.tssrc/renderer/src/web/web-preload-api.ts
navigator.clipboard only exists in secure contexts, so the web client
served over plain HTTP (e.g. a LAN address) silently dropped every copy:
writeClipboardText resolved successfully without writing anything. This
broke Ctrl/Cmd+Shift+C, context-menu Copy, right-click copy,
copy-on-select, OSC 52, and Copy Pane/Terminal ID on the client PC.
Fall back to document.execCommand('copy') on a temporary textarea — the
only clipboard write available in insecure contexts — mirroring the
paste-side ClipboardEvent fallback (stablyai#9900). Also retry via execCommand
when a secure-context clipboard write is permission-gated, and reject
instead of silently succeeding when no write path exists.
Co-Authored-By: Claude Fable 5 <[email protected]>
textarea.select() clobbers the document selection (chat/diff text in the web client UI; xterm's canvas-internal selection is unaffected). Clone the selection ranges before copying and restore them in finally. Co-Authored-By: Claude Fable 5 <[email protected]>
… hidden textarea
Review fixes on top of the PR's insecure-context copy fallback.
The hidden-textarea approach worked but had three measurable defects, all
reproduced over a real plain-HTTP LAN origin (isSecureContext=false,
navigator.clipboard=undefined) in Chromium 147, Firefox 148, and WebKit 26.4:
1. It clobbered the page's DOM selection whenever focus was in an editable
element. The restore ran before previousFocus.focus(), and refocusing an
input collapses the document selection, undoing the restore. Reproduced in
all three engines with focus in a textarea and in a contenteditable.
2. It was O(text). A 16 MB copy (CLIPBOARD_TEXT_WRITE_MAX_BYTES) blocked the
renderer for 1423ms in Chromium, 2111ms in Firefox, 3511ms in WebKit. The
copy event path does the same write in 13-64ms.
3. It appended a textarea holding the copied text to document.body, where a
MutationObserver installed by any page script observed the value.
Serving the text from a capture-phase copy ClipboardEvent needs no DOM node,
no selection change, and no focus change. The textarea path is kept as a
fallback because WebKit declines execCommand('copy') when nothing is selected,
and its cleanup order is corrected.
Also guards the copy surfaces against the API's new rejection. writeClipboardText
used to resolve unconditionally, so several call sites never attached a handler;
an insecure-context copy with no live user gesture (transient activation is ~5s
on Chromium/Firefox, ~1s on WebKit) now produced 5 unhandled rejections per the
repro, recorded as renderer crash breadcrumbs. Copy Pane ID additionally showed
a success toast for a copy that never happened.
c8f6561 to
fa8e1d2
Compare
|
Reviewed with an independent reproduction over a genuine plain-HTTP LAN origin (not localhost, which counts as a secure context and would have masked the bug). Confirmed: every copy surface resolved successfully while writing nothing, and your tests are load-bearing — 3 fail on revert. One implementation change, pushed to this branch. The hidden-textarea approach carried three defects I measured in Chromium, Firefox and WebKit:
The replacement serves the copy from a capture-phase One claim didn't survive: the PR says "existing callers already swallow that." I measured 5 unhandled rejections per run across all three browsers from the real call shapes — All five surfaces you named still work: shortcut, context-menu copy, copy-on-select, OSC 52, Copy Pane ID. Validation: 152 web tests, 77 terminal copy tests, typecheck 0, oxlint clean. |
|
looking into it |
Reviewed with an independent reproduction over a real plain-HTTP origin. Replaced the hidden-textarea fallback with a capture-phase copy event so clipboard text never enters the DOM, and added rejection handlers to the surfaces that had none.
Fixes #10532 · Related: #9900
User-visible change
Copying from a terminal in the paired web client did nothing when the client was connected over plain HTTP (e.g. a LAN address).
navigator.clipboardonly exists in secure contexts, and the web preload'swriteClipboardTextresolved successfully without writing anything, so every copy surface failed silently on the client PC:Ctrl/Cmd+Shift+C(terminal.copySelection)terminalClipboardOnSelect)This PR adds the copy-side counterpart of #9900 (which fixed paste in the HTTP web client): when
navigator.clipboard.writeTextis unavailable, fall back todocument.execCommand('copy')on a temporary textarea — the only clipboard write available in insecure contexts. When a secure-context write is permission-gated (rejects), retry through the same fallback while the user gesture's transient activation is still live. When no write path exists at all, reject instead of silently succeeding, so callers can react.Scope
src/renderer/src/web/web-clipboard-copy-fallback.ts(new): execCommand copy helper — hidden readonly textarea, focus restore, cleanup on throw.src/renderer/src/web/web-preload-api.ts:writeClipboardTexttries the async clipboard API first, then the fallback; rejects when neither works.Known limitation (out of scope)
Context-menu Paste on an insecure-context web client cannot be fixed: browsers only expose clipboard reads there through a native
pasteClipboardEvent, which a menu click cannot synthesize. KeyboardCtrl/Cmd+Vworks via the #9900 fallback.Tests
web-clipboard-copy-fallback.test.ts(5 tests): copies through the temporary textarea, cleans up and restores focus, reports failure whenexecCommandreturns false / throws / is absent.web-preload-api.test.ts(+3 tests): insecure-context fallback engages, no-write-path rejects with a clear error, permission-gatedwriteTextrejection falls back and still succeeds.pnpm lint,pnpm typecheckpass.pnpm testfull suite passes (35,747 passed; the only 2 failures were insrc/relay/agent-exec-handler.test.tsand are environment-dependent — they compare spawn env against the dev shell's injectedGIT_CONFIG_*vars and pass with a clean environment; unrelated to this change).pnpm buildpasses.Manual validation
Validated on a real paired session: host app (patched web bundle) + browser client over plain
http://<LAN IP>(window.isSecureContext === false,navigator.clipboard === undefined). Terminal copy now lands on the client PC's clipboard, andCtrl/Cmd+Vpaste (#9900 path) still works. Happy to attach a screen recording in a comment if useful.Platform / remote notes
execCommand('copy')is deprecated but supported by Chrome, Edge, Firefox, and Safari, and is the established fallback for insecure contexts.Screenshots
No visual change — no new UI; the fallback textarea is invisible and removed synchronously. See "Manual validation" above for behavior verification.
Code review summary
Reviewed by Claude (Fable 5) during implementation:
src/renderer/src/web/). No Node/Electron APIs, no path handling, no keyboard-chord changes, so macOS/Windows/Linux desktop builds are unaffected; client browsers (Chrome, Edge, Firefox, Safari) all support theexecCommand('copy')fallback. The Electron preload (src/preload/index.ts) and main-process clipboard IPC are untouched.CLIPBOARD_METHODSstays image-only). The SSH/remote image temp-file path andconnectionIdrouting are unchanged. Local Electron copy behavior is unchanged.execCommandcall. Copy-on-select on an insecure-context client triggers this per selection change (xterm can fire several during a drag); bounded, synchronous DOM work with focus restored each time — acceptable, and only on the already-degraded HTTP path.position: fixed,opacity: 0,readonly(no mobile keyboard), removed infinally, and the previously focused element is re-focused so terminal input keeps working after copy (same concern as [Bug]: Terminal loses focus after context menu Copy/Paste #592).pnpm lint, andpnpm typecheckpass.Residual risk: browser clipboard behavior is vendor-dependent; paired-client manual validation over plain HTTP is required in addition to unit tests (matches the residual-risk note in
docs/remote-web-paste-activity-fixes.md).X: @badaverse_dev
🤖 Generated with Claude Code
ELI5
Copy from terminals in the HTTP web client silently failed because the secure clipboard API isn't available on plain HTTP. Copy now falls back so selection and shortcuts work on LAN web clients.