client-compress icon indicating copy to clipboard operation
client-compress copied to clipboard

Failed to execute 'toBlob' on 'HTMLCanvasElement': Tainted canvases may not be exported

Open devakone opened this issue 6 years ago • 1 comments

On some browser versions (Chrome/Brave), the compression leads to:

DOMException: Failed to execute 'toBlob' on 'HTMLCanvasElement': Tainted canvases may not be exported.

This is due to a CORS security issue as explained here: https://stackoverflow.com/questions/46984372/todataurl-on-htmlcanvaselement-tainted-canvases-may-not-be-exported

In the code for Photo.js the fix would be to

   // Create an object URL which points to the File/Blob image data
    const objectUrl = URL.createObjectURL(this.data)
    const img = new window.Image()
   // Fix CORS error
    img.crossOrigin = 'anonymous';
    await loadImageElement(img, objectUrl)

devakone avatar Dec 21 '18 21:12 devakone

Adding

https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image

For a better explanation of the issue.

devakone avatar Dec 22 '18 21:12 devakone