Skip to content

Commit aa3a779

Browse files
fix: Suppress Sentry errors from third-party ad scripts
1 parent 3595979 commit aa3a779

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

src/router.tsx

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,59 @@ 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 errors from ad scripts
62+
beforeSend(event, hint) {
63+
// Check if the error originated from third-party ad scripts
64+
const frames = event.exception?.values?.[0]?.stacktrace?.frames
65+
const errorMessage = event.exception?.values?.[0]?.value || ''
66+
const originalException = hint.originalException
67+
68+
// Filter out errors from Publift Fuse ad viewability scripts
69+
if (frames) {
70+
const hasThirdPartyAdScript = frames.some((frame) => {
71+
const filename = frame.filename || ''
72+
return (
73+
filename.includes('/nobid/blocking_script.js') ||
74+
filename.includes('/media/native/') ||
75+
filename.includes('fuse.js') ||
76+
filename.includes('fuseplatform.net')
77+
)
78+
})
79+
80+
// Filter race condition errors from ad scripts
81+
if (hasThirdPartyAdScript) {
82+
const isRaceConditionError =
83+
errorMessage.includes('is not a function') ||
84+
errorMessage.includes('null is not an object') ||
85+
errorMessage.includes('contextWindow.parent')
86+
87+
if (isRaceConditionError) {
88+
return null // Drop the error
89+
}
90+
}
91+
}
92+
93+
// Also check the error message directly for ad script errors
94+
if (
95+
originalException &&
96+
typeof originalException === 'object' &&
97+
'message' in originalException
98+
) {
99+
const message = String(originalException.message)
100+
if (
101+
(message.includes('is not a function') ||
102+
message.includes('null is not an object') ||
103+
message.includes('contextWindow.parent')) &&
104+
(message.includes('blocking_script') ||
105+
message.includes('fuse') ||
106+
message.includes('fuseplatform'))
107+
) {
108+
return null // Drop the error
109+
}
110+
}
111+
112+
return event
113+
},
61114
})
62115
}
63116

0 commit comments

Comments
 (0)