Clipboard brick: `Failed to read or decode Blob for clipboard item type image/png.`
Describe the bug
It doesn't look like the clipboard brick is actually able to copy images into the clipboard. Rather, the API itself is broken?
To Reproduce
Try this in your console:
document.onclick = async () => {
const response = await fetch('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAIAAAC0Ujn1AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAEDSURBVEhLtZJBEoMwDAP7lr6nn+0LqUGChsVOwoGdvTSSNRz6Wh7jxvT7+wn9Y4LZae0e+rXLeBqjh45rBtOYgy4V9KYxlOpqRjmNiY4+uJBP41gOI5BM40w620AknTVwGgfSWQMK0tnOaRpV6ewCatLZxn8aJemsAGXp7JhGLBX1wYlUtE4jkIpnwKGM9xeepG7mwblMpl2/CUbCJ7+6CnQzAw5lvD/8DxGIpbMClKWzdjpASTq7gJp0tnGaDlCVzhpQkM52OB3gQDrbQCSdNSTTAc7kMAL5dIDjjj64UE4HmEh1NaM3HWAIulQwmA4wd+i4ZjwdYDR00GqWsyPrizLD76QCPOHqP2cAAAAAElFTkSuQmCC')
const blob = await response.blob()
const image = new Image()
image.src = URL.createObjectURL(blob);
document.body.prepend(image);
navigator.clipboard.write([new ClipboardItem({
[blob.type]: blob
})])
}
The same happens the extension with this setup:
Actual behavior
You'll see that the blob is correctly parsed and even added to the current page after you click on it, but the browser will throw on clipboard.write()
Additional context
I'm trying to test the clipboard brick for https://github.com/pixiebrix/pixiebrix-extension/pull/6808
Strangely, the search results for this error are very limited, only pointing to this unanswered SO question: https://stackoverflow.com/q/75525395/288906
Also I found a couple of issues with the implementation:
-
undefinedmakes it through as a string into the clipboard instead of throwing an error - that the API is restricted to just text/plain, text/html and image.png, so perhaps the brick should be further restricted around these.
This issue will be closed in 7 days unless the stale label is removed, or a comment is added to the issue.
This issue will be closed in 7 days unless the stale label is removed, or a comment is added to the issue.
This issue was closed because it has been stale for 7 days with no activity.