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 checkcopyToClipboard(text)โ write a string to the clipboardcopyElementTextToClipboard(element)โ copy an element's text contentreadFromClipboard()โ read the clipboard's text
See the API reference for full signatures.