I'm trying to override Object() calls in JavaScript, in order to intercept and save all the parameters passed to the object constructor.
I don't have any access to the original code since I am running from an injected code but I do run from the same scope and share the same window of the original code.
I tried this approach:
(function (nativeObject) {
window.Object = function (value) {
if (value.magic) {
window.myMagic = value.magic;
}
return nativeObject(value);
}
})(Object);
as well as saving the original window.Object on window.nativeObject and calling it from within my hook, but in both ways I end up getting:
TypeError: Object.defineProperty is not a function
TypeError: Object.keys is not a function
Uncaught (in promise) TypeError: Object.isExtensible is not a function
Uncaught (in promise) TypeError: Object.create is not a function
Is it because my window.myMagic calls the the Object methods to set the myMagic key in the window object?
Is what I'm trying to do possible?
Objectcalls? That sounds like a really bad idea.XMLHttpRequest,Object, etc - and do some analytics based on it. Is there a smarter way to do this?Objectcalls is unlikely to be effective, since most objects are constructed through other means.myObject.key = ...?keyname, with proxies), but for both you must have control overmyObjectand it only works with assignments. Still not sure what your goal (or even concrete problem) is, so I can't give practical advice.