fix(web): drop third-party browser extension exceptions - #26
Draft
posthog[bot] wants to merge 1 commit into
Draft
posthog[bot] wants to merge 1 commit into
posthog[bot] wants to merge 1 commit into
Conversation
Visitor browser extensions throw WebExtension messaging errors (for example "Invalid call to runtime.sendMessage(). Tab not found.") inside the amend.sh page. posthog-js forwarded them as unhandled exceptions because getPostHogOptions() set capture_exceptions with no before_send filter, so they surfaced as amend.sh error tracking issues. Add a before_send hook that drops an $exception event when its message matches a known WebExtension messaging API and its stack carries no application frame. Keep the check in a pure, unit-tested helper. Generated-By: PostHog Desktop Task-Id: 36f78318-af32-4c45-8d2d-a53fa8e64fdb
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.
Problem
chrome.runtimeorbrowser.runtimecall anywhere inapps/weborpackages/backend.getPostHogOptions()setcapture_exceptions: truewith nobefore_sendfilter, so posthog-js forwarded every unhandled window error, including third-party ones.Changes
before_sendhook togetPostHogOptions()that drops an$exceptionevent when its message matches a known WebExtension messaging API and its stack carries no application frame.isThirdPartyExtensionException(), with unit tests.autocapture: false, capture_exceptions: true, + before_send: (event) => { + if (event?.event === "$exception" && isThirdPartyExtensionException(event.properties)) { + return null; + } + return event; + },Drop rule — both conditions must hold:
runtime/tabs.sendMessage/connect/onMessage/onConnectin_app === trueNote
The filter is conservative: an error keeps flowing whenever any application frame is present, even if the message matches. Only frameless, synthetic extension errors are dropped.
Testing
bun test scripts/posthog-exception-filter.test.ts— 5 pass (drops the reported error, keeps application errors and unrelated events).turbo -F web check-types,oxlint, andoxfmt --checkpass on the changed files.Agent context
opencoredev/opentab, but that repo is a bare WXT scaffold with no PostHog setup. The real capture path lives here inamend.sh, so the fix lands here.Why
A single Safari visit to
https://amend.sh/#pricingfiled a visitor extension error as an amend.sh issue. The impact is low, but this class of noise recurs for as long as the filter is missing.Created with PostHog Desktop from this inbox report.