Skip to content

Commit 380487f

Browse files
authored
feat: Suppress third-party ad script errors in Sentry
1 parent 7aa5178 commit 380487f

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/router.tsx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,46 @@ export function getRouter() {
5858
// Session Replay
5959
replaysSessionSampleRate: 0.1, // This sets the sample rate at 10%. You may want to change it to 100% while in development and then sample at a lower rate in production.
6060
replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur.
61+
// Filter out known third-party ad script errors
62+
beforeSend(event, hint) {
63+
const error = hint.originalException
64+
const errorMessage =
65+
typeof error === 'string'
66+
? error
67+
: error instanceof Error
68+
? error.message
69+
: ''
70+
71+
// Check if the error comes from third-party ad scripts
72+
const frames = event.exception?.values?.[0]?.stacktrace?.frames || []
73+
const isAdScriptError = frames.some((frame) => {
74+
const filename = frame.filename || ''
75+
return (
76+
filename.includes('/nobid/blocking_script.js') ||
77+
filename.includes('/media/native/') ||
78+
filename.includes('fuse.js') ||
79+
filename.includes('fuseplatform.net')
80+
)
81+
})
82+
83+
// Check if the error message matches known ad script errors
84+
const isKnownAdError =
85+
errorMessage.includes('is not a function') ||
86+
errorMessage.includes('null is not an object') ||
87+
errorMessage.includes('contextWindow.parent')
88+
89+
if (isAdScriptError && isKnownAdError) {
90+
// Suppress the error - log to console in debug mode
91+
console.debug(
92+
'Suppressed third-party ad script error:',
93+
errorMessage,
94+
frames.map((f) => f.filename),
95+
)
96+
return null // Don't send this event to Sentry
97+
}
98+
99+
return event
100+
},
61101
})
62102
}
63103

0 commit comments

Comments
 (0)