DEV Community

Discussion on: 🎉 How to Copy an Image or a Text to Clipboard in Javascript (2022) ☘️

Collapse
 
mcpat1993 profile image
Patrick McLaren

On the navigator.clipboard.write line I'm getting the following:
Type 'Blob' is missing the following properties from type 'Promise': then, catch, finally, [Symbol.toStringTag] from ts(2739)

Do you have any pointers?

Collapse
 
gnowland profile image
Gifford Nowland

I'm having the same issue, did you find a solution?

Collapse
 
avillapalos profile image
Villapalos

Clipboard API write() is not compatible with Firefox, the only way to be able to copy an image is using the deprecated execCommand() function:

    const img = document.createElement('img')
    img.src = '<YOUR_IMAGE_SRC>'

    const div = document.createElement('div')
    div.contentEditable = 'true'
    div.appendChild(img)
    document.body.appendChild(div)
    this.selectElement(div)
    document.execCommand('copy')
    document.body.removeChild(div)
Enter fullscreen mode Exit fullscreen mode