The Clipboard interface's readText() method returns a Promise which resolves with a copy of the textual contents of the system clipboard.. The "clipboard-read" permission of the Permissions API must be granted before you can read data from the clipboard.
Syntax
var promise = navigator.clipboard.readText()
Parameters
None.
Return value
A Promise that resolves with a DOMString containing the textual contents of the clipboard. Returns an empty string if the clipboard is empty, does not contain text, or does not include a textual representation among the DataTransfer objects representing the clipboard's contents.
To read non-text contents from the clipboard, use the read() method instead. You can write text to the clipboard using writeText().
Example
This example retrieves the textual contents of the clipboard and inserts the returned text into an element's contents.
navigator.clipboard.readText().then(
clipText => document.getElementById("outbox").innerText = clipText);
Specifications
| Specification | Status | Comment |
| Clipboard API and eventsThe definition of 'readText()' 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 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 |
Legend
- Full support
- Full support
- No support
- No support
- See implementation notes.'
- See implementation notes.
See also
- Clipboard API
- Async Clipboard API demo on Glitch
- Image support for Async Clipboard article
Clipboard.writeText()Clipboard.write()
Clipboard.readText() by Mozilla Contributors is licensed under CC-BY-SA 2.5.