Web/API/Clipboard/writeText

From Get docs


The Clipboard interface's writeText() property writes the specified text string to the system clipboard. Text may be read back using either read() or readText().

The "clipboard-write" permission of the Permissions API, is granted automatically to pages when they are in the active tab.

Note: Browser support for the asynchronous clipboard APIs is still in the process of being implemented. Be sure to check the compatibility table as well as Clipboard availability in Clipboard for more information.


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 eventsThe definition of 'writeText()' in that specification. Working Draft Initial definition.

Browser compatibility

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
writeText Chrome

Full support 66

Edge

Full support 79

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

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

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