fix(analytics): drop browser-extension exception noise before ingestion
What does this PR do?
Adds a before_send filter 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.sendMessage is the WebExtension messaging API and we ship no chrome.runtime / browser.runtime usage anywhere in the repo, so nothing in our code path produces it.
The shared init previously had no before_send hook, so it ingested this class of extension noise as-is.
- Detection lives in a small, pure, unit-tested module (
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. - The filter is exported from
@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_send hook stops this class of noise going forward.
Note on scope: The specific events that raised the issue occurred on the www.trycomp.ai landing 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 the runtime.sendMessage message). This PR is the going-forward, defense-in-depth piece for the apps in this repo that use the shared PostHog provider.
- Fixes #XXXX (GitHub issue number) — N/A
- Fixes COMP-XXXX (Linear issue number) — N/A
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)
- I have self-reviewed the code (A decent size PR without self-review might be rejected).
- I have updated the developer docs in /docs if this PR makes changes that would require a documentation change. If N/A, write N/A here and check the checkbox. — N/A
- I confirm automated tests are in place that prove my fix is effective or that my feature works.
How should this be tested?
- No environment variables required.
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.- Expected: extension-originated
$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_send filter in @trycompai/analytics. This keeps error tracking clean by suppressing extension‑generated $exception events (e.g., WebExtension runtime.sendMessage “Tab not found”).
-
Bug Fixes
- Adds
before_send: dropBrowserExtensionExceptionsto the shared PostHog init. - Detects known extension messages and extension‑scheme stack frames; passes real events through.
- Exports the filter from
@trycompai/analyticsand adds unit tests.
- Adds
-
Dependencies
- Adds
vitestand a minimal config to run analytics package tests.
- Adds