0

I made the code and with liveserver I can download it, but when I open it without the VisualStudio extension, the following error appears in the console:

Uncaught (in promise) DOMException: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported.

HTML Code HTML

document.getElementById("dl-png").onclick = function() {
  const screenshotTarget = document.getElementById("htmlContent");

  html2canvas(screenshotTarget).then((canvas) => {
    const base64image = canvas.toDataURL("image/png");
    var anchor = document.createElement('a');
    anchor.setAttribute("href", base64image);
    anchor.setAttribute("download", "Cartão_Aniversário-" + nameClient.value + ".png");
    anchor.click();
    anchor.remove();
  });
};

I want to download after changes, but the page is blank

  • The duplicate has a lot of reasons why this may be happening. My guess would be you're running this HTML on your local machine file path (C:\yoursite\canvas.html) instead of on a local web server. – Rory McCrossan Jan 30 '23 at 12:12

0 Answers0