Skip to main content

clipboard

Read from and write to the system clipboard via the async Clipboard API.

Import: @rtorcato/browser-common/clipboard

๐Ÿ“– MDN: Clipboard API ยท ๐Ÿ“Š caniuse: async clipboard

Requires a secure context (HTTPS, or localhost in dev). Writing is generally allowed from a user gesture; reading may prompt for permission.

Exampleโ€‹

import {
isClipboardApiAvailable,
copyToClipboard,
readFromClipboard,
} from '@rtorcato/browser-common/clipboard'

if (isClipboardApiAvailable()) {
await copyToClipboard('Copied from the app')
const text = await readFromClipboard()
console.log(text)
}

Exportsโ€‹

  • isClipboardApiAvailable() โ€” feature check
  • copyToClipboard(text) โ€” write a string to the clipboard
  • copyElementTextToClipboard(element) โ€” copy an element's text content
  • readFromClipboard() โ€” read the clipboard's text

See the API reference for full signatures.