Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify how to handle unsupported data types in write(). #128

Open
lgarron opened this issue Jun 26, 2020 · 0 comments
Open

Specify how to handle unsupported data types in write(). #128

lgarron opened this issue Jun 26, 2020 · 0 comments

Comments

@lgarron
Copy link
Contributor

lgarron commented Jun 26, 2020

Right now, the spec is not clear about how unsupported data types should be handled in write().

I think there are a few reasonable options:

  • Return which data types were copied, e.g. give write() a return type of Promise<Array<{[type: string]: boolean}>>.
  • Specify that the browser should error.
  • Specify that the browser should ignore it.

It would also be useful if there was a way to query for supported types (#67), especially in the last case.

Conflicting browser implementations

Consider the following snippet:

document.body.addEventListener("click", async function() {
  console.log("copying!");
  const item = new ClipboardItem({
    "food/falafel": new Blob(["\uD83E\uDDC6"], { type: "food/falafel" })
  });
  await navigator.clipboard.write([item]);
  console.log("copied!");
});

Chrome throws an error. It seems to be DOMException for unknown data types and NotAllowedException for known but unsupported data types.
Screen Shot 2020-06-26 at 16 05 17
Screen Shot 2020-06-26 at 16 26 09

Safari resolves the Promise without an error.
Screen Shot 2020-06-26 at 16 05 57

Note that since the return type is Promise<void>, there is no other way (in general) to check that the copy operation succeeded as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant