Description
MDN URL
https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/write
What specific section or headline is this issue about?
Write canvas contents to the clipboard
What information was incorrect, unhelpful, or incomplete?
The example for copying canvas content to clipboard does not work on Safari (presumably on iOS too but I have only been able to test on a macbook).
I get a console error when clicking the blue square - or actually two different error messages. Firstly:
Unhandled Promise Rejection: TypeError: ClipboardItem.supports is not a function. (In 'ClipboardItem.supports("image/png")', 'ClipboardItem.supports' is undefined)
and then if I remove the supports
check I get another error:
NotAllowedError: The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.
There was never a prompt to allow permission.
What did you expect to see?
The blue square would be copied to clipboard successfully
Do you have any supporting links, references, or citations?
I have found various articles/blogs relating to copying to clipboard on safari and seem to indicate that when instantiating a new ClipboardItem, Safari only works if the blob is resolved from a promise. But I have not been able to replicate this successfully.
new ClipboardItem({ [blob.type]: blob })
Some related links below:
- https://web.dev/articles/async-clipboard#demos:~:text=Warning%3A%20Safari,type%3A%20%27foo/bar%27%20%7D))%3B%20%7D)%2C%20%7D)
- https://www.bigbinary.com/blog/copy-generated-image-clipboard-javascript
- https://stackoverflow.com/questions/65356108/how-to-use-clipboard-api-to-write-image-to-clipboard-in-safari
- https://wolfgangrittner.dev/how-to-use-clipboard-api-in-firefox/
Do you have anything more you want to share?
No response
MDN metadata
Page report details
- Folder:
en-us/web/api/clipboard/write
- MDN URL: https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/write
- GitHub URL: https://github.com/mdn/content/blob/main/files/en-us/web/api/clipboard/write/index.md
- Last commit: eaa5b39
- Document last modified: 2025-01-27T15:36:38.000Z