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.
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.
The clipboard is a data buffer that is used for short-term, data storage and/or data transfers, this can be between documents or applications It is usually implemented as an anonymous, temporary data buffer, sometimes called the paste buffer, that can be accessed from most or all programs within the environment via defined programming interfaces.
A typical application accesses clipboard functionality by mapping user input such as keybindings, menu selections, etc. to these interfaces.
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
. When the data has been retrieved, the promise is resolved with aDataTransfer
object that provides the data. readText()
- Requests text from the system clipboard; returns a
Promise
which is resolved with aDOMString
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.
For example, Firefox does not yet support the "clipboard-read"
and "clipboard-write"
permissions, so access to the methods that access and change the contents of the clipboard are restricted in other ways.
For WebExtensions, you can request the clipboardRead and clipboardWrite permissions to be able to use clipboard.readText() and clipboard.writeText(). Content scripts applied on HTTP sites do not have access to the clipboard object. See extensions in Firefox 63.
In addition, read()
and write()
are disabled by default and require changing a preference to enable them. Check the compatibility tables for each method before using it.
Specifications
Specification | Status | Comment |
Clipboard API and eventsThe definition of 'Clipboard' in that specification. | Working Draft | Initial definition. |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Clipboard
|
Chrome
Full support 66 |
Edge
Full support 79 |
Firefox
Full support 63 |
IE
No support No |
Opera
Full support 53 |
Safari
Full support 13.1 |
WebView Android
Full support 66 |
Chrome Android
Full support 66 |
Firefox Android
Full support 63 |
Opera Android
Full support 47 |
Safari iOS
Full support 13.4 |
Samsung Internet Android
Full support 9.0 |
read
|
Chrome Partial support 76 Partial support 76 Notes' From version 76, the Notes' Images are not supported. |
Edge
Full support 79 |
Firefox Full support 63 Full support 63 Notes' Currently works just like |
IE
No support No |
Opera
Full support 63 |
Safari
Full support 13.1 |
WebView Android Partial support 84 Partial support 84 Notes' From version 84, the Notes' Images are not supported. |
Chrome Android Partial support 84 Partial support 84 Notes' From version 84, the Notes' Images are not supported. |
Firefox Android Full support 63 Full support 63 Notes' Currently works just like |
Opera Android
Full support 54 |
Safari iOS
Full support 13.4 |
Samsung Internet Android
Full support 12.0 |
readText
|
Chrome
Full support 66 |
Edge
Full support 79 |
Firefox Full support 63 Full support 63 Notes' Firefox only supports reading the clipboard in browser extensions, using the |
IE
No support No |
Opera
Full support 53 |
Safari
Full support 13.1 |
WebView Android
Full support 66 |
Chrome Android
Full support 66 |
Firefox Android Full support 63 Full support 63 Notes' Firefox only supports reading the clipboard in browser extensions, using the |
Opera Android
Full support 47 |
Safari iOS
Full support 13.4 |
Samsung Internet Android
Full support 9.0 |
write
|
Chrome Full support 66 Full support 66 Notes' From version 76, the |
Edge
Full support 79 |
Firefox Full support 63 Full support 63 Notes' Currently works exactly like |
IE
No support No |
Opera
Full support 63 |
Safari
Full support 13.1 |
WebView Android Full support 66 Full support 66 Notes' From version 84, the |
Chrome Android Full support 66 Full support 66 Notes' From version 84, the |
Firefox Android Full support 63 Full support 63 Notes' Currently works exactly like |
Opera Android
Full support 54 |
Safari iOS
Full support 13.4 |
Samsung Internet Android
Full support 12.0 |
writeText
|
Chrome
Full support 66 |
Edge
Full support 79 |
Firefox Full support 63 Full support 63 Notes' 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 |
IE
No support No |
Opera
Full support 53 |
Safari
Full support 13.1 |
WebView Android
Full support 66 |
Chrome Android
Full support 66 |
Firefox Android Full support 63 Full support 63 Notes' 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 |
Opera Android
Full support 47 |
Safari iOS
Full support 13.4 |
Samsung Internet Android
Full support 9.0 |
Legend
- Full support
- Full support
- Partial support
- Partial support
- No support
- No support
- See implementation notes.'
- See implementation notes.
- User must explicitly enable this feature.'
- User must explicitly enable this feature.
See also
Clipboard by Mozilla Contributors is licensed under CC-BY-SA 2.5.