I want to override CanvasRenderingContext2D and I'm using this code to do that:
(function() {
var getStackTrace = function() {
var obj = {};
Error.captureStackTrace(obj, getStackTrace);
return obj.stack;
};
var orig_fillText = CanvasRenderingContext2D.prototype.fillText;
CanvasRenderingContext2D.prototype.fillText = function() {
if(arguments !== undefined){
var stackTrace = getStackTrace();
if(stackTrace.indexOf("myText") != -1){
console.log(arguments[0]);
}
}
orig_fillText.apply(this, arguments);
};
}());
That code is working fine if I execute it directly on the console, but is not working if I execute it from my Chrome Extension content script (I'm adding new HTML to the page with the same extension and that part is working, so the chrome extension is not the problem).
I can note my global vars are not shared with the JS from the website either so I guess is related with some type of isolation?