diff --git a/gatsby/onPreBootstrap.ts b/gatsby/onPreBootstrap.ts index e1fbcb23c993..eefbc65fa2b8 100644 --- a/gatsby/onPreBootstrap.ts +++ b/gatsby/onPreBootstrap.ts @@ -114,6 +114,24 @@ posthog.init("${process.env.GATSBY_POSTHOG_API_KEY}", { if (!hasInAppFrame) { return null } + // Browser extensions (e.g. Dark Reader) inject an inline script. When it + // throws, its single frame is "global code" at line 1 of the document URL + // and is marked in_app, so it reads as a first-party error and each new + // page URL mints a new fingerprint. Our own code loads from separate script + // files, never inline in the page, so this shape is always extension noise. + var documentUrl = window.location.href.split('#')[0].replace(/\\/$/, '') + var isInjectedInlineScript = exceptions.some(function (ex) { + var frames = (ex && ex.stacktrace && ex.stacktrace.frames) || [] + if (frames.length !== 1) { + return false + } + var frame = frames[0] + var filename = (frame && frame.filename ? frame.filename : '').split('#')[0].replace(/\\/$/, '') + return frame && frame.function === 'global code' && frame.lineno === 1 && filename === documentUrl + }) + if (isInjectedInlineScript) { + return null + } return event }, person_profiles: 'identified_only',