ClipboardItem.getType()

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.

getType()ClipboardItem インターフェイスのメソッドで、要求された MIME タイプBlob で解決するプロミス (Promise) を返します。 MIME タイプが見つからない場合はエラーになります。

構文

js
getType(type);

引数

type

有効な MIME タイプです。

返値

Blob オブジェクトで解決するプロミス (Promise)です。

例外

NotFoundError DOMException

type が既知の MIME タイプに一致しない。

TypeError

引数が指定されなかった、または typeClipboardItem のものではない。

次の例では、 clipboard.read() メソッドによってクリップボード上のすべてのアイテムを返しています。そして、 ClipboardItem.types プロパティを利用して 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-gettype

ブラウザーの互換性

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
getType() method

Legend

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

Full support
Full support

関連情報