Last active
January 16, 2024 15:38
-
-
Save jadbaz/ab4636495c835f37d4d182797c8623ca to your computer and use it in GitHub Desktop.
Sentry Vanilla JS example
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset='utf-8'> | |
<title>Sentry JS Example</title> | |
<meta name='viewport' content='width=device-width, initial-scale=1'> | |
<script | |
src="https://browser.sentry-cdn.com/5.16.1/bundle.min.js" | |
integrity="sha384-XeIbINcUQP10HtmVHwZigannjNDpoQRe+uhAoW9J5HU5dHFpilP164LjqO78xtIB" | |
crossorigin="anonymous"> | |
</script> | |
<script type="text/javascript"> | |
Sentry.init({ | |
dsn: "<YOUR_SENTRY_DSN>", | |
beforeSend(event, hint) { | |
if (event.exception) { | |
Sentry.showReportDialog({ eventId: event.event_id }); | |
} | |
return event; | |
} | |
}); | |
console.log("Sentry initialized") | |
Sentry.captureMessage("Initialized Sentry", "info"); | |
function crashAndReportError() { | |
console.log('crashAndReportError'); | |
Sentry.captureException(new Error('Congrats, you broke it')); | |
Sentry.showReportDialog({ }) | |
} | |
</script> | |
</head> | |
<body> | |
<button onclick="crashAndReportError()">Report error</button> | |
<button onclick="crashTheWorld()">Throw unhandled exception</button> | |
</body> | |
</html> |
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset='utf-8'> | |
<title>Sentry JS Minimal Requirements</title> | |
<meta name='viewport' content='width=device-width, initial-scale=1'> | |
<script | |
src="https://browser.sentry-cdn.com/5.16.1/bundle.min.js" | |
integrity="sha384-XeIbINcUQP10HtmVHwZigannjNDpoQRe+uhAoW9J5HU5dHFpilP164LjqO78xtIB" | |
crossorigin="anonymous"> | |
</script> | |
<script type="text/javascript"> | |
Sentry.init({ dsn: "<YOUR_SENTRY_DSN>" }); | |
</script> | |
</head> | |
<body> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can find the latest bundle version here: https://github.com/getsentry/sentry-javascript/tags