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.
Browser supportโ
| API | Chrome | Edge | Firefox | Safari | iOS Safari | Baseline |
|---|---|---|---|---|---|---|
Clipboard.writeText | โ 66+ [1,2] | โ 79+ [1,2] | โ 63+ [3,4] | โ 13.1+ [3] | โ 13.4+ [3] | Widely available |
Clipboard.readText | โ 66+ [5] | โ 79+ [5] | โ 125+ [3,6,7] | โ 13.1+ | โ 13.4+ | Newly available |
- Chrome, Edge: From version 107, this method must be called within user gesture event handlers, or the user must grant the clipboard-write permission.
- Chrome, Edge: Before version 107, the user must grant the clipboard-write permission.
- Firefox, Safari, iOS Safari: This method must be called within user gesture event handlers.
- Firefox: Web extensions with the clipboardWrite permission in their manifest can write data without a user gesture.
- Chrome, Edge: The user must grant the clipboard-read permission.
- Firefox: A paste prompt is displayed when the clipboard is read. If the clipboard contains same-origin content, the prompt is suppressed.
- Firefox: Web extensions with the clipboardRead permission in their manifest can read data without the paste prompt displaying. Prior to Firefox 147, extensions without this permission were unable to read clipboard data.
Needs: a user gesture, a permission grant
โ
supported ยท โ partial ยท โ not supported ยท [n] see note. Generated from MDN browser-compat-data and web-features. caniuse: Clipboard.writeText ยท Clipboard.readText
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.