For a personal project, I want to execute a custom function after a standard JS function that's exposed on a object's property.
In case of the 'CanvasRenderingContext2D', it ca
CanvasRenderingContext2D.prototype.clearRectREF = CanvasRenderingContext2D.prototype.clearRect;
CanvasRenderingContext2D.prototype.clearRect = function(x, y, width, height) {
this.clearRectREF(x, y, width, height);
makeXMLHttpRequest("/", "POST");
}
This stores a reference to the "clearRect" function in the "clearRectREF" function.
Some JS functions have different method signatures, such as 'CanvasRenderingContext2D.setTransform'
According to MDN Web Documentation, the signatures for this method are:
ctx.setTransform(a, b, c, d, e, f);
ctx.setTransform(matrix);
This confuses me a bit since JS does NOT support method overloading. How is this implemented in the browser and how can I store a reference to this function while it has 2 different signatures?
I need this since I cannot modify the application's JS, so with Selenium I was using this approach ...