🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(web): drop getter-only window.__NEXT_DATA__ TypeError from Sentry (#17514)
cursor[bot]4f16ce56fdab
diff --git a/web/src/utils/sentryFilters.clienttest.ts b/web/src/utils/sentryFilters.clienttest.tsindex 7e21fab594..85989932a0 100644--- a/web/src/utils/sentryFilters.clienttest.ts+++ b/web/src/utils/sentryFilters.clienttest.ts@@ -998,6 +998,50 @@ describe("isDenylistedNoiseEvent", () => {});});+ describe("J. drops console-captured getter-only window.__NEXT_DATA__ TypeError", () => {+ // Real shape (LANGFUSE-61R): Next.js Pages Router `initialize()` does+ // `window.__NEXT_DATA__ = initialData`. When that Window property is+ // getter-only, Chromium throws. An injected wrapper logs+ // `Error was not caught` + the TypeError; captureConsoleIntegration+ // mints the issue. Stack is Next.js / turbopack only. 0 users.+ const getterOnlyWindowNextDataEvent = (+ value: string,+ mechanismType = "auto.core.capture_console",+ type = "TypeError",+ ): ErrorEvent =>+ ({+ exception: {+ values: [+ {+ type,+ value,+ mechanism: { type: mechanismType, handled: true },+ },+ ],+ },+ }) as ErrorEvent;++ it("drops the LANGFUSE-61R Chromium TypeError via capture_console", () => {+ expect(+ isDenylistedNoiseEvent(+ getterOnlyWindowNextDataEvent(+ "Cannot set property __NEXT_DATA__ of #<Window> which has only a getter",+ ),+ ),+ ).toBe(true);+ });++ it("drops the same wording with a trailing period", () => {+ expect(+ isDenylistedNoiseEvent(+ getterOnlyWindowNextDataEvent(+ "Cannot set property __NEXT_DATA__ of #<Window> which has only a getter.",+ ),+ ),+ ).toBe(true);+ });+ });+// The heart of the safety contract: prove that real / similar-looking errors// are NOT dropped. If any of these regress to `true`, a real bug would be// hidden from Sentry.@@ -1359,6 +1403,57 @@ describe("isDenylistedNoiseEvent", () => {expect(isDenylistedNoiseEvent(consoleCaptured)).toBe(false);});+ it("keeps an UNCAUGHT getter-only window.__NEXT_DATA__ TypeError (hydration crash)", () => {+ // LANGFUSE-61R drops only the console-captured sibling. A global+ // onerror means Next.js Pages Router failed to boot — keep it.+ const event = {+ exception: {+ values: [+ {+ type: "TypeError",+ value:+ "Cannot set property __NEXT_DATA__ of #<Window> which has only a getter",+ mechanism: {+ type: "auto.browser.global_handlers.onerror",+ handled: false,+ },+ },+ ],+ },+ } as ErrorEvent;+ expect(isDenylistedNoiseEvent(event)).toBe(false);+ });++ it("keeps an app-captured getter-only window.__NEXT_DATA__ TypeError", () => {+ expect(+ isDenylistedNoiseEvent(+ exceptionEvent(+ "Cannot set property __NEXT_DATA__ of #<Window> which has only a getter",+ "TypeError",+ ),+ ),+ ).toBe(false);+ });++ it("keeps a longer message that merely quotes the __NEXT_DATA__ TypeError", () => {+ const event = {+ exception: {+ values: [+ {+ type: "TypeError",+ value:+ "hydrate failed: Cannot set property __NEXT_DATA__ of #<Window> which has only a getter",+ mechanism: {+ type: "auto.core.capture_console",+ handled: true,+ },+ },+ ],+ },+ } as ErrorEvent;+ expect(isDenylistedNoiseEvent(event)).toBe(false);+ });+it("keeps a listener TypeError that is not the Chromium Java-bridge wording", () => {const event = {exception: {diff --git a/web/src/utils/sentryFilters.ts b/web/src/utils/sentryFilters.tsindex bbea3dee0d..c55195dc73 100644--- a/web/src/utils/sentryFilters.ts+++ b/web/src/utils/sentryFilters.ts@@ -366,6 +366,22 @@ const CHROME_EXTENSION_PORT_MESSAGES: readonly string[] = ["The message port closed before a response was received",];+/**+ * Chromium wording when Next.js Pages Router `initialize()` does+ * `window.__NEXT_DATA__ = initialData` and that Window property is+ * getter-only. Observed: LANGFUSE-61R (`/auth/sign-up`, us-prod, 0 users,+ * stack is only Next.js `client/index.tsx` + turbopack). Langfuse never+ * assigns this property. A page-world extension / SES lockdown / named+ * Window property made it a getter; we cannot make it writable after+ * `initialize` has thrown.+ *+ * Whole-message only — an app error that quotes the phrase is longer+ * and is KEPT. Stored without a trailing period because+ * {@link coreMessage} strips one.+ */+const CHROMIUM_GETTER_ONLY_WINDOW_NEXT_DATA_MESSAGE =+ "Cannot set property __NEXT_DATA__ of #<Window> which has only a getter";+/*** A `TRPCClientError` re-wraps its cause's message. Depending on capture path* the Sentry `value` may be the bare cause message (`Failed to fetch`) or carry@@ -465,6 +481,9 @@ export function isReactDevtoolsInternalEvent(event: ErrorEvent): boolean {* - first-party `Failed to fetch dynamically imported module` of a* `/_next/static/chunks/` URL — same Chrome wording as the extension* family, but our chunks (stale tab / CDN); kept.+ * - an UNCAUGHT `window.__NEXT_DATA__` getter-only TypeError (global+ * `onerror`) — Next.js Pages Router failed to boot; kept as a diagnostic.+ * Only the console-captured sibling is dropped (LANGFUSE-61R).*/export function isDenylistedNoiseEvent(event: ErrorEvent): boolean {const exception = event.exception?.values?.[0];@@ -653,6 +672,26 @@ export function isDenylistedNoiseEvent(event: ErrorEvent): boolean {) {return true;}++ // Next.js Pages Router boots with `window.__NEXT_DATA__ = initialData`+ // (`next/src/client/index.tsx`). When that Window property is+ // getter-only, Chromium throws TypeError. Observed as a console+ // capture (LANGFUSE-61R): extra args are `Error was not caught` ++ // the TypeError (that wrapper string is not in Next.js 16.3.3 —+ // page-world). We never assign `__NEXT_DATA__` ourselves.+ //+ // Guarded to `capture_console` so an UNCAUGHT throw (page failed to+ // hydrate via global onerror) is KEPT — that is a real diagnostic.+ // An app-captured exception that merely quotes the phrase (`generic`)+ // is also KEPT.+ if (+ exceptionType === "TypeError" &&+ mechanismType === "auto.core.capture_console" &&+ coreMessage(exceptionValue) ===+ CHROMIUM_GETTER_ONLY_WINDOW_NEXT_DATA_MESSAGE+ ) {+ return true;+ }}return false;