(
target: T,
method: M,
hook: (originalFn: T[M], detach: () => void) => T[M],
async = false
)
| 33 | })(); |
| 34 | |
| 35 | export function hookNative<T extends object, M extends keyof T>( |
| 36 | target: T, |
| 37 | method: M, |
| 38 | hook: (originalFn: T[M], detach: () => void) => T[M], |
| 39 | async = false |
| 40 | ): void { |
| 41 | // reserve for future hook update |
| 42 | const _fn = target[method]; |
| 43 | const detach = () => { |
| 44 | target[method] = _fn; // detach |
| 45 | }; |
| 46 | |
| 47 | // This script can run before anything on the page, |
| 48 | // so setting this function to be non-configurable and non-writable is no use. |
| 49 | const hookedFn = hook(_fn, detach); |
| 50 | target[method] = hookedFn; |
| 51 | |
| 52 | if (!async) { |
| 53 | makeNative(hookedFn as any, _fn as any); |
| 54 | } else { |
| 55 | setTimeout(() => { |
| 56 | makeNative(hookedFn as any, _fn as any); |
| 57 | }); |
| 58 | } |
| 59 | } |
no outgoing calls
no test coverage detected