question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported.

See original GitHub issue

Bug reports:

I am getting a tainted canvas error, even with the allowTaint flag set to false. Similar to #1409. The url I’m testing is: http://en.miui.com/forum.php I’m not sure how to set up a jsFiddle with this sorry, but I have tested it via a chrome extension using the executeScript functionality.

From extension:

var captureScreenCode = 
  `html2canvas(document.body, {
    allowTaint: false,
    useCORS: false
    }).then(function(canvas) {
    console.log(canvas.toDataURL());
  });`;
chrome.tabs.executeScript(1234, { file: 'html2canvas.js' }, () => {
  chrome.tabs.executeScript(1234, { code: captureScreenCode });
});

Console output of tab:

0ms html2canvas: html2canvas 1.0.0-alpha.10
html2canvas.js:2673 978ms html2canvas: Document cloned, using computed rendering
html2canvas.js:2673 981ms html2canvas: Starting node parsing
html2canvas.js:2673 996ms html2canvas: Added image http://en.miui.com/static/image/miui/base/logo.png
html2canvas.js:2673 1056ms html2canvas: Added image http://en.miui.com/static/image/miui/base/pin_3.gif
html2canvas.js:2673 1063ms html2canvas: Added image http://en.miui.com/static/image/miui/base/rushreply_z.png
html2canvas.js:2673 1066ms html2canvas: Added image http://en.miui.com/static/image/miui/base/hot_3.gif
html2canvas.js:2673 1070ms html2canvas: Added image http://en.miui.com/static/image/miui/base/agree.gif
html2canvas.js:2673 1091ms html2canvas: Added image http://en.miui.com/static/image/miui/base/hot_1.gif
html2canvas.js:2673 1168ms html2canvas: Added image http://en.miui.com/static/image/miui/base/hot_2.gif
html2canvas.js:2673 1290ms html2canvas: Added image http://en.miui.com/static/image/miui/base/pin_2.gif
html2canvas.js:2673 1560ms html2canvas: Added image http://en.miui.com/static/image/miui/base/pin_1.gif
html2canvas.js:2673 1596ms html2canvas: Added image http://en.miui.com/static/image/miui/base/imghack.png
html2canvas.js:2673 1625ms html2canvas: Added image http://en.miui.com/static/image/miui/base/signin_2.png
html2canvas.js:2673 1665ms html2canvas: Added image http://en.miui.com/static/image/miui/base/icon_mi_facebook.jpg
html2canvas.js:2673 1668ms html2canvas: Added image http://en.miui.com/static/image/miui/base/icon_mi_twitter.jpg
html2canvas.js:2673 1676ms html2canvas: Added image http://en.miui.com/static/image/miui/base/icon_mi_gplus.jpg
html2canvas.js:2673 1682ms html2canvas: Added image http://en.miui.com/static/image/miui/base/icon_mi_weibo.jpg
html2canvas.js:2673 1686ms html2canvas: Added image http://en.miui.com/static/image/miui/base/icon_youtube.png
html2canvas.js:2673 1689ms html2canvas: Added image http://en.miui.com/static/image/miui/base/miuiweb.jpg?4
html2canvas.js:2673 1705ms html2canvas: Added image http://en.miui.com/static/image/miui/base/fansStationRetract.png?t=0
html2canvas.js:2673 1711ms html2canvas: Added image http://en.miui.com/static/image/miui/base/fansStationRetract.png??t=0
html2canvas.js:2673 1730ms html2canvas: Added image http://en.miui.com/static/image/miui/base/footer_title.png
html2canvas.js:2673 1778ms html2canvas: Finished parsing node tree
html2canvas.js:2673 1951ms html2canvas: Finished loading 20 images (20) [img, img, img, img, img, img, img, img, img, img, img, img, img, img, img, img, img, img, img, img]
html2canvas.js:2673 1957ms html2canvas: Starting renderer
html2canvas.js:2673 1959ms html2canvas: Canvas renderer initialized (1388x3165 at 0,0) with scale 2
html2canvas.js:2673 2064ms html2canvas: Render completed
VM289:5 Uncaught (in promise) DOMException: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported.
    at <anonymous>:5:24
    at <anonymous>

Specifications:

  • html2canvas version tested with: 1.0.0-alpha.10
  • Browser & version: Google chrome v64.0.3282.140 (Official Build) (64-bit)
  • Operating system: macOS High Sierra v10.13.3

Thanks for all your work on this amazing library.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:10

github_iconTop GitHub Comments

2reactions
zhaosaisaicommented, May 6, 2019

Let us hack it

const TempImage = window.Image

const Image = function() {
      const img = new TempImage()
      img.crossOrigin = 'anonymous'
      return img
}

It works

2reactions
amitguptagwlcommented, Jun 13, 2018

I’ve switched to “dom to image” library which solved my issue. Here is the result match-it

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tainted canvases may not be exported - Stack Overflow
It gives me error: Uncaught SecurityError: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported. What should I do?
Read more >
Failed to execute 'toDataURL' on 'HTMLCanvasElement ...
Bug reports: Uncaught (in promise) DOMException: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported.
Read more >
Resolving "Tainted canvases may not be exported" with Konva
Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported. Unable to get image data from canvas because the canvas has...
Read more >
Tainted canvases may not be exported - Gary Rafferty
Uncaught DOMException : Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported.
Read more >
Failed to execute 'toDataURL' on 'HTMLCanvasElement'
thum:50 Uncaught DOMException : Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported. at getThumb.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found