Skip to content

fix(analytics): drop browser-extension exception noise before ingestion#3467

Draft
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-code/suppress-extension-exception-noise
Draft

fix(analytics): drop browser-extension exception noise before ingestion#3467
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-code/suppress-extension-exception-noise

Conversation

@posthog

@posthog posthog Bot commented Jul 21, 2026

Copy link
Copy Markdown

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 $exception events 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/analytics so 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 (or vitest run) exercises lib/before-send.test.ts, which covers: the runtime.sendMessage "Tab not found" message, extension-scheme stack frames, the flat $exception_message fallback, genuine app exceptions passing through, non-$exception events being ignored, and malformed/missing properties not throwing.
  • Expected: extension-originated $exception events return null from before_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: dropBrowserExtensionExceptions to the shared PostHog init.
    • Detects known extension messages and extension‑scheme stack frames; passes real events through.
    • Exports the filter from @trycompai/analytics and adds unit tests.
  • Dependencies

    • Adds vitest and a minimal config to run analytics package tests.

Written for commit 06f222b. Summary will update on new commits.

Review in cubic

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
@vercel

vercel Bot commented Jul 21, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
app Ready Ready Preview, Comment Jul 21, 2026 12:14pm
comp-framework-editor Ready Ready Preview, Comment Jul 21, 2026 12:14pm
portal Ready Ready Preview, Comment Jul 21, 2026 12:14pm

Request Review

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant