-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
CORS #1544
Comments
I fixed some cors issues I was having with the combination of Google Chrome, AWS S3, and multiple origins. I found this stackoverflow thread: Which links to this bug report: Anyhow as workaround solution you can try this modified version of html2canvas: use the options:
Hope that helps. FYI, this will add the current time stamp to cors image urls to sidestep a cache issue I was having on Chrome... Which means it will effect performance by re-downloading those images... |
Thank you @CrandellWS
Please make sure that you image is returning CORS enable headers. Otherwise you have to add CORS policy to your s3 bucket. |
Thank you @Pritam1994 |
Hi, I have added the following options -
Bit it is not showing captcha. Instead a blank box. |
Without modifying html2canvas, here is an idea: // 1.First get the Base64 encoding of cross-domain pictures through canvas
const img = new Image();
img.onload = () => {
const c = this.$refs.crossImg;
const ctx = c.getContext('2d');
ctx.drawImage(img, 0, 0, c.width, c.height);
this.crossImgBase64 = c.toDataURL('image/png');
// 2.Draw
Html2canvas(this.$refs.html, {
// useCORS: true,
}).then((canvas) => {
this.pngBase64 = canvas.toDataURL('image/png');
this.isShowPng = true;
});
};
img.crossOrigin = 'anonymous';
img.src = 'https://secure.gravatar.com/avatar/03af4ed2fa8526e9f37c847cc4083141'; Here a example |
I am using version 1.0.0-rc.0 and just adding @CrandellWS's solution didn't work if (!supportsDataImages || useCORS){
img.crossOrigin = 'anonymous';
}
img.onerror = reject;
img.src = src; Adding src alone won't work, the code has to be like this if (!supportsDataImages || useCORS){
img.crossOrigin = 'anonymous';
img.src = src +'?v='+new Date().getTime();
}
else{
img.src = src;
}
img.onerror = reject; |
It seems it is not fixed yet. |
been stuck for days and finally found the solution from here: in addition, I added: useCORS: true and on the img tag: <img imageUrl + '?time=' + new Date().valueOf() crossorigin='anonymous'> hope this helps |
@yulisartika Well, when i put |
@SalahAdDin as @yulisartika said and on the img tag: <img imageUrl + '?time=' + new Date().valueOf() crossorigin='anonymous'> setting the image url to have an unique parameter is key |
Adding crossOrigin="" did it for me. |
@arohablue for me did not =´( |
We had to make a proxy server. |
For me the image is stored on WAS so I also added a cors filter there and used the below to fetch it. |
As i need to get screenshot for iframe from other page but its in same domain but then also getting this error:- Failed to execute 'open' on 'Document': Can only call open() on same-origin documents Getting this error on html2canvas any help appreciated |
Proxy server I would say. |
Has anyone had the same situation as me? |
for people still having the issue, for me what worked was a mix of some replies here.. I have:
plus |
@RSchneider94 i wish it wa that easy for some reason when I have @memsenpai I have the exact same issue as you my S3 bucket has AllowOrigin wildcard |
For me was the response!! |
@xrzhuang I must use a server as a proxy to solve that issue :( |
For anyone who may have run into this seemingly simple issue. As long your application can make cross origin requests fine and your only issue is html2canvas not being able to reach those URLs, you can convert your visible images to data URLs prior to the canvas printing to bypass the need for html2canvas to fetch them cross origin. This is the only way I was able to get around this without proxy or reworking CORS in my functions or server. --
|
Thanks! I solved my problem sending the URL to the server, download on the server, convert to dataURL and return to the frontend. |
i'm trying to take a shot of a google recaptcha challenge loaded by iframe from another iframe, already used allowTaint and useCORS, and all i get is a error.
0ms html2canvas: html2canvas 1.0.0-alpha.12
10ms html2canvas: DOMException: Failed to execute 'open' on 'Document': Can only call open() on same-origin documents.
DOMException: Failed to execute 'open' on 'Document': Can only call open() on same-origin documents.
The text was updated successfully, but these errors were encountered: