dom / latest / clipboard_api.html /

Clipboard API

The Clipboard API provides the ability to respond to clipboard commands (cut, copy, and paste) as well as to asynchronously read from and write to the system clipboard.

Note: This API is not available in Web Workers (not exposed via WorkerNavigator).

This API is designed to supersede accessing the clipboard using document.execCommand().

Accessing the clipboard

Instead of creating a Clipboard object through instantiation, you access the system clipboard through the Navigator.clipboard global:

navigator.clipboard.readText().then(
  clipText => document.querySelector(".editor").innerText += clipText);

This snippet fetches the text from the clipboard and appends it to the first element found with the class editor. Since readText() (and read(), for that matter) returns an empty string if the clipboard isn't text, this code is safe.

Interfaces

Clipboard Secure context

Provides an interface for reading and writing text and data to or from the system clipboard. The specification refers to this as the 'Async Clipboard API.'

ClipboardEvent Secure context

Represents events providing information related to modification of the clipboard, that is cut, copy, and paste events. The specification refers to this as the 'Clipboard Event API'.

ClipboardItem Secure context

Represents a single item format, used when reading or writing data.

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
Clipboard_API
66
79
87
No
53
13.1
66
66
No
47
13.4
9.0
ClipboardItem
66
The ClipboardItem constructor only accepts a blob as the item data, but not strings or Promises that resolve to strings or blobs. See bug 1014310.
79
The ClipboardItem constructor only accepts a blob as the item data, but not strings or Promises that resolve to strings or blobs. See bug 1014310.
87
No
53
The ClipboardItem constructor only accepts a blob as the item data, but not strings or Promises that resolve to strings or blobs. See bug 1014310.
13.1
66
The ClipboardItem constructor only accepts a blob as the item data. Full implementation would also allow for a string or a Promise which resolves with either a string or blob. See bug 1014310.
66
The ClipboardItem constructor only accepts a blob as the item data. Full implementation would also allow for a string or a Promise which resolves with either a string or blob. See bug 1014310.
No
47
The ClipboardItem constructor only accepts a blob as the item data. Full implementation would also allow for a string or a Promise which resolves with either a string or blob. See bug 1014310.
13.4
9.0
The ClipboardItem constructor only accepts a blob as the item data, but not strings or Promises that resolve to strings or blobs. See bug 1014310.
getType
66
79
87
No
53
13.1
66
66
No
47
13.4
9.0
presentationStyle
No
No
87
No
No
13.1
No
No
No
No
13.4
No
types
66
79
87
No
53
13.1
66
66
No
47
13.4
9.0
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
Clipboard_API
58
12
22
4
45
10.1
58
58
22
43
10.3
7.0
ClipboardEvent
58
17
22
No
45
10.1
58
58
22
43
10.3
7.0
clipboardData
58
12
22
5
45
10.1
58
58
22
43
10.3
7.0
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
Clipboard_API
66
79
63
No
53
13.1
66
66
63
47
13.4
9.0
read
86
From version 86, the text/html MIME type is supported.
76
From version 76, the image/png MIME type is supported.
66
Images are not supported.
79
90
Firefox only supports reading the clipboard in browser extensions, using the "clipboardRead" extension permission.
87-90
Firefox only supports reading the clipboard in browser extensions, using the "clipboardRead" extension permission.
63-87
["This method returns a DataTransfer object instead of an array of ClipboardItem objects.", "Firefox only supports reading the clipboard in browser extensions, using the \"clipboardRead\" extension permission."]
No
63
13.1
84
From version 84, the image/png MIME type is supported.
66
Images are not supported.
86
From version 86, the text/html MIME type is supported.
84
From version 84, the image/png MIME type is supported.
66
Images are not supported.
No
54
13.4
12.0
readText
66
79
63
Firefox only supports reading the clipboard in browser extensions, using the "clipboardRead" extension permission.
No
53
13.1
66
66
63
Firefox only supports reading the clipboard in browser extensions, using the "clipboardRead" extension permission.
47
13.4
9.0
write
66
From version 76, the image/png MIME type is supported.
79
87
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.
63
["This method accepts a DataTransfer object instead of an array of ClipboardItem objects.", "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."]
No
63
13.1
66
From version 84, the image/png MIME type is supported.
66
From version 84, the image/png MIME type is supported.
No
54
13.4
12.0
writeText
66
79
63
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.
No
53
13.1
Must be called within user gesture event handlers such as pointerdown or pointerup.
66
66
63
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.
47
13.4
Must be called within user gesture event handlers such as pointerdown or pointerup.
9.0

Clipboard

BCD tables only load in the browser

ClipboardEvent

BCD tables only load in the browser

ClipboardItem

BCD tables only load in the browser

See also

© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API