diff --git a/doc/observability.md b/doc/observability.md index f9aaac0700f..66010479c8c 100644 --- a/doc/observability.md +++ b/doc/observability.md @@ -293,7 +293,10 @@ navigation links through a bounded `beforeSend` hook. performance trace and no profile. - The server hook reads only saved run and company metadata for navigation. It copies no request data and preserves the event if the lookup fails. - The browser adds no `beforeSend` hook. Neither runtime adds a custom filter. + The browser `beforeSend` hook only adds the diagnostics listed in + "Browser data" and never drops an event. The browser drops one class of + browser-injected errors with the built-in `ignoreErrors` option (see + "Browser data"). The server adds no filter. ### Server request data @@ -478,6 +481,15 @@ diagnostic reads do not prevent the original exception from being reported. The monitoring gate and sign-out behavior still apply. This context does not suppress errors, change DOM operations, or disable browser translation. +The browser does not send an error whose message contains `__firefox__`. +Firefox for iOS injects Reader-mode and helper scripts into each page, and +these scripts read a `__firefox__` global. When such a script runs before its +setup is complete, the page reports "Can't find variable: __firefox__" or +"undefined is not an object (evaluating 'window.__firefox__.reader')". No +Paperclip code defines or reads `__firefox__`, so these errors do not come +from Paperclip. The built-in `ignoreErrors` option drops them. All other +errors from the same browser are still sent. + ### Fail-open behavior A failed Sentry import or a failed init never stops the server and never diff --git a/ui/src/lib/sentry.test.ts b/ui/src/lib/sentry.test.ts index d4787fd1102..0700e58d804 100644 --- a/ui/src/lib/sentry.test.ts +++ b/ui/src/lib/sentry.test.ts @@ -502,6 +502,12 @@ describe("buildBrowserSentryInitOptions", () => { expect(options.tracesSampleRate).toBe(0); }); + it("ignores only Firefox for iOS's injected-script errors", async () => { + const { buildBrowserSentryInitOptions } = await importFreshSentry(); + + expect(buildBrowserSentryInitOptions(DSN).ignoreErrors).toEqual(["__firefox__"]); + }); + it("adds diagnostics without a transaction filter", async () => { const { buildBrowserSentryInitOptions } = await importFreshSentry(); @@ -664,6 +670,24 @@ describe("captured event shape against the real @sentry/browser SDK", () => { expect((captured as unknown as Record).request).toBeUndefined(); }); + it.each([ + ["TypeError", "undefined is not an object (evaluating 'window.__firefox__.reader')"], + ["ReferenceError", "Can't find variable: __firefox__"], + ])("drops a global %s from Firefox for iOS's injected scripts and keeps the app's own errors", async (type, message) => { + const captured: Array> = []; + const Sentry = await initRealSentryForTest((event) => { captured.push(event); }); + try { + const injected = type === "TypeError" ? new TypeError(message) : new ReferenceError(message); + window.onerror?.call(window, `${type}: ${message}`, "https://example.test/MYB/decisions", 1, 19, injected); + window.onerror?.call(window, "TypeError: app failure", "https://example.test/assets/index.js", 1, 1, new TypeError("app failure")); + await Sentry.flush(2000); + expect(captured.map((event) => (event.exception as { values: Array<{ value: string }> }).values[0]?.value)) + .toEqual(["app failure"]); + } finally { + await Sentry.close(); + } + }); + it("an event captured after a console call and a fetch call carries no breadcrumb", async () => { const originalFetch = globalThis.fetch; globalThis.fetch = vi.fn(async () => new Response("ok")) as unknown as typeof fetch; diff --git a/ui/src/lib/sentry.ts b/ui/src/lib/sentry.ts index b93b3fa684b..52481d6dcbc 100644 --- a/ui/src/lib/sentry.ts +++ b/ui/src/lib/sentry.ts @@ -211,6 +211,7 @@ export function buildBrowserSentryInitOptions( : undefined, tracesSampleRate: 0, sendDefaultPii: false, + ignoreErrors: ["__firefox__"], beforeSend: (event, hint) => { const isUnhandledRejection = event.exception?.values?.some((value) => value.mechanism?.type === "onunhandledrejection"