diff --git a/src/anti-detection.ts b/src/anti-detection.ts index 2e3ee1f..aa8d18d 100644 --- a/src/anti-detection.ts +++ b/src/anti-detection.ts @@ -7,31 +7,26 @@ export const makeNative = (() => { const l: Set = new Set() - const target = Function.prototype - const method = 'toString' - const _toString = target[method] - const toString = function () { - if (l.has(this)) { - // "function () {\n [native code]\n}" - return _toString.call(parseInt) as string + hookNative(Function.prototype, 'toString', (_toString) => { + return function () { + if (l.has(this)) { + // "function () {\n [native code]\n}" + return _toString.call(parseInt) as string + } + return _toString.call(this) as string } - return _toString.call(this) as string - } - target[method] = toString - - // make `Function.prototype.toString` itself "native" - l.add(toString) + }) return (fn: Function) => { l.add(fn) } })() -export const hookNative = ( +export function hookNative ( target: T, method: M, hook: (originalFn: T[M], detach: () => void) => T[M], -): void => { +): void { // reserve for future hook update const _fn = target[method] const detach = () => { @@ -43,5 +38,7 @@ export const hookNative = ( const hookedFn = hook(_fn, detach) target[method] = hookedFn - makeNative(hookedFn as any) + setTimeout(() => { + makeNative(hookedFn as any) + }) }