mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
test if canvas has become tainted
This commit is contained in:
parent
1447b031c6
commit
c86d12b915
@ -14,23 +14,37 @@
|
|||||||
options.elements = this;
|
options.elements = this;
|
||||||
options.flashcanvas = "../external/flashcanvas.min.js";
|
options.flashcanvas = "../external/flashcanvas.min.js";
|
||||||
|
|
||||||
html2canvas.logging = options && options.logging;
|
html2canvas.logging = options && options.logging;
|
||||||
options.complete = function(images){
|
options.complete = function(images){
|
||||||
var queue = html2canvas.Parse(this[0], images, options),
|
var queue = html2canvas.Parse(this[0], images, options),
|
||||||
$canvas = $(html2canvas.Renderer(queue, options)),
|
$canvas = $(html2canvas.Renderer(queue, options)),
|
||||||
finishTime = new Date();
|
finishTime = new Date();
|
||||||
|
|
||||||
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.siblings().toggle();
|
||||||
|
|
||||||
|
$(window).click(function(){
|
||||||
|
$canvas.toggle().siblings().toggle();
|
||||||
|
throwMessage("Canvas Render " + ($canvas.is(':visible') ? "visible" : "hidden"));
|
||||||
|
});
|
||||||
|
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");
|
||||||
}
|
}
|
||||||
$canvas.css({ position: 'absolute', left: 0, top: 0 }).appendTo(document.body);
|
}
|
||||||
$canvas.siblings().toggle();
|
|
||||||
|
|
||||||
$(window).click(function(){
|
|
||||||
$canvas.toggle().siblings().toggle();
|
|
||||||
throwMessage("Canvas Render " + ($canvas.is(':visible') ? "visible" : "hidden"));
|
|
||||||
});
|
|
||||||
throwMessage('Screenshot created in '+ ((finishTime.getTime()-timer)) + " ms<br />",4000);
|
|
||||||
|
|
||||||
};
|
};
|
||||||
html2canvas.Preload(this[0], options);
|
html2canvas.Preload(this[0], options);
|
||||||
|
Loading…
Reference in New Issue
Block a user