diff --git a/src/router.tsx b/src/router.tsx index 56988a9c..c8c66584 100644 --- a/src/router.tsx +++ b/src/router.tsx @@ -58,6 +58,53 @@ export function getRouter() { // Session Replay 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. replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur. + // Filter out third-party ad script errors (Publift Fuse and NoBid) + beforeSend(event, hint) { + const error = hint.originalException + + // Check if error is from third-party ad scripts + const isAdScriptError = event.exception?.values?.some((exception) => { + const frames = exception.stacktrace?.frames || [] + + // Check if any frame in the stack trace is from ad scripts + const hasAdScriptFrame = frames.some((frame) => { + const filename = frame.filename || '' + return ( + filename.includes('/media/native/') || + filename.includes('fuse.js') || + filename.includes('fuseplatform.net') || + filename.includes('/nobid/blocking_script.js') + ) + }) + + // Check if error message matches known patterns + const errorMessage = exception.value || '' + const hasKnownErrorPattern = + errorMessage.includes('contextWindow.parent') || + errorMessage.includes('null is not an object') || + errorMessage.includes('is not a function') + + return hasAdScriptFrame && hasKnownErrorPattern + }) + + // Also check the error object directly if available + const isAdScriptErrorFromHint = + error && + typeof error === 'object' && + 'message' in error && + typeof error.message === 'string' && + (error.message.includes('contextWindow.parent') || + error.message.includes('null is not an object') || + error.message.includes('is not a function')) + + // Drop the event if it's from ad scripts + if (isAdScriptError || isAdScriptErrorFromHint) { + console.debug('Filtered out ad script error from Sentry:', event) + return null + } + + return event + }, }) }