I'm trying to modify a function:
console.error = function() {
return "fake";
}
However, it is possible to detect the function was changed by just running toString()
on it:
> console.error.toString()
'function() {\nreturn "fake";\n}'
If the function hadn't been modified, 'function () { [native code] }'
would be returned instead.
A solution can be to override toString(), however, it is possible to see that toString has been overriden by running toString on it:
> console.error.toString = () => 'function () { [native code] }';
> console.error.toString()
'function () { [native code] }'
> console.error.toString.toString()
"() => 'function () { [ native code ] }'"
Is there anyway to recursively override toString() or any other method such that it is not possible to detect the function was overriden?
The use case would be for a WebExtension to modify some functions while making it as hard as possible for a website to detect it.
Function.prototype.toString
). But why are you trying to do this at all?