Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

πŸ”Š Filter password-manager extension noise from error tracking (#2576)

posthog-eu[bot]543939e6043e
diff --git a/packages/posthog/src/client.ts b/packages/posthog/src/client.ts
index 43c5ff2d7..2afc37446 100644
--- a/packages/posthog/src/client.ts
+++ b/packages/posthog/src/client.ts
@@ -1,10 +1,44 @@
"use client";
+import type { CaptureResult } from "posthog-js";
import posthog from "posthog-js";
export { useFeatureFlagEnabled } from "posthog-js/react";
import { isGlobalPrivacyControlEnabled } from "./utils";
+/**
+ * Stack-frame function names that only ever appear in password-manager browser
+ * extension content scripts (1Password/Dashlane-style form scanners), never in
+ * our own code. Such extensions scan the page for login forms, misread our
+ * invite voting form (`voting-form.tsx`) as a login form, and throw a
+ * `DOMException: InvalidAccessError` from inside their own `MutationObserver`
+ * callback. PostHog's exception autocapture then attributes the error to our
+ * page URL, so this third-party noise ends up in error tracking.
+ *
+ * Matching any of these frames lets us drop the whole noise class β€” including
+ * future variants such as other `logLogin*Detected` probes β€” before it is sent.
+ */
+const EXTENSION_NOISE_FRAME_PATTERN =
+ /^(dispatchToBridge|logLogin\w*Detected)$/;
+
+function isInjectedExtensionException(event: CaptureResult) {
+ const exceptionList = event.properties?.$exception_list as
+ | Array<{ stacktrace?: { frames?: Array<{ function?: string }> } }>
+ | undefined;
+
+ if (!Array.isArray(exceptionList)) {
+ return false;
+ }
+
+ return exceptionList.some((exception) =>
+ exception?.stacktrace?.frames?.some(
+ (frame) =>
+ typeof frame?.function === "string" &&
+ EXTENSION_NOISE_FRAME_PATTERN.test(frame.function),
+ ),
+ );
+}
+
if (typeof window !== "undefined" && process.env.NEXT_PUBLIC_POSTHOG_API_KEY) {
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_API_KEY, {
debug: false,
@@ -20,6 +54,15 @@ if (typeof window !== "undefined" && process.env.NEXT_PUBLIC_POSTHOG_API_KEY) {
capture_performance: {
web_vitals: false,
},
+ before_send: (event) => {
+ if (
+ event?.event === "$exception" &&
+ isInjectedExtensionException(event)
+ ) {
+ return null;
+ }
+ return event;
+ },
});
}