I am getting the following error while trying to retrieve the data URL from a canvas on which an SVG image is drawn on Internet Explorer and Safari browsers while the others are working properly.
In addition, the SVG image contains some <image>
elements whose xlink:href
attributes are set to images read from the user's file system as data URLs. Since these images are not located on different domains, i could not think of any reason why this error is thrown when trying to get the dataURL of the canvas on which the SVG image is drawn. Thanks in advance.
SECURITY_ERR: DOM Exception 18: An attempt was made to break through the security policy of the user agent."
I can confirm this issue in Internet Explorer 11 using a test case that I made:
http://jsfiddle.net/tsbXW/
This is a known limitation of Internet Explorer that Microsoft is working on:
https://connect.microsoft.com/IE/feedback/details/828416/cavas-todataurl-method-doesnt-work-after-draw-svg-file-to-canvas
As demonstrated by the bug report, any SVG image drawn into a canvas taints the canvas, causing a SecurityError
when toDataURL() is called.
For what it's worth, the bug report's test case does not work in Safari 7.0.5, either (though purportedly Apple has fixed the issue in Safari 8). Also, the test case does not work in Firefox until version 11 due to Bug 672013 - Allow SVG-as-an-image to be drawn into a canvas without marking it as write-only.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With