Created
November 28, 2017 15:37
-
-
Save cvazac/4f22883563a334e03365a1c0c478fe92 to your computer and use it in GitHub Desktop.
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() { | |
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