Created
February 25, 2024 12:34
-
-
Save Overmiind/7f3bc27782a3f8c5689140a44f8a9d19 to your computer and use it in GitHub Desktop.
Unblock dev tools
This file contains hidden or 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