nytimes / svg-crowbar

Extracts an SVG node and accompanying styles from an HTML document and allows you to download it all as an SVG file.
https://nytimes.github.io/svg-crowbar/
MIT License
840 stars 152 forks source link

it works in firefox #9

Open graphicore opened 10 years ago

graphicore commented 10 years ago

I used svg-crowbar with a Firefox version 30.0 (Lubuntu) and it worked with my example. But the project page says "It only works in Chrome."

balubino commented 9 years ago

My understanding is that the script is not guaranteed to work properly in FF. In particular I have experienced problems in two scenarios (but there could be more pitfalls): while reading cssrules from external stylesheets and when more then one svg block are embedded in one page. So if neither of the two conditions are present, i.e. one single svg block with inline style, it may execute and save to .svg without a glitch in Firefox.

In fact this seems the case for many d3js scripts and examples and snippets available from http://bl.ocks.org. Any confirmation of this?

The first problem I mentioned above can instead be observed in various Leaflet examples where svg creation is involved; trying to save the image trigger an error from FF: http://leafletjs.com/examples/geojson.html.

svg-crowbar.js Line: 224 If (ss.cssRules) { "SecurityError: The operation is insecure.".

However wrapping a try {} catch {} around some check code as suggested in this thread http://stackoverflow.com/questions/21642277/security-error-the-operation-is-insecure-in-firefox-document-stylesheets seems to be a viable solution.