diff --git a/src/file.ts b/src/file.ts index ecb7dd7..2cc6f54 100644 --- a/src/file.ts +++ b/src/file.ts @@ -24,7 +24,7 @@ let magic: Promise | string = new Promise((resolve) => { // This script can run before anything on the page, // so setting this function to be non-configurable and non-writable is no use. - target[method] = function (i) { + const hookFn = function (i: number) { const m = this.match(MAGIC_REG) if (m) { resolve(m[2]) @@ -33,6 +33,17 @@ let magic: Promise | string = new Promise((resolve) => { } return _fn.call(this, i) as number } + target[method] = hookFn + + // make hooked methods "native" + const _toString = Function.prototype['toString'] + Function.prototype.toString = function s () { + if (this === hookFn || this === s) { + // "function () {\n [native code]\n}" + return _toString.call(parseInt) as string + } + return _toString.call(this) as string + } }) export const getFileUrl = async (type: FileType, index = 0): Promise => {