Re: [w3c/clipboard-apis] Arbitrary clipboard types (Issue #165)

Just curious, why can't the author enumerate the `types` after the read operation to see if a particular format is available or not? That way you don't have to add special code for this feature. Here is a sample code (mentioned in the explainer):
```const items = await navigator.clipboard.read()
const item = items[0]
if (item.types.includes("web text/custom")) {
  // prefer this web app's custom markup if available
  const custom_markup = await (await clipboardItem.getType("web text/custom")).text()
  // process the custom markup...
} 
else if (types.includes("web text/html")) {
  // native apps may write "web text/html" in addition to "text/html", prefer it
  const html = await (await clipboardItem.getType("web text/html")).text();
  // process the html...
} 
else if (types.includes("text/html")) {
  // process html if available
  const html = await (await clipboardItem.getType("text/html")).text();
  // process the html...
}

-- 
Reply to this email directly or view it on GitHub:
https://github.com/w3c/clipboard-apis/issues/165#issuecomment-1041846374
You are receiving this because you are subscribed to this thread.

Message ID: <w3c/clipboard-apis/issues/165/1041846374@github.com>

Received on Wednesday, 16 February 2022 16:27:02 UTC