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

Webkit fails to render SVGs #39

Closed
koppor opened this issue Jun 4, 2013 · 8 comments
Closed

Webkit fails to render SVGs #39

koppor opened this issue Jun 4, 2013 · 8 comments

Comments

@koppor
Copy link

koppor commented Jun 4, 2013

Including SVGs in the HTML leads to a parsing error. Is it possible to add SVG support?

Example SVG:

<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
   <circle cx="100" cy="50" r="40" stroke="black" stroke-width="2" fill="red" />
</svg> 
@cburgmer
Copy link
Owner

cburgmer commented Jun 5, 2013

Thanks for reporting.

As far as I can tell, this is an issue with Webkit. It works fine in Firefox.

Please see this test case: http://jsfiddle.net/cburgmer/c7EcP/4/. Green borders show an <svg> element, an adjacent blue border on the right shows the same SVG as <img> encoded via a data:URI.

It seems that Chrome and Safari in the newest versions don't render an SVG inside another SVG's <foreignObject> if included via an <img> element. This process is employed internally with rasterizeHTML.js to render HTML.

The third column in this test case indicates a possible workaround for Webkit. Here the internal SVG is converted to an <img> element instead of being embeded via a <svg> tag.

I don't think I will get to implementing such a workaround in the near future. Anybody willing to do so can have a look how external image references are embedded as an example.

@cburgmer
Copy link
Owner

cburgmer commented Jun 6, 2013

Of course, if you have a say over the content you can work around that bug yourself. Just replace the SVG with the following image:

'<img src="data:image/svg+xml;charset=utf-8,' + encodeURIComponent(THE_SVG) + '"/>'

This can have side effects with CSS applied to the SVG.

@cipri-tom
Copy link

is there a way to keep the CSS styles while using the workaround?

@cburgmer
Copy link
Owner

If you follow the general idea above, then CSS embedded in the SVG (not linked) should automatically apply.

My thoughts were more around styles applied from the parent document - however it seems that they don't apply across borders anyway.

In case there's still an issue please provide an example on jsfiddle (or similar) and we can have a look at it.

@cipri-tom
Copy link

the styles were not embedded and that is why I had a problem. I stripped them by hand from the stylesheet and added them to the svg. It works now. Thanks for the solution!

@cburgmer
Copy link
Owner

cburgmer commented Apr 7, 2014

Chrome in the mean time seems to work well with the test case I've posted above. Safari still fails.

@sbrown345
Copy link

It looks like this is working in Safari now.

@cburgmer
Copy link
Owner

cburgmer commented May 7, 2016

Thanks, Simon. It also works for me now. Seems WebKit has caught up!

I've updated the docs (https://github.com/cburgmer/rasterizeHTML.js/wiki/Limitations#webkit-origin), and will close the issue.

As always, happy to reopen if necessary.

@cburgmer cburgmer closed this as completed May 7, 2016
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

4 participants