-
-
Save bymaximus/b096672e35e5c4d973cbac7b58199efb to your computer and use it in GitHub Desktop.
Unblock dev tools
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
() => { | |
function isDevToolsScript() { | |
var stack = new Error().stack; | |
return stack.includes('devtool'); | |
} | |
Date.prototype.originalGetTime = Date.prototype.getTime; | |
Date.prototype.getTime = function () { | |
if (!isDevToolsScript()) { | |
return this.originalGetTime(); | |
} | |
return 0; | |
} | |
const originalOnMessageSetter = Object.getOwnPropertyDescriptor(Worker.prototype, 'onmessage').set; | |
Object.defineProperty(Worker.prototype, 'onmessage', { | |
set: function (fn) { | |
if (!isDevToolsScript()) { | |
originalOnMessageSetter.call(this, fn); | |
return; | |
} | |
newFn = (ev) => { | |
ev.data.time = 0; | |
fn(ev); | |
} | |
originalOnMessageSetter.call(this, newFn); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment