【发布时间】:2021-05-04 22:04:56
【问题描述】:
我正在尝试修改一个函数:
console.error = function() {
return "fake";
}
但是,只需在其上运行 toString() 即可检测到功能已更改:
> console.error.toString()
'function() {\nreturn "fake";\n}'
如果函数没有被修改,则返回'function () { [native code] }'。
一种解决方案可以是覆盖 toString(),但是,可以通过对其运行 toString 来查看 toString 已被覆盖:
> console.error.toString = () => 'function () { [native code] }';
> console.error.toString()
'function () { [native code] }'
> console.error.toString.toString()
"() => 'function () { [ native code ] }'"
是否有递归地重写 toString() 或任何其他方法,使得无法检测到函数被重写?
用例是 WebExtension 修改某些功能,同时使网站尽可能难以检测到它。
【问题讨论】:
-
我认为你唯一的选择是覆盖默认的 Function proptotype 函数 (
Function.prototype.toString)。但是你为什么要这么做呢? -
听起来像an XY problem。你想做什么?
标签: javascript