demo · v133

ClipboardItem with Promise

Click "write" to copy text via a ClipboardItem whose values are Promise<DOMString>. The promise resolves only at write time. Useful when the text needs an async fetch or expensive serialisation.

checking support...

the code

// Chrome 133+: the value can be a Promise that resolves to a DOMString.
const item = new ClipboardItem({
  "text/plain": (async () => {
    await new Promise(r => setTimeout(r, 50));
    return "Hello at " + new Date().toISOString();
  })(),
});
await navigator.clipboard.write([item]);

see also