-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Ignoring errors from <anonymous> files #3147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It should be something along the lines of: Sentry.init({
beforeSend(event) {
try {
if (event.exception.values[0].stacktrace.frames[0].filename === `<anonymous>`) {
return null;
}
} catch (e) {}
return event;
},
}); Please refer to https://github.com/getsentry/sentry-javascript/blob/master/packages/types/src/event.ts for more details on the event type itself. Let me know you still need help. Cheers! |
Great, thanks! I’ll try this 🙂 |
@lobsterkatie Thanks! |
Hello ! we've improved the /* disable errors originating from injected scripts such as Google Tag Manager */
function isInjectedCode(event: Sentry.Event | undefined): boolean {
const frames = event?.exception?.values?.[0]?.stacktrace?.frames;
if (!frames || frames.length === 0) return false;
const firstFrame = frames[0];
if (firstFrame.filename === '<anonymous>') {
return true;
}
const lastFrame = frames[frames.length - 1];
if (
typeof lastFrame.filename === 'string' &&
(lastFrame.filename === window.location.pathname ||
(lastFrame.filename.startsWith(window.location.origin) &&
// static file should not be considered as injected code. We use react-script currently, and all js-generated files are in this "static" directory.
!lastFrame.filename.includes('/static/')))
) {
return true;
}
if (
frames.some(
(frame) =>
typeof frame.filename === 'string' &&
(frame.filename.startsWith('http://www.googletagmanager.com') ||
frame.filename.startsWith('https://googleads.')),
)
) {
return true;
}
return false;
}
Sentry.init({
beforeSend(event, hint) {
if (isInjectedCode(event)) {
return null;
}
return event;
},
}); |
Thanks for your code. I changed http://www.googletagmanager.com to https://www.googletagmanager.com otherwise this does not work. |
We're seeing a lot of errors that have stack traces like this:
Our website uses Google Tag Manager which injects tons of weird crashy stuff into our app that we don't know (or care) about.
I'm assuming that since there's no stack information available for these errors, they have arisen from injected code that for some reason has no accessible source URL (maybe inline or cross origin scripts?).
In any case, it seems like we're unable to do anything about these errors which means they essentially mount up to noise (and lots of it), so we would like to simply ignore these. I haven't been able to find any mention of how to ignore all errors without a source URL in the documentation (https://docs.sentry.io/platforms/javascript/configuration/).
The text was updated successfully, but these errors were encountered: