Clipboard.writeText()

The Clipboard interface's writeText() property writes the specified text string to the system clipboard.

Note: The specification requires the Permissions API be used to obtain the "clipboardWrite" permission before writing to the clipboard. However, exact requirements vary from browser to browser, since this is a new API. Check the compatibility table and Clipboard availability in Clipboard for details.

Syntax

var promise = navigator.clipboard.writeText(newClipText)

Parameters

newClipText
The DOMString to be written to the clipboard.

Return value

A Promise which is resolved once the clipboard's contents have been updated. The promise is rejected if the caller does not have permission to write to the clipboard.

Example

This example sets the clipboard's contents to the string "<empty clipboard>".

navigator.clipboard.writeText("<empty clipboard>").then(function() {
  /* clipboard successfully set */
}, function() {
  /* clipboard write failed */
});

Specifications

Specification Status Comment
Clipboard API and events
The definition of 'writeText()' in that specification.
Working Draft Initial definition.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic supportChrome Full support 66Edge ? Firefox Full support 63
Notes
Full support 63
Notes
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 "clipboardWrite" permission can write to the clipboard at any time.
IE ? Opera Full support 53Safari ? WebView Android No support NoChrome Android Full support 66Edge Mobile ? Firefox Android Full support 63
Notes
Full support 63
Notes
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 "clipboardWrite" permission can write to the clipboard at any time.
Opera Android Full support 53Safari iOS ? Samsung Internet Android ?

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
See implementation notes.
See implementation notes.

Document Tags and Contributors

Contributors to this page: AndreiPetcu, Sheppy, samouss, ExE-Boss, thgh, jpmedley
Last updated by: AndreiPetcu,