W3cubDocs

/Web APIs

Clipboard: readText() method

The Clipboard interface's readText() method returns a Promise which resolves with a copy of the textual contents of the system clipboard.

Syntax

js

readText()

Parameters

None.

Return value

A Promise that resolves with a string 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().

Security

Transient user activation is required. The user has to interact with the page or a UI element in order for this feature to work.

The "clipboard-read" permission of the Permissions API must be granted before you can read data from the clipboard.

Examples

This example retrieves the textual contents of the clipboard and inserts the returned text into an element's contents.

js

navigator.clipboard
  .readText()
  .then((clipText) => (document.getElementById("outbox").innerText = clipText));

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
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

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/readText