Skip to content

Instantly share code, notes, and snippets.

@kossnocorp
Created April 25, 2020 09:58
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 kossnocorp/4008fdb47558dc79762792ad1faf6804 to your computer and use it in GitHub Desktop.
Save kossnocorp/4008fdb47558dc79762792ad1faf6804 to your computer and use it in GitHub Desktop.
var errorsStash = []
var errorListener = function(e) {
errorsStash.push(e.error)
}
var unhandledRejectionListener = function(e) {
errorsStash.push(e.reason)
}
window.addEventListener('error', errorListener)
window.addEventListener('unhandledrejection', unhandledRejectionListener)
window.__passOnToSentry__ = function() {
delete window.__passOnToSentry__
window.removeEventListener('error', errorListener)
window.removeEventListener('unhandledrejection', unhandledRejectionListener)
return errorsStash
}
<script src="https://browser.sentry-cdn.com/5.15.5/bundle.min.js" integrity="xyz" crossorigin="anonymous"></script>
Sentry.init({ dsn: 'https://xxx@yyy.ingest.sentry.io/zzz' });
var errors = window.__passOnToSentry__()
for (var i = 0; i < errors.length; i++) {
Sentry.captureException(errors[i])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment