Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tainted canvas exception when uploading svg file #88

Closed
P1ayer4312 opened this issue Sep 19, 2022 · 1 comment
Closed

Tainted canvas exception when uploading svg file #88

P1ayer4312 opened this issue Sep 19, 2022 · 1 comment

Comments

@P1ayer4312
Copy link

When I try to upload a svg file to sanity using the "Upload assets" option, it fails to upload and throws this error in the console:
Uncaught DOMException: Failed to execute 'toBlob' on 'HTMLCanvasElement': Tainted canvases may not be exported.

I went through the node package, and modified the "createBlob" function inside /node_modules/sanity-plugin-media/dist/utils/generatePreviewBlobUrl.js, I added img.crossOrigin = "Anonymous"; to the image element being sent to the function and it works fine now, but I'm not sure if that's the right way of fixing this issue.

I include the svg file used for testing.
long_text.svg.zip

@robinpyon
Copy link
Collaborator

Thanks for flagging @P1ayer4312!

The issue is specific to the SVG you're trying to upload as it contains <foreignObject> elements.

This SO answer provides a bit more context.

A change has since been made so errors in the preview image generation process won't impede the upload process. Whilst you won't see a preview image when uploading an SVG that contains foreign html elements, you should now be able to upload as normal.

Also worth mentioning that all SVGs uploaded to Sanity are automatically optimised and these elements will be stripped!

robinpyon added a commit that referenced this issue Oct 6, 2022
- fix: correctly infer filename from files containing uppercase extensions, tweak upload card layout
- fix: fix minor regression with tag positioning, dont portal tooltips to prevent overflow issues
- ci: add semver automation workflow
- fix: catch errors when preview images fail to be generated (#88)
- fix: throw an error when trying to call window.crypto from insecure contexts (#50)
- fix: don't hardcode z-indices, correctly render last filter item (#57, #82)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants