Each target below registers a Ctrl+V keydown handler that calls
preventDefault() on the keydown and then reads the clipboard via
navigator.clipboard.readText(), appending the result to the
target with the prefix [readText]. This mirrors how xterm.js
handles paste in the VS Code Web / Codespaces integrated terminal.
The three targets differ only in their paste event handler:
paste handler.paste handler appends
clipboardData.getData('text/plain') with prefix
[paste]; does NOT call preventDefault.preventDefault on the paste event.
Expected post-fix behavior, after a single Ctrl+V on each target with the
source text PASTE_ME on the clipboard:
[readText] PASTE_ME.
Pre-fix, the surrogate also synthesizes a paste event after the clipboard
permission is granted. That synthesized event runs the page's paste handler
and, unless the page calls preventDefault on it, also performs
the browser's default paste action (inserting the text into the focused
contenteditable). So pre-fix you'd see PASTE_ME appearing
twice or three times depending on which target.
Source to copy from: