Loading raven.js without blocking onload event
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
/** | |
* Setup Js error lazy tracking | |
* - Pros: doesn't block rendering, onload event | |
* - Cons: lower quality error reports for lazy errors | |
* | |
* @author vinhlh | |
* | |
* @param {object} window | |
* @param {object} labJs | |
* @param {string} ravenCdn | |
* @param {string} sentryDsn | |
*/ | |
(function(window, labJs, ravenCdn, sentryDsn) { | |
var errors = []; | |
var oldOnError = window.onerror; | |
window.onerror = function() { | |
errors.push(arguments); | |
oldOnError && oldOnError.apply(this, arguments); | |
}; | |
window.addEventListener('load', function() { | |
labJs | |
.script(ravenCdn) | |
.wait(function() { | |
window.onerror = oldOnError; | |
Raven.config(sentryDsn).install(); | |
errors.forEach(function(args) { | |
window.onerror.apply(this, args); | |
}); | |
}); | |
}); | |
})(window, $LAB, 'raven.min.js', 'https://xxx@sentry.io/9'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment