I appreciate if anyone can tell me how to intercept a function call in javascript. I know it is possible with making use of proxies.
for example I tried the code below to intercept it but now I want to intercept toDataURL()
. in order to call toDataURL you need to create a canvas element first.So, now I want to know how is this possible to define a proxy to intercept toDataURL()
.
Example code to intercept it :
window.x = 0;
let calls = (function(){
let canvas = document.createElement('canvas');
let fun = canvas.toDataURL;
canvas.toDataURL = function(){
window.x++;
return fun.apply(document, arguments);
}
return ()=>calls;
})();