test if canvas has become tainted

This commit is contained in:
Niklas von Hertzen 2012-03-01 18:44:52 +02:00
parent 1447b031c6
commit c86d12b915

View File

@ -23,7 +23,11 @@
if (options && options.profile && window.console && window.console.profileEnd) { if (options && options.profile && window.console && window.console.profileEnd) {
console.profileEnd(); console.profileEnd();
} }
$canvas.css({ position: 'absolute', left: 0, top: 0 }).appendTo(document.body); $canvas.css({
position: 'absolute',
left: 0,
top: 0
}).appendTo(document.body);
$canvas.siblings().toggle(); $canvas.siblings().toggle();
$(window).click(function(){ $(window).click(function(){
@ -32,6 +36,16 @@
}); });
throwMessage('Screenshot created in '+ ((finishTime.getTime()-timer)) + " ms<br />",4000); throwMessage('Screenshot created in '+ ((finishTime.getTime()-timer)) + " ms<br />",4000);
// test if canvas is read-able
try {
$canvas[0].toDataURL();
} catch(e) {
if ($canvas[0].nodeName.toLowerCase() === "canvas") {
// TODO, maybe add a bit less offensive way to present this, but still something that can easily be noticed
alert("Canvas is tainted, unable to read data");
}
}
}; };
html2canvas.Preload(this[0], options); html2canvas.Preload(this[0], options);