ClipboardItem.types

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

ブラウザーの互換性

BCD tables only load in the browser

関連情報