Skip to content

Instantly share code, notes, and snippets.

@oroce
Forked from karolisdzeja/gist:8010574
Last active April 29, 2018 20:51
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oroce/ec3786ba7eff59963842220c3ffc56b4 to your computer and use it in GitHub Desktop.
Save oroce/ec3786ba7eff59963842220c3ffc56b4 to your computer and use it in GitHub Desktop.
Load Raven async
(function (window, document, script, raven, el, first, loaded) {
raven = [];
window.onerror = function e(message, file, line, colno, ex) {
if (loaded) {
return;
}
raven.push([message, file, colno, ex]);
};
el = document.createElement(script);
first = document.getElementsByTagName(script)[0];
el.src = 'https://cdn.ravenjs.com/3.7.0/raven.min.js';
el.onreadystatechange = el.onload = function() {
if (loaded) {
return;
}
loaded = true;
Raven.config('<DSN>', {
release: '<VERSION>',
}).install();
for (var i = 0; i < raven.length; i++) {
var entry = raven[i];
Raven.captureException(entry[4] || new Error(entry[0]), {
extra: {
file: entry[1],
lineno: entry[2],
colno: entry[3]
}
});
}
};
first.parentNode.insertBefore(el, first);
})(window, document, 'script');
@oroce
Copy link
Author

oroce commented Nov 11, 2016

at this point the biggest help would be having traceKitWindowOnError as an exported function from raven, so something like could be done:

for (var i = 0; i < raven.length; i++) {
  Raven.traceKitWindowOnError.apply(Raven, raven[i]);     
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment