I know how to intercept a native function in JavaScript. For example, I use the code below to intercept document.createElement
:
var origParseFloat = document.createElement;
document.createElement = function(str) {
alert("Called");
return origParseFloat(str);
}
My question here is that how can I intercept methods of an object.
I mean what if I want to intercept toDataURL()
which is a method for CanvasElement.The code above does not work in this case.
so now the main question is how can I intercept toDataURL()
in a case such as below:
canvas = document.createElement('canvas');
var tdu = canvas.toDataURL();