10LOC

#clipboard-api

Web Platformintermediate

navigator.clipboard for real copy/paste, no execCommand

export const copyToClipboard = (text: string) =>
  navigator.clipboard.writeText(text).then(() => true).catch(() => false);

export const pasteFromClipboard = () =>
  navigator.clipboard.readText().then((text) => text).catch(() => null);

Copy text, read it back, and copy raw image data to the system clipboard with a promise-based API — no hidden textarea, no execCommand.