W3cubDocs

/Web APIs

Clipboard

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

The Clipboard interface implements the Clipboard API, providing—if the user grants permission—both read and write access to the contents of the system clipboard. The Clipboard API can be used to implement cut, copy, and paste features within a web application.

EventTarget Clipboard

The system clipboard is exposed through the global Navigator.clipboard property.

Calls to the methods of the Clipboard object will not succeed if the user hasn't granted the needed permissions using the Permissions API and the 'clipboard-read' or 'clipboard-write' permission as appropriate.

Note: In reality, at this time browser requirements for access to the clipboard vary significantly. Please see the section Clipboard availability for details.

All of the Clipboard API methods operate asynchronously; they return a Promise which is resolved once the clipboard access has been completed. The promise is rejected if clipboard access is denied.

Instance methods

Clipboard is based on the EventTarget interface, and includes its methods.

read()

Requests arbitrary data (such as images) from the clipboard, returning a Promise that resolves with an array of ClipboardItem objects containing the clipboard's contents.

readText()

Requests text from the system clipboard; returns a Promise which is resolved with a string containing the clipboard's text once it's available.

write()

Writes arbitrary data to the system clipboard. This asynchronous operation signals that it's finished by resolving the returned Promise.

writeText()

Writes text to the system clipboard, returning a Promise which is resolved once the text is fully copied into the clipboard.

Clipboard availability

The asynchronous clipboard API is a relatively recent addition, and the process of implementing it in browsers is not yet complete. Due to both potential security concerns and technical complexities, the process of integrating this API is happening gradually in most browsers. See the browser compatibility section below for more information.

In browser extensions, you can access the system clipboard using the WebExtension clipboard API.

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
Clipboard 66 79 63 No 53 13.1 66 66 63 47 13.4 9.0
read
86From version 86, the text/html MIME type is supported.
76From version 76, the image/png MIME type is supported.
66Images are not supported.
79
90Firefox only supports reading the clipboard in browser extensions, using the "clipboardRead" extension permission.
No 63 13.1
84From version 84, the image/png MIME type is supported.
66Images are not supported.
86From version 86, the text/html MIME type is supported.
84From version 84, the image/png MIME type is supported.
66Images are not supported.
No 54 13.4 12.0
readText 66 79
NoFirefox only supports reading the clipboard in browser extensions, using the "clipboardRead" extension permission.
No 53 13.1 66 66
NoFirefox only supports reading the clipboard in browser extensions, using the "clipboardRead" extension permission.
47 13.4 9.0
write
66From version 76, the image/png MIME type is supported.
79
87Writing 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.
63["This method accepts a DataTransfer object instead of an array of ClipboardItem objects.", "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."]
No 63 13.1
66From version 84, the image/png MIME type is supported.
66From version 84, the image/png MIME type is supported.
No 54 13.4 12.0
writeText 66 79
63Writing 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.
No 53
13.1Must be called within user gesture event handlers such as pointerdown or pointerup.
66 66
63Writing 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.
47
13.4Must be called within user gesture event handlers such as pointerdown or pointerup.
9.0

See also

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Clipboard