Skip to content

Instantly share code, notes, and snippets.

@cvazac
Created November 28, 2017 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cvazac/4f22883563a334e03365a1c0c478fe92 to your computer and use it in GitHub Desktop.
Save cvazac/4f22883563a334e03365a1c0c478fe92 to your computer and use it in GitHub Desktop.
(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