clipboard-apis
clipboard-apis copied to clipboard
Specify how to handle unsupported data types in `write()`.
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 ofPromise<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.

Safari resolves the Promise without an error.

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.