Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported.
See original GitHub issueBug 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:
- Created 6 years ago
- Comments:10
Top 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 >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
Let us hack it
It works
I’ve switched to “dom to image” library which solved my issue. Here is the result match-it