pixiebrix-extension icon indicating copy to clipboard operation
pixiebrix-extension copied to clipboard

Clipboard brick: `Failed to read or decode Blob for clipboard item type image/png.`

Open fregante opened this issue 2 years ago • 2 comments

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:

Screenshot 1

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

fregante avatar Nov 03 '23 04:11 fregante

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:

  • undefined makes 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.

fregante avatar Nov 03 '23 04:11 fregante

This issue will be closed in 7 days unless the stale label is removed, or a comment is added to the issue.

github-actions[bot] avatar Feb 13 '24 00:02 github-actions[bot]

This issue will be closed in 7 days unless the stale label is removed, or a comment is added to the issue.

github-actions[bot] avatar Jun 23 '24 00:06 github-actions[bot]

This issue was closed because it has been stale for 7 days with no activity.

github-actions[bot] avatar Jun 30 '24 00:06 github-actions[bot]