W3cubDocs

/DOM

Clipboard API

The Clipboard API provides the ability to respond to clipboard commands (cut, copy, and paste) as well as to asynchronously read from and write to the system clipboard. Access to the contents of the clipboard is gated behind the Permissions API; without user permission, reading or altering the clipboard contents is not permitted.

This API is designed to supersede accessing the clipboard using document.execCommand()

Accessing the clipboard

Instead of creating a Clipboard object through instantiation, you access the system clipboard through the Navigator.clipboard global:

navigator.clipboard.readText().then(
  clipText => document.queryElementSelector(".editor").innerText += clipText);

This snippet fetches the text from the clipboard and appends it to the first element found with the class "editor". Since readText() (and read(), for that matter) returns an empty string if the clipboard isn't text, this code is safe.

Interfaces

Clipboard Secure context
Provides an interface for reading and writing text and data to or from the system clipboard. The specification refers to this as the 'Async Clipboard API.'
ClipboardEvent Secure context
Represents events providing information related to modification of the clipboard, that is cut, copy, and paste events. The specification refers to this as the 'Clipboard Event API'.

Specifications

Specification Status Comment
Clipboard API and events Working Draft Initial definition.

Browser compatibilityUpdate compatibility data on GitHubUpdate compatibility data on GitHub

Clipboard

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
Basic support 66 ? 63 ? 53 ?
read No ? 63
Disabled
63
Disabled
Currently works just like readText(); non-text content is not currently supported.
Disabled From version 63: this feature is behind the dom.events.asyncClipboard.dataTransfer preference (needs to be set to true). To change preferences in Firefox, visit about:config.
? No ?
readText 66 ? 63
63
Firefox only supports reading the clipboard in browser extensions, using the "clipboardRead" extension permission.
? 53 ?
write No ? 63
Disabled
63
Disabled
Currently works exactly like writeText(), including the availability limitations currently imposed by Firefox.
Disabled From version 63: this feature is behind the dom.events.asyncClipboard.dataTransfer preference (needs to be set to true). To change preferences in Firefox, visit about:config.
? No ?
writeText 66 ? 63
63
Writing to the clipboard is available without permission in secure contexts and browser extensions, but only from user-initiated event callbacks. Browser extensions with the "clipboardWrite" permission can write to the clipboard at any time.
? 53 ?
Mobile
Android webview Chrome for Android Edge Mobile Firefox for Android Opera for Android iOS Safari Samsung Internet
Basic support No 66 ? 63 53 ? ?
read No No ? 63
Disabled
63
Disabled
Currently works just like readText(); non-text content is not currently supported.
Disabled From version 63: this feature is behind the dom.events.asyncClipboard.dataTransfer preference (needs to be set to true). To change preferences in Firefox, visit about:config.
No ? ?
readText No 66 ? 63
63
Firefox only supports reading the clipboard in browser extensions, using the "clipboardRead" extension permission.
53 ? ?
write No No ? 63
Disabled
63
Disabled
Currently works exactly like writeText(), including the availability limitations currently imposed by Firefox.
Disabled From version 63: this feature is behind the dom.events.asyncClipboard.dataTransfer preference (needs to be set to true). To change preferences in Firefox, visit about:config.
No ? ?
writeText No 66 ? 63
63
Writing to the clipboard is available without permission in secure contexts and browser extensions, but only from user-initiated event callbacks. Browser extensions with the "clipboardWrite" permission can write to the clipboard at any time.
53 ? ?

ClipboardEvent

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
Basic support Yes Yes Yes 4 Yes Yes
ClipboardEvent() constructor 58 ? Yes ? 45 ?
clipboardData Yes Yes 22 5 Yes Yes
Mobile
Android webview Chrome for Android Edge Mobile Firefox for Android Opera for Android iOS Safari Samsung Internet
Basic support Yes Yes Yes Yes Yes Yes Yes
ClipboardEvent() constructor 58 58 ? Yes 45 ? ?
clipboardData Yes Yes Yes 22 Yes Yes ?

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API