exupero / saveSvgAsPng

Save SVGs as PNGs from the browser.
MIT License
1.09k stars 362 forks source link

Using `canvg` breaks Safari 12 #224

Closed ryanfitzer closed 4 years ago

ryanfitzer commented 4 years ago

I added it for IE11 support, which works. But that causes Safari to error out with:

SyntaxError: The string did not match the expected pattern.

Is there a conditional I can use to add canvg? For example:

const options = someCondition ? { canvg: canvg } : {};
saveSvgAsPng( svg, 'svg.png', options );

I'm not exactly clear on what IE11 doesn't support that requires canvg to be used other than the error Rendered SVG images cannot be downloaded.

I've looked through both codebases but I haven't figured out some sort of feature test I can use to target IE11.

Any guidance would be appreciated.

ryanfitzer commented 4 years ago

Here's what I ended up going with:

const options = ( typeof window.navigator.msSaveBlob !== 'undefined' ) ? { canvg: canvg } : {};
saveSvgAsPng( svg, 'svg.png', options );