feat(site): add OSC 52 clipboard support to web terminal - #26437
Conversation
Register an OSC 52 handler on the xterm.js parser so that programs like tmux can copy text to the browser's system clipboard via escape sequences. The handler decodes the base64 payload and writes it using the existing copyToClipboard utility, which provides an HTTP fallback for insecure contexts. Closes #16577
aqandrew
left a comment
There was a problem hiding this comment.
Clean, well-scoped feature. The OSC 52 parsing is correct, the UTF-8 decode path via Uint8Array.from(atob(...)) + TextDecoder handles multi-byte characters properly, and the test exercises the real xterm parser end-to-end. Good reuse of the existing copyToClipboard utility.
2 P3s and 1 nit across 3 inline comments.
Fix comment accuracy: 'let the default handler run' to 'ignore' since xterm.js has no built-in OSC 52 handler. Restore navigator.clipboard after test using save/restore pattern in a scoped describe block. Add edge-case tests for missing separator, clipboard read query, and invalid base64.
Documentation CheckUpdates Needed
Automated review via Coder Agents |
ThomasK33
left a comment
There was a problem hiding this comment.
I think it looks good, but I don’t have enough context or knowledge to assess the change confidently.
If you’re confident about it and just need a quick stamp of approval, let me know.
|
I wasn't 100% comfortable merging this until somebody could verify it working manually, but we're good now! 🙂 I just successfully did this with @jeremyruppel: repro steps
|
Registers an OSC 52 handler on the xterm.js terminal parser so that programs like tmux can copy text to the browser's system clipboard via escape sequences (e.g.
printf "\\033]52;c;$(echo -n 'Coder is Cool' | base64)\\a").The handler decodes the base64 payload and writes it using the existing
copyToClipboardutility, which provides an HTTP fallback for insecure contexts. Clipboard read queries (?) are ignored since responding would require writing back to the PTY.No new dependencies are needed; xterm.js 5.5.0 already exposes
terminal.parser.registerOscHandler.Closes #16577
Generated by Coder Agents on behalf of @aqandrew.
relevant context from agent chat, summarized by me
ref DEVEX-465
Installing @xterm/addon-clipboard would have been another way to implement this feature. This would follow established addon-loading patterns in
WorkspaceTerminal:coder/site/src/modules/terminal/WorkspaceTerminal.tsx
Lines 232 to 241 in 612b6d4
However, registering a custom handler instead has a few advantages re: security and flexibility:
payload === "?") prevents processes in the workspace from reading the user's clipboard without consentThe approach/tests seem sound to me. I would just ask that someone among reviewers manually test this with tmux, since I'm not a tmux user 🙏🏽