Skip to content

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

♻️ Move isInjectedExtensionException into posthog utils (#2672)

Luke Vellaaca5605b555d
diff --git a/packages/posthog/src/client.ts b/packages/posthog/src/client.ts
index 2afc37446..233a198ba 100644
--- a/packages/posthog/src/client.ts
+++ b/packages/posthog/src/client.ts
@@ -1,43 +1,12 @@
"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),
- ),
- );
-}
+import {
+ isGlobalPrivacyControlEnabled,
+ isInjectedExtensionException,
+} from "./utils";
if (typeof window !== "undefined" && process.env.NEXT_PUBLIC_POSTHOG_API_KEY) {
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_API_KEY, {
diff --git a/packages/posthog/src/utils.ts b/packages/posthog/src/utils.ts
index 33557ef03..1f68c7bfb 100644
--- a/packages/posthog/src/utils.ts
+++ b/packages/posthog/src/utils.ts
@@ -1,3 +1,5 @@
+import type { CaptureResult } from "posthog-js";
+
type NavigatorWithGlobalPrivacyControl = Navigator & {
globalPrivacyControl?: boolean;
};
@@ -9,3 +11,36 @@ export function isGlobalPrivacyControlEnabled() {
true
);
}
+
+/**
+ * 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)$/;
+
+export 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),
+ ),
+ );
+}