Skip to content

Commit 13d83e6

Browse files
authored
fix: Enhance error suppression for Publift Fuse and race conditions
1 parent 943c7ed commit 13d83e6

File tree

2 files changed

+41
-44
lines changed

2 files changed

+41
-44
lines changed

src/components/Gam.tsx

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -55,50 +55,6 @@ export function GamOnPageChange() {
5555

5656
export const GamScripts = () => (
5757
<>
58-
<script
59-
dangerouslySetInnerHTML={{
60-
__html: `
61-
// Add global error handler to suppress Publift Fuse cross-origin errors
62-
// These errors occur in iOS Safari due to strict Same-Origin Policy enforcement
63-
// when the ad viewability script tries to access parent window properties
64-
// Also suppress race condition errors during navigation
65-
(function() {
66-
var originalErrorHandler = window.onerror;
67-
window.onerror = function(message, source, lineno, colno, error) {
68-
// Check if this is a Publift Fuse cross-origin error
69-
if (
70-
source && (
71-
source.includes('/media/native/') ||
72-
source.includes('fuse.js') ||
73-
source.includes('fuseplatform.net') ||
74-
source.includes('/nobid/blocking_script.js')
75-
) && (
76-
(message && typeof message === 'string' && (
77-
message.includes('contextWindow.parent') ||
78-
message.includes('null is not an object') ||
79-
message.includes('is not a function')
80-
)) ||
81-
(error && error.message && (
82-
error.message.includes('contextWindow.parent') ||
83-
error.message.includes('null is not an object') ||
84-
error.message.includes('is not a function')
85-
))
86-
)
87-
) {
88-
// Suppress the error - log to console in debug mode
89-
console.debug('Suppressed Publift Fuse cross-origin error:', message, source);
90-
return true; // Prevent default error handling
91-
}
92-
// Call original error handler for other errors
93-
if (originalErrorHandler) {
94-
return originalErrorHandler.apply(this, arguments);
95-
}
96-
return false;
97-
};
98-
})();
99-
`,
100-
}}
101-
/>
10258
<script
10359
async
10460
src="https://cdn.fuseplatform.net/publift/tags/2/4019/fuse.js"

src/router.tsx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,47 @@ 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+
beforeSend(event, hint) {
62+
// Filter out Publift Fuse and ad script errors that are expected
63+
// These errors occur in iOS Safari and during navigation due to strict Same-Origin Policy
64+
// and race conditions with ad script initialization
65+
const error = hint.originalException
66+
const errorMessage =
67+
typeof error === 'string'
68+
? error
69+
: error instanceof Error
70+
? error.message
71+
: ''
72+
73+
// Check if this is an ad script error we want to suppress
74+
const frames = event.exception?.values?.[0]?.stacktrace?.frames || []
75+
const hasAdScriptFrame = frames.some((frame) => {
76+
const filename = frame.filename || ''
77+
return (
78+
filename.includes('/media/native/') ||
79+
filename.includes('fuse.js') ||
80+
filename.includes('fuseplatform.net') ||
81+
filename.includes('/nobid/blocking_script.js')
82+
)
83+
})
84+
85+
const hasExpectedErrorMessage =
86+
errorMessage.includes('contextWindow.parent') ||
87+
errorMessage.includes('null is not an object') ||
88+
errorMessage.includes('is not a function')
89+
90+
if (hasAdScriptFrame && hasExpectedErrorMessage) {
91+
// Suppress the error - log to console in debug mode
92+
console.debug(
93+
'Suppressed Publift Fuse/ad script error:',
94+
errorMessage,
95+
frames[0]?.filename,
96+
)
97+
return null // Don't send to Sentry
98+
}
99+
100+
return event
101+
},
61102
})
62103
}
63104

0 commit comments

Comments
 (0)