Expand description
Handing text to the reader’s clipboard.
The Clipboard API exists only on pages served over HTTPS (or from localhost), and a browser may refuse a write even there. Safari grants the clipboard only inside the click that asked, so the write starts at once, in the handler, never in a task that runs a turn later (Collin, 2026-11-02: the hero’s Copy did nothing in Safari). Where the API is missing, the text is copied the old way, by the copy command, still inside the click, from a textarea the reader never sees: selecting the visible box painted its selection across every line’s whitespace (Collin, 2026-11-02). A page that offers a copy says so when the copy does not happen, and selects the text instead, so the reader’s own copy key finishes the job.
Functions§
- copy
- Put
texton the clipboard. The write starts now, in the caller’s turn; the future says whether the browser took it. When the Clipboard API is not there, the copy command does it at once. - copy_
by_ command - Copy
textwith the browser’s copy command, from a textarea placed off screen for the moment it takes: the way to the clipboard on a page with no Clipboard API, inside a click. Nothing the reader sees is selected. True when the browser says it copied. - select_
contents - Focus the element
idand select the text inside it, from its first character to its last, so the reader can copy it by hand. The selection runs over the text, not the box around it.