I am creating a web application, and I want it to have a feature that allows the user to download screenshots of the page.
I tried to use a library called html2canvas
, and I had written the code as it said on the tutorial, but it returned an error: Uncaught (in promise) DOMException: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported
.
Here's the code that I have written to use html2canvas :
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script>
<div id="Display"></div>
html2canvas(document.querySelector("#Display")).then(canvas => {
const downloadLink = document.createElement("a");
downloadLink.href = canvas.toDataURL("image/png");
downloadLink.click()
});
And this is the library's source code : https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js
Could anyone solve this problem?