diff --git a/src/router.tsx b/src/router.tsx index 56988a9c..a4ac4415 100644 --- a/src/router.tsx +++ b/src/router.tsx @@ -58,6 +58,59 @@ 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 known third-party errors from ad scripts + beforeSend(event, hint) { + // Check if the error originated from third-party ad scripts + const frames = event.exception?.values?.[0]?.stacktrace?.frames + const errorMessage = event.exception?.values?.[0]?.value || '' + const originalException = hint.originalException + + // Filter out errors from Publift Fuse ad viewability scripts + if (frames) { + const hasThirdPartyAdScript = frames.some((frame) => { + const filename = frame.filename || '' + return ( + filename.includes('/nobid/blocking_script.js') || + filename.includes('/media/native/') || + filename.includes('fuse.js') || + filename.includes('fuseplatform.net') + ) + }) + + // Filter race condition errors from ad scripts + if (hasThirdPartyAdScript) { + const isRaceConditionError = + errorMessage.includes('is not a function') || + errorMessage.includes('null is not an object') || + errorMessage.includes('contextWindow.parent') + + if (isRaceConditionError) { + return null // Drop the error + } + } + } + + // Also check the error message directly for ad script errors + if ( + originalException && + typeof originalException === 'object' && + 'message' in originalException + ) { + const message = String(originalException.message) + if ( + (message.includes('is not a function') || + message.includes('null is not an object') || + message.includes('contextWindow.parent')) && + (message.includes('blocking_script') || + message.includes('fuse') || + message.includes('fuseplatform')) + ) { + return null // Drop the error + } + } + + return event + }, }) }