Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.8, 6.9
-
None
Description
The `window.navigator.clipboard.write()` API seems to fail with the error NotAllowedError: Failed to execute 'write' on 'Clipboard': Invalid Blob types., at least for text/plain.
https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/write
You can test this in the wild on discord.com (account required) by selecting "Copy Text" from the three dot menu from a text message in a channel.
Edit: discord has switched back to using writeText() now
Here's a test script:
<script type='text/javascript'> function copy(text) { console.log(text) // This doesn't work. // Fails with NotAllowedError: Failed to execute 'write' on 'Clipboard': Invalid Blob types. // But ClipboardItem.supports('text/plain') returns true! window.navigator.clipboard.write( [ new ClipboardItem( { ["text/plain"]: text } ) ] ) } function copytext(text) { // This works. navigator.clipboard.writeText(text) } </script> <div onclick="copy('Text One')">Text One</div> <div onclick="copy('Text Two')">Text Two</div> <div onclick="copytext('Text writeText')">Text writeText</div>