Skip to content

Instantly share code, notes, and snippets.

@vinhlh
Created December 6, 2016 06:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vinhlh/2e53e5ca299095c6b6ef62199c8cd230 to your computer and use it in GitHub Desktop.
Save vinhlh/2e53e5ca299095c6b6ef62199c8cd230 to your computer and use it in GitHub Desktop.
Loading raven.js without blocking onload event
/**
* 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