-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
toPng and toBlob Not working in Edge (Error) #78
Comments
change your fiddle to have you will most likely find the error is DomException 18. This is likely because the canvas is considered tainted by the time a foreignObject tag is added, and toDataUrl() wont work. |
@kapyaar If your assumption is correct, does this mean Edge is completely unsupported? |
I have been fooling around with this issue for a week now. I posted questions, talked to some experts, etc, and even posted a bounty on SO. :) If you look at html2canvas, it uses the same approach, based on Promise, but the svg returned does not have a foreignObject tag in it. Which makes it possible to run dataUrl request on the canvas. The downside is, that plugin misses out on certain css elements such as clipping hidden overflow content, border, etc. So to answer your question, likely, an unfortunate "YES". I am not familiar with svg in detail. Hopefully the author will look into this. A lot of folks love this plugin. :) |
@kapyaar Thanks for the info. Damn, that's disappointing if so. Let's hope it can be resolved somehow :) |
Hi. Unfortunately, I don't have MS Edge (I'm on Ubuntu), so I currently can't test on it. |
If you post the stacktrace you get maybe we can figure something out |
Here is the output that is given in MS Edge for the jsfiddle posted by @jamesburke-examtime |
I'm getting the same problem with toJpeg, as well. Here's the output for that same jsfiddle, but using jpeg instead: |
It does not matter jpg or png. All of them uses toDataUrl() function. This gets blocked if the browser thinks the canvas is tainted. |
It's working for me in Firefox + Chrome though, so does that mean Edge has a flawed interpretation of canvas tainting? |
@kapyaar @tsayen Nothing is working in IE, Edge. Also .toPng and .toJpeg not working in iPad and iPhone. What is next step for it. I need it very urgent bases so please help me. Your work is awesome but i am facing this issue at few places. In ipad and iphone i convert svg to png. Now working in both but it's a temporary solution. In Edge and IE not working. First i get error |
In edge, it errors with "Promise not found...", due to the fact that IE 11 not exposes promise api? |
Unfortunately the next step (for me) was to switch to another library. All this issues are true, and there is nothing you can do about it as they are browser dependent (canvas and security). |
@kapyaar — out of interest, which library did you switch to? I'm interested to see if there are other options with broader support. |
i am using HTML2Canvas |
HTML2Canvas is unreliable. Even the website says it should not be used for production. I think performance-wise this library is better. however, the issue with toDataUrl() prohibits it being used in IE. tsk. |
Maybe this can be looked into for more information about how to solve this problem. I think that if this is a security issue, Chrome and Firefox will probably block this in the future too. |
I just looked into this more and I've found the general solution here: https://codepen.io/tigt/post/optimizing-svgs-in-data-uris And wrapping the uri in encodeURI will make everything work.
|
@chrisregnier Thanks for sharing the fix. It did work on Edge but I see a lot of strings of %0A scattered across the image. Anyone else have this issue? Please share if anyone could fix it. |
I am expering the same issue with Edge. |
And I with Chrome. I've removed a few by replacing a string with a line break by two |
I haven't looked at this in quite a while, but I just did a quick scan through the code and found this being called when serializing svgs in makeSvgDataUri.
My guess is this is not properly escaping things and should be using the encodeUri method instead. |
I also just realized that stray |
After trying @chrisregnier solution I was able to fix the error caused by the However, even though I don't get an error anymore, the content of the screenshot taken is blank on Edge (and again, it works as expected on Chrome and Firefox). Other than that change, I also did what @GuiRitter suggested to replace that stray for a space by the way, as the encoded URI had messed up things a little and that fixed it. Does anyone have any clue of what might be happening here? No errors are thrown by the lib and I don't see what could be causing the issue. The page that I am trying to take a screenshot from has a lot of SVGs, images and special fonts by the way (such as fontawesome). Thanks! :) |
With the fix by @chrisregnier |
Same issue here : works fine in Firefox/Chrome but I have a "blank" image on MS Edge 44. |
Has anyone solved this problem, I also lost all the pictures~~ |
+1 |
I'm experiencing errors on Edge when attempting to use toBlob or toPng. Running the following jsfiddle gives me the "something went wrong" error: jsfiddle
Using Microsoft Edge 38.14393.0.0.
Works as expected in other Chrome and Firefox.
The text was updated successfully, but these errors were encountered: