button.addEventListener("click", () => writeClipboardText("<empty clipboard>"));
async function writeClipboardText(text) {
try {
await navigator.clipboard.writeText(text);
} catch (error) {
console.error(error.message);
}
}Clipboard: writeText() method / notebook
Clipboard: writeText() method
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.