比如 XMLHttpRequest,有没有什么手段可以知道这个东西有没有被人为重写?
网站找了不少方法都做不到
下面是我做的一些尝试,这些检测方法都能被绕过
{ function isNative(api) { return /native code/.test(api.toString()) && typeof api !== 'undefined' } let test = function (input, fake) { console.log("------------------------") console.log("是否是伪造:", fake) console.log("toString:", input.toString()) console.log("toString.toString:", input.toString) console.log("prototype 方法", input.hasOwnProperty("prototype")) console.log("toString.call","方法",Function.prototype.toString.call(input)) console.log("网传最不靠谱方法:isNative", isNative(input)) } test(XMLHttpRequest, false) { let XMLHttpRequest = function () { "[native code]" } XMLHttpRequest.toString = function () { return "function XMLHttpRequest() { [native code] }" } let toString = function () { return "function toString() { [native code] }" } toString.toString = toString XMLHttpRequest.toString.toString = toString Function.prototype.toString = toString delete XMLHttpRequest.prototype test(XMLHttpRequest, true) // XMLHttpRequest.prototype = undefined // test(XMLHttpRequest, true) } } 