Cross Domain images not rendering (No CORS or proxy)
See original GitHub issueHi,
Using the following code images are not rendering cross-domain.
html2canvas($(".canvas-surround"), {
logging: true,
width: 1920 * getScale(),
height: 1080 * getScale(),
useCORS: false,
onrendered: function(canvas) {
var bottomCtx = canvas.getContext("2d");
var topCtx = canvas.getContext("2d");
var bData = bottomCtx.getImageData(0, 0, canvas.width, canvas.height);
var tData = topCtx.getImageData(0, 0, canvas.width, canvas.height);
var merged = mergeData(bData, tData);
bottomCtx.putImageData(merged, 0, 0);
var newImg = canvas.toDataURL("image/png");
console.log(newImg);
var blob = b64toBlob(newImg, "image/png");
console.log(blob);
var blobUrl = URL.createObjectURL(blob);
console.log(blobUrl);
downloadURI(blobUrl);
}
});
Whilst trying to grab images from “http://www.thermmark.co.uk” from “http://www.playgroundmarkingsdirect.co.uk” the images would not render.
When I moved the code over to the “http://www.thermmark.co.uk” website the images rendered (I own both domains)
Any ideas?
Issue Analytics
- State:
- Created 8 years ago
- Comments:26 (3 by maintainers)
Top Results From Across the Web
Allowing cross-origin use of images and canvas - HTML
HTML provides a crossorigin attribute for images that, in combination with an appropriate CORS header, allows images defined by the <img> ...
Read more >How do I handle CORS with html2Canvas and AWS S3 images?
See the edit, I did try setting the crossOrigin attribute with no luck, and I use useCORS set to true (forgot to mention...
Read more >What Is a CORS Error and How to Fix It (3 Ways) - Bannerbear
A CORS error is common when making an HTTP request to another origin. You can get rid of it using one of the...
Read more >3 Ways to Fix the CORS Error — and How the Access-Control ...
Fix one: install the Allow-Control-Allow-Origin plugin. The quickest fix you can make is to install the moesif CORS extension .
Read more >How to win at CORS - JakeArchibald.com
By default, a cross-origin CORS request is made without credentials. So, no cookies, no client certs, no automatic Authorization header, and Set ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi Rookev,
You can do so by passing one of the option in html2canvas function. And trust me this will surely work 😃
html2canvas($(‘#div_pdf’)[0], { useCORS: true, //By passing this option in function Cross origin images will be rendered properly in the downloaded version of the PDF onrendered: function (canvas) { canvasToImageSuccess(canvas); } }); For further info you can have a look at the documentation of the html2canvas library on below URL-: https://html2canvas.hertzen.com/documentation.html
Maybe You should use
useCORS
ptoperty as true, it intended for crossdomained web content