ClipboardItem()

Draft
This page is not complete.

The ClipboardItem() constructor of the Clipboard API creates a new ClipboardItem object which represents data to be stored or retrieved via the Clipboard API, that is clipboard.write() and clipboard.read() respectively.

Note: Image format support varies by browser. See the browser compatibility table for the Clipboard interface.

Syntax

var ClipboardItem = new ClipboardItem(ClipboardItemData);

Parameters

ClipboardItemData
An Object with the MIME type as the key and Blob as the value.

Note: To work with text see the Clipboard.readText() and Clipboard.writeText() methods of the Clipboard interface.

Examples

The below example requests a png image using the Fetch API, and in turn, the responses' blob() method, to create a new ClipboardItem and write it to the clipboard, using the Clipboard API.

Note: You can only pass in one clipboard item at a time.

async function writeClipImg() {
  try {
    const imgURL = '/myimage.png';
    const data = await fetch(imgURL);
    const blob = await data.blob();

    await navigator.clipboard.write([
      new ClipboardItem({
        [blob.type]: blob
      })
    ]);
    console.log('Fetched image copied.');
  } catch(err) {
    console.error(err.name, err.message);
  }
}

Specifications

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

Browser compatibility

DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
ClipboardItem() constructor
Experimental
Chrome Full support 66Edge Full support ≤79Firefox No support NoIE No support NoOpera Full support YesSafari No support NoWebView Android Full support 66Chrome Android Full support 66Firefox Android No support NoOpera Android Full support YesSafari iOS No support NoSamsung Internet Android Full support Yes

Legend

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.

See also