Repository navigation
Make terminal OSC 52 copy reach the system clipboard - #1
Merged
Merged
Conversation
Programs in the integrated terminal copy by emitting OSC 52. xterm's
clipboard addon hands the payload to IClipboardService.writeText with the
type 'clipboard', which the browser implementation filed into an in-memory
map instead of writing out, so on web the copy silently did nothing.
Only the write path changes. readText('clipboard') still returns the
in-memory value, so a read query cannot be used to pull the clipboard back
into the terminal as input.
Needs a secure context: without one navigator.clipboard is undefined and the
execCommand fallback cannot run, since OSC 52 arrives with no user gesture.
ru-sh
force-pushed
the
fix/osc52-clipboard
branch
from
September 18, 2026 06:31
dde81ba to
3f19e51
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Copying from the integrated terminal with OSC 52 silently does nothing on web.
Programs that copy this way (tmux, vim, Claude Code) report success and the
clipboard is unchanged.
Cause
xterm's clipboard addon is loaded for every terminal and hands the payload to
IClipboardService.writeText(text, 'clipboard')(xtermTerminal.ts). Thebrowser implementation opens with:
'clipboard'is not an alternate clipboard, it is the system one, so the writeis filed into a
Mapandnavigator.clipboardis never reached. Electron doesnot have the bug because it forwards the type to
electron.clipboard.The OSC 52 provider is the only caller in the tree that passes
'clipboard',so letting it fall through changes nothing else.
Upstream: microsoft/vscode#318254. Drop
patches/osc52-clipboard.diffwhen afix lands there.
Only the write path
readText('clipboard')keeps returning the in-memory value. Letting readsthrough would mean a program printing
ESC]52;c;?could pull the user'sclipboard back into the terminal as input, which is the usual reason terminals
disable OSC 52 reads.
Requires a secure context
Without HTTPS or localhost,
navigator.clipboardis undefined and theexecCommandfallback cannot run, because OSC 52 arrives asynchronously withno user gesture attached. Chromium works gesture-free in a secure context;
Firefox still requires a gesture and will not copy this way.
Testing
New e2e test in
test/e2e/terminal.test.tsgrants clipboard permissions, typesprintf '\033]52;c;<base64>\a'into a terminal and pollsnavigator.clipboard.readText().Run against a real build over localhost, it fails before the patch
(
Expected: "osc52-…",Received: "") and passes after it.