-
Notifications
You must be signed in to change notification settings - Fork 560
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
Crash on svg with <use> tags referencing external svg files #425
Labels
Comments
Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can. |
strindhaug
added a commit
to strindhaug/html-to-image
that referenced
this issue
Aug 29, 2023
15 tasks
Absolutely the same issue. Not working with sprites |
+1 |
1 similar comment
+1 |
mvantassel
pushed a commit
to mvantassel/html-to-image
that referenced
this issue
Nov 1, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If the html contains svg with an external svg-file in the use tag then the html-to-image functions crash.
Expected Behavior
I'd expect it to work without issue.
Current Behavior
The javascript crashes, with a message saying something like
Document.querySelector: '/gfx/sprites.svg?v=v123#some-icon' is not a valid selector
Possible Solution
It looks like the code in ensureSVGSymbols blindly assumes the xlink:href attribute is a valid queryselector to an svg element elsewhere in the document.
I'm pretty sure the xlink:href and href attribute is not required to be a valid queryselector since the spec says it's an URL: https://www.w3.org/TR/SVG2/struct.html#UseElementHrefAttribute
and it does work on our website.
The fact that it works when the use-tag refers to an embedded element is mostly an accident.
I'm not quite sure how to fix it so that
ensureSVGSymbols
would work with both files and local references;but at least if you wrapped these two querySelector's in try/catch or verify that the "id" variable is a valid css selector before using it,
it would at least not crash, and you'll still get an image possibly missing a few icons rather than nothing.
Steps To Reproduce
Try to use any of toPng, toJpeg, toBlob, toPixelData, toSvg on html containing an svg defined something like this:
The text was updated successfully, but these errors were encountered: