fix(analytics): drop browser-extension exception noise before ingestion#3467
Draft
posthog[bot] wants to merge 1 commit into
Draft
fix(analytics): drop browser-extension exception noise before ingestion#3467posthog[bot] wants to merge 1 commit into
posthog[bot] wants to merge 1 commit into
Conversation
Add a `before_send` filter to the shared PostHog init so exceptions injected by third-party browser extensions (e.g. WebExtension `runtime.sendMessage` "Tab not found" errors) never reach error tracking. None of this originates from our code — we ship no `chrome.runtime` / `browser.runtime` usage. The detection lives in a small, pure, unit-tested module (`lib/before-send.ts`) that matches known extension messaging errors and stack frames served from extension URL schemes, and is exported for reuse across apps consuming `@trycompai/analytics`. Generated-By: PostHog Code Task-Id: e1f4abe6-730b-438d-8dcc-ca3ad3a9d406
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Adds a
before_sendfilter to the shared PostHog init (packages/analytics) so exceptions injected by third-party browser extensions never reach error tracking. The trigger was an error-tracking inbox issue —'Error' captured as exception with message: 'Invalid call to runtime.sendMessage(). Tab not found.'— which is thrown by a browser extension's injected content script, not by us.runtime.sendMessageis the WebExtension messaging API and we ship nochrome.runtime/browser.runtimeusage anywhere in the repo, so nothing in our code path produces it.The shared init previously had no
before_sendhook, so it ingested this class of extension noise as-is.lib/before-send.ts) that drops$exceptionevents whose message matches known extension messaging errors, or whose stack frames are served from extension URL schemes (chrome-extension://,moz-extension://,safari-web-extension://, …). All other events pass through untouched.@trycompai/analyticsso any app consuming it gets the same behavior.Why: This exception is externally-injected browser-extension noise with no matching code in the repo — pure inbox clutter, no user-facing bug. The
before_sendhook stops this class of noise going forward.Note on scope: The specific events that raised the issue occurred on the
www.trycomp.ailanding page, which lives in a separate repo, so this monorepo change does not affect those exact events. Those have already been handled directly in error tracking (issue marked suppressed + a tightly-scoped ingestion suppression rule matching only theruntime.sendMessagemessage). This PR is the going-forward, defense-in-depth piece for the apps in this repo that use the shared PostHog provider.Visual Demo (For contributors especially)
N/A — this only drops third-party browser-extension exceptions before they are sent to PostHog; there is no user-facing UI change.
Mandatory Tasks (DO NOT REMOVE)
How should this be tested?
cd packages/analytics && bun run test(orvitest run) exerciseslib/before-send.test.ts, which covers: theruntime.sendMessage"Tab not found" message, extension-scheme stack frames, the flat$exception_messagefallback, genuine app exceptions passing through, non-$exceptionevents being ignored, and malformed/missing properties not throwing.$exceptionevents returnnullfrombefore_send(dropped); all real events and non-exception events pass through unchanged.Checklist
N/A
Created with PostHog Code from this inbox report.
Summary by cubic
Drops third‑party browser extension exception noise before ingestion by adding a PostHog
before_sendfilter in@trycompai/analytics. This keeps error tracking clean by suppressing extension‑generated$exceptionevents (e.g., WebExtensionruntime.sendMessage“Tab not found”).Bug Fixes
before_send: dropBrowserExtensionExceptionsto the shared PostHog init.@trycompai/analyticsand adds unit tests.Dependencies
vitestand a minimal config to run analytics package tests.Written for commit 06f222b. Summary will update on new commits.