Skip to content

Instantly share code, notes, and snippets.

@jadbaz
Last active January 16, 2024 15:38
Show Gist options
  • Save jadbaz/ab4636495c835f37d4d182797c8623ca to your computer and use it in GitHub Desktop.
Save jadbaz/ab4636495c835f37d4d182797c8623ca to your computer and use it in GitHub Desktop.
Sentry Vanilla JS example
<!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>
<!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>
@extrawurst
Copy link

where did you get the hash from

@jadbaz
Copy link
Author

jadbaz commented Oct 8, 2022

At this point I don't remember
I must've gotten it from the docs

@YoranSys
Copy link

You can find the latest bundle version here: https://github.com/getsentry/sentry-javascript/tags

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