ClipboardItem.types

Baseline 2024
Newly available

Since June 2024, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

typesClipboardItem インターフェイスの読み取り専用プロパティで、この ClipboardItem の内容で利用できるMIME タイプの配列 (Array) を返します。

利用できるMIME タイプの配列 (Array) です。

以下の例では、 clipboard.read() メソッドによってクリップボード上のすべての項目を返しています。次に、 types プロパティで利用可能な型を確認し、 ClipboardItem.getType() メソッドを使用して Blob オブジェクトを返しています。指定されたタイプに対応するクリップボードのコンテンツが見つからない場合は、エラーが返されます。

js
async function getClipboardContents() {
  try {
    const clipboardItems = await navigator.clipboard.read();

    for (const clipboardItem of clipboardItems) {
      for (const type of clipboardItem.types) {
        const blob = await clipboardItem.getType(type);
        // we can now use blob here
      }
    }
  } catch (err) {
    console.error(err.name, err.message);
  }
}

仕様書

Specification
Clipboard API and events
# dom-clipboarditem-types

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
types

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

関連情報