Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(function() {
let userThinkTime = 0
;['alert', 'confirm', 'prompt'].forEach(function(methodName) {
window[methodName] = (function(method) {
return function () {
userThinkTime -= performance.now()
var returnValue = method.apply(window, arguments)
userThinkTime += performance.now()
return returnValue
}
})(window[methodName])
})
window.addEventListener = (function(addEventListener) {
const methodName = 'onbeforeunload'
const handlers = []
addEventListener.call(window, methodName, function () {
let duration = 0
duration -= performance.now()
for (var i = 0; i < handlers.length; i++)
try {
handlers[i]()
} catch (e) {
console.error(e)
}
duration += performance.now()
console.info(methodName, duration, 'userThinkTime', userThinkTime)
})
return function () {
if (arguments[0] === methodName) {
handlers.push(arguments[1])
} else {
addEventListener.apply(window, arguments)
}
}
})(window.addEventListener)
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment