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
html2canvas does not render images located in the element #722
Comments
Hi. |
I believe images from other sites are blocked by default because it "taints the HTML5 canvas". Here is the option you need to use when you call the renderer: attribute: allowTaint Found it here: https://html2canvas.hertzen.com/documentation.html. |
same problem.... |
I have faced the same issue, the best way to solve the issue is to run the project on the server and see the result. |
Insert de option allowTaint to view all images into your screenshot
|
I have list of div element in. |
The same problem.Thanks for the solution. |
html2canvas not converting imges given src in base64 format. I have printed the log. Kindly help 1283ms html2canvas: Document cloned html2canvas.js:1487 |
html2canvsas not rendering images given with base64 src, call is not coming back to "onrendered" 1283ms html2canvas: Document cloned html2canvas.js:1487 |
@SebasAlvarez - the allowTaint option doesn't work anymore. Does it still work for you? |
@SebasAlvarez , @sandeepnagra : |
@venkateshduddu - are you shifting the focus to new tab first before taking screenshot? |
@sandeepnagra - no sandeep, am just using click event. one more thing screenshot working if i use local image path but server path not working in new tab. |
@venkateshduddu - a click event won't shift the focus to new tab automatically, you have to trigger that. So try that first, I am 100% sure it will solve your issue. Regarding the server path, is that network drive authenticated? If yes, are you authenticating before uploading files to the network drive? It's a whole different story if you want to upload them to S3 bucket. |
hi when i try to screen an iframe with internal ip camera, it return a void image, please can you help me? |
If I used allowTaint then download option not worked . Please help |
I just fixed this problem. |
Thank you very much @Sotyoyo , My bug was fixed with the above code. THank you Thank you |
@Sotyoyo Thanks a lot bro, god bless you <3 |
@Sotyoyo Thank you so much, its work for me :) |
Image is not render is there any problem in my code ? html2canvas(document.getElementById("html-2-pdfwrapper"), { |
its work! thx! |
that's is right / html2canvas(document.querySelector("#id-of-element"),{ logging: true, letterRendering: 1, allowTaint: false, useCORS: true }).then(canvas => { |
Thanks. It works fine. But I can't clone image style to canvas |
I still face the same issue even after using above options below is my code. |
same to you. Have you solved it? |
same issue with me any help |
I'm seeing the same issue. What am I doing wrong?
|
The below also works if you want to include html2canvas(report, {letterRendering: 1, allowTaint: true, useCORS: true})
.then((canvas) => {
const imgData = canvas.toDataURL('image/png');
// const pdf = new jsPDF();
// pdf.addImage(imgData, 'PNG', 10, 10);
//pdf.save("foo.pdf");
}); |
My content is contains image that come from Aws.s3(). The above mentioned Comments are not working for my case. html2canvas(content, {letterRendering: 1,allowTaint: false,useCORS:true }) The output canvas only contains a blank box instead of image. Any one have a solution for my case? |
same issue here. images coming from S3 bucket |
Thanks |
Access to image at 'https://image/logo link' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. |
For anyone coming here, after trying many things, I found out that for getting images from an external resources ( such as S3 bucket), you have to enable both useCORS = true for html2canvas, and enable CORS policy on the images served from S3. |
I resolved it using the html2canvas proxy. You can see some details on usage and testing here: |
I also had that kind of issue. But now I think I have a solution. Before adding an image to canvas add crossOrigin = 'Anonymous' to the image.Like that: I hope that will also work for you! |
@Sotyoyo Alhamdulillah, thank you broo |
It does not work with early versions. |
This is react project where I have created a card that has some details and hero image! |
Glory to Heroes |
useCORS: true |
html2canvas doesn't evaluate srcset rules and uses only the src values, it also ignores the object-fit style of images |
why? |
Went through the doc and saw that object-fit wasn’t supported, had to switch to media queries instead of the using srcsets rules as there’s no specification that states if html2canvas considers that when processing images. |
Still getting the same issue. |
I found out what is happen even using // img 1- with cors blocked but rendering on html and not downloading using html2canvas
<img
src="https://a-static.mlcdn.com.br/618x463/kit-gamer-razer-battle-bundle-mouse-deathadder-v2-headset-gamer-blackshark-v2-x-mousepad-gigant/formatameupc/kitrz/a78905f66dd2f260c5daa60dd726c80a.jpeg"
>
// img 2- with cors allowed and download using html2canvas
<img
src="https://lh3.googleusercontent.com/acezh821GREUTqwpxvzCnLtRfEkmkLF1aHSj3d8RYRFMvdCA0KL-9IN7XvJnke2agLv3pq-dpU2ceTehC3MFB22EnOgps0UbLVU0ujg=w600"
crossorigin="anonymous"
> html2canvas(div, {
letterRendering: 1,
logging: true,
letterRendering: 1,
useCORS: true,
}).then(function(canvas) {
var myImage = canvas.toDataURL();
downloadURI(myImage, "promo.png");
});
function downloadURI(uri, name) {
var link = document.createElement("a");
link.download = name;
link.href = uri;
document.body.appendChild(link);
link.click();
//after creating link you should delete dynamic link
} the problem is: Now if I use img 2 with And the error I think everyone is having is because we don't have control of the server to allow cors, but we still see html rendered with the image and since it's rendered we believe it can be downloaded. I shared this to see if someone have any insight how to solve it |
me too |
Let's say if I would add text and a background color, then I'd press save, it would show the text and background color, but if I add an image into the div it won't show the image, but still the other things.
The text was updated successfully, but these errors were encountered: