Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(web): drop Next.js Invalid URL noise on data: document URLs (#16910)

cursor[bot]6dcea100219c
diff --git a/web/src/utils/sentryFilters.clienttest.ts b/web/src/utils/sentryFilters.clienttest.ts
index b4b6151963..96f86cfc3e 100644
--- a/web/src/utils/sentryFilters.clienttest.ts
+++ b/web/src/utils/sentryFilters.clienttest.ts
@@ -599,6 +599,72 @@ describe("isDenylistedNoiseEvent", () => {
});
});
+ describe("H. drops Next.js App Router Invalid URL on data: documents", () => {
+ // Real shape (LANGFUSE-60K): Electron loads the Next.js HTML as a
+ // `data:text/html,…` document. App Router does
+ // `new URL(canonicalUrl, window.location.href)` and Chromium throws
+ // because a data: URL is not a valid base. Mechanism is the global
+ // onerror handler; stack is Next.js Router only.
+ const dataDocumentInvalidUrlEvent = (
+ value: string,
+ url: string,
+ mechanismType = "auto.browser.global_handlers.onerror",
+ ): ErrorEvent =>
+ ({
+ exception: {
+ values: [
+ {
+ type: "TypeError",
+ value,
+ mechanism: { type: mechanismType, handled: false },
+ },
+ ],
+ },
+ request: { url },
+ }) as ErrorEvent;
+
+ it("drops the Chromium constructor TypeError on a data: page URL", () => {
+ expect(
+ isDenylistedNoiseEvent(
+ dataDocumentInvalidUrlEvent(
+ "Failed to construct 'URL': Invalid URL",
+ "data:text/html,<!DOCTYPE html><html></html>",
+ ),
+ ),
+ ).toBe(true);
+ });
+
+ it("drops the same TypeError when only tags.url is the data: document", () => {
+ const event = {
+ exception: {
+ values: [
+ {
+ type: "TypeError",
+ value: "Failed to construct 'URL': Invalid URL",
+ mechanism: {
+ type: "auto.browser.global_handlers.onerror",
+ handled: false,
+ },
+ },
+ ],
+ },
+ tags: { url: "data:text/html,probe" },
+ } as unknown as ErrorEvent;
+ expect(isDenylistedNoiseEvent(event)).toBe(true);
+ });
+
+ it("drops the Firefox constructor wording on a data: page URL", () => {
+ expect(
+ isDenylistedNoiseEvent(
+ dataDocumentInvalidUrlEvent(
+ "URL constructor: /health is not a valid URL",
+ "data:text/html,probe",
+ ),
+ ),
+ ).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.
@@ -925,6 +991,69 @@ describe("isDenylistedNoiseEvent", () => {
expect(isDenylistedNoiseEvent(event)).toBe(false);
});
+ it("keeps the same Invalid URL TypeError on an https page (real app bug)", () => {
+ const event = {
+ exception: {
+ values: [
+ {
+ type: "TypeError",
+ value: "Failed to construct 'URL': Invalid URL",
+ mechanism: {
+ type: "auto.browser.global_handlers.onerror",
+ handled: false,
+ },
+ },
+ ],
+ },
+ request: { url: "https://cloud.langfuse.com/project/abc/traces" },
+ } as ErrorEvent;
+ expect(isDenylistedNoiseEvent(event)).toBe(false);
+ });
+
+ it("keeps an app-captured Invalid URL TypeError even on a data: page", () => {
+ // Mechanism guard: captureException / capture_console must still surface.
+ expect(
+ isDenylistedNoiseEvent(
+ exceptionEvent("Failed to construct 'URL': Invalid URL", "TypeError"),
+ ),
+ ).toBe(false);
+ const consoleCaptured = {
+ exception: {
+ values: [
+ {
+ type: "TypeError",
+ value: "Failed to construct 'URL': Invalid URL",
+ mechanism: {
+ type: "auto.core.capture_console",
+ handled: true,
+ },
+ },
+ ],
+ },
+ request: { url: "data:text/html,probe" },
+ } as ErrorEvent;
+ expect(isDenylistedNoiseEvent(consoleCaptured)).toBe(false);
+ });
+
+ it("keeps a different TypeError on a data: page", () => {
+ const event = {
+ exception: {
+ values: [
+ {
+ type: "TypeError",
+ value: "Cannot read properties of undefined (reading 'map')",
+ mechanism: {
+ type: "auto.browser.global_handlers.onerror",
+ handled: false,
+ },
+ },
+ ],
+ },
+ request: { url: "data:text/html,probe" },
+ } as ErrorEvent;
+ expect(isDenylistedNoiseEvent(event)).toBe(false);
+ });
+
it("keeps a longer app message that merely quotes the Java-bridge suffix", () => {
const event = {
exception: {
diff --git a/web/src/utils/sentryFilters.ts b/web/src/utils/sentryFilters.ts
index 9660ff90b8..d4408b26c9 100644
--- a/web/src/utils/sentryFilters.ts
+++ b/web/src/utils/sentryFilters.ts
@@ -194,6 +194,44 @@ const BENIGN_NON_ERROR_REJECTION_VALUE_PREFIXES: readonly string[] = [
const ANDROID_WEBVIEW_JAVA_BRIDGE_ERROR_RE =
/^Error invoking [A-Za-z_][\w$]*: Java bridge method invocation error$/;
+/**
+ * Chromium wording when `new URL(input, base)` rejects the base. A `data:`
+ * document URL cannot resolve a path-absolute URL, so Next.js App Router's
+ * `new URL(canonicalUrl, window.location.href)` throws during hydrate.
+ * Observed: LANGFUSE-60K (Electron health probe loading the app HTML as a
+ * `data:` URL; stack is Next.js `Router` only, 0 users).
+ */
+const CHROMIUM_INVALID_URL_CONSTRUCTOR_MESSAGE =
+ "Failed to construct 'URL': Invalid URL";
+
+/**
+ * Firefox wording for the same `new URL` rejection (`URL constructor: <x>
+ * is not a valid URL`).
+ */
+const FIREFOX_INVALID_URL_CONSTRUCTOR_RE =
+ /^URL constructor: .+ is not a valid URL\.?$/;
+
+function isInvalidUrlConstructorMessage(value: string): boolean {
+ return (
+ value === CHROMIUM_INVALID_URL_CONSTRUCTOR_MESSAGE ||
+ FIREFOX_INVALID_URL_CONSTRUCTOR_RE.test(value)
+ );
+}
+
+/**
+ * True when the event's page URL is a `data:` document. Checks `request.url`
+ * first, then `tags.url` — Sentry's transaction/culprit often strips the
+ * `data:` scheme, so those fields are not used.
+ */
+function isDataDocumentUrl(event: ErrorEvent): boolean {
+ const requestUrl = event.request?.url;
+ if (typeof requestUrl === "string" && requestUrl.startsWith("data:")) {
+ return true;
+ }
+ const taggedUrl = event.tags?.url;
+ return typeof taggedUrl === "string" && taggedUrl.startsWith("data:");
+}
+
/**
* 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
@@ -431,6 +469,27 @@ export function isDenylistedNoiseEvent(event: ErrorEvent): boolean {
) {
return true;
}
+
+ // Next.js App Router hydrates with
+ // `new URL(canonicalUrl, window.location.href)`. A `data:` document is
+ // not a valid base for a path-absolute canonical URL, so Chromium throws
+ // TypeError. Observed only from third-party Electron probes that load the
+ // app HTML as a data: URL (LANGFUSE-60K) — 0 users, Next.js frames only.
+ // We cannot fix Next.js here, and the page is not a real session.
+ //
+ // Requires TypeError + exact constructor wording + a data: page URL +
+ // a Sentry browser/global-handler mechanism so:
+ // - the same TypeError on an https:// page is KEPT (real app bug);
+ // - an app-captured exception that merely quotes the phrase is KEPT.
+ if (
+ exceptionType === "TypeError" &&
+ typeof mechanismType === "string" &&
+ mechanismType.startsWith("auto.browser.") &&
+ isInvalidUrlConstructorMessage(exceptionValue) &&
+ isDataDocumentUrl(event)
+ ) {
+ return true;
+ }
}
return false;