How to Prevent Sending JavaScript Errors from Specific Browsers with Sentry raven-js
Tadashi Shigeoka · Thu, December 12, 2019
I’ll introduce sample code for preventing client-side JavaScript errors from specific browsers from being sent with Sentry raven-js.
Background
Using Sentry raven-js
This article discusses raven-js.
Nowadays, @sentry/browser is used instead, so use this for new implementations.
Don't Want to Detect Errors from Unsupported Browsers
Since IE versions before Internet Explorer 11 (IE11) are naturally out of support, the background is that I don’t want client-side JavaScript errors occurring in those browsers to be sent to Sentry.
Not Sending JavaScript Errors from Specific Browsers to Sentry
Sample Code: Don't Send Errors from IE Versions Before IE 11
Raven.config('https://your_dsn@sentry.io/12345', {
shouldSendCallback(data) {
var ua = window.navigator.userAgent.toLowerCase();
// Don't send errors from IE versions before IE11
if (ua.indexOf('msie') !== -1) {
return false;
}
return true;
}
}).install();
That’s all from the Gemba.