niklasvh / html2canvas

Screenshots with JavaScript
https://html2canvas.hertzen.com/
MIT License
30.58k stars 4.81k forks source link

Image is not generated by html2canvas in firefox without giving any errors #2046

Open po95-backup opened 5 years ago

po95-backup commented 5 years ago

Here is my code of generating a image on chrome, firefox and other browsers. When i click on my function to generate a image in firefox, the browser holds the request and after sometime it prints some outputs without downloading the image

var node = document.querySelector("#pop-up-table");
            html2canvas(node, {}).then(function(canvas){
                var userAgent = navigator.userAgent;
                var a = document.createElement('a');
                if(userAgent.search('Chrome') >= 0){
                    a.href = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream");
                    a.download = 'table.png';
                } else {
                    a.href = canvas.toDataURL("image/jpeg").replace("image/jpeg", "image/octet-stream");
                    a.download = 'table.jpg';
                }
                a.click();
            });

I modified the code slightly for firefox (will generate jpg for firefox and other browsers) other than chrome because of a claim on a comment in this post (here)

16df332f834 0ms Starting document clone                                   html2canvas.min.js:20:84099
16df332f834 3798ms Document cloned, using computed rendering              html2canvas.min.js:20:84099
16df332f834 3799ms Starting DOM parsing                                   html2canvas.min.js:20:84099
16df332f834 10556ms Starting renderer                                     html2canvas.min.js:20:84099
16df332f834 10557ms Canvas renderer initialized 
(770x1184 at 197,96.60000610351562)with scale 1                           html2canvas.min.js:20:84099
16df332f834 27498ms Finished rendering                                    html2canvas.min.js:20:84099

Have seen these solutions below but it didn't bring any good:

NB: I call this code snippet in a setTimeout() function and increasing time didn't help

drxcheng commented 5 years ago

same

praveenkumarhopscotch commented 4 years ago

same problem facing

swvv commented 4 years ago

same

UserHuRu commented 4 years ago

same~ but is sometimes in mobile

gillespieza commented 4 years ago

me too

JordanBoulan commented 3 years ago

same problem. I tried using 'image/jpeg', but still not working for me. image

chua1989 commented 2 years ago

same to me

sharmavj89 commented 1 year ago

Facing similar issue on ios (all browsers) but working fine on every other device. Anyone found a solution yet?

MeexReay commented 1 month ago

same

UserHuRu commented 1 month ago

邮件已成功收到啦~胡茹茹