fix: drop benign Capacitor iOS teardown exception from error tracking#469
Draft
posthog-eu[bot] wants to merge 1 commit into
Draft
fix: drop benign Capacitor iOS teardown exception from error tracking#469posthog-eu[bot] wants to merge 1 commit into
posthog-eu[bot] wants to merge 1 commit into
Conversation
Capacitor's injected native-bridge.js registers a pagehide listener (sendPageHideMessage -> sendDataToNative) that reads window.webkit.messageHandlers. During WKWebView teardown on navigation that object is already undefined, throwing a TypeError that posthog-js captures as an unhandled exception. The page is already unloading, so no user-facing flow breaks — it is pure teardown-race noise. Add a narrow before_send rule matching the exact window.webkit.messageHandlers access message together with a Capacitor bridge frame (sendPageHideMessage / sendDataToNative), neither of which exists in our own code, so real exceptions stay visible. Generated-By: PostHog Code Task-Id: 574e2626-3298-407b-9abf-17094dcdf5ce
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Summary
A single iOS user's error tracking flagged a brand-new
TypeError: undefined is not an object (evaluating 'window.webkit.messageHandlers'). It isn't thrown by our code — it comes from Capacitor's injectednative-bridge.js: onpagehideit runssendPageHideMessage→sendDataToNative, which posts towindow.webkit.messageHandlers. While the WKWebView tears down during navigation that object is alreadyundefined, so the access throws and posthog-js captures it as an unhandled exception.This adds a narrow
before_sendrule inlib/posthog/shared.ts(alongside the existing script-error / extension-RPC / rrweb noise filters) that drops the event only when the exactwindow.webkit.messageHandlersmessage co-occurs with a Capacitor bridge frame (sendPageHideMessage/sendDataToNative). Neither symbol exists anywhere in our code, so genuine exceptions stay visible.Why
The page is already unloading when this fires, so no user-facing flow breaks — it's a benign teardown race in a third-party bridge that just clutters error tracking. Chose the
before_sendfilter over a Capacitor dependency bump to match the repo's established noise-suppression pattern and avoid a native-shell upgrade that can't be verified in CI.Verification
Confirmed the fingerprint in error tracking: 1 occurrence / 1 user, iOS Mobile Safari (WKWebView), on a past-papers PDF page. Stack frames carry
sendPageHideMessageandsendDataToNativewith thewindow.webkit.messageHandlersmessage — both matched by the new filter.grepconfirmssendPageHideMessage,sendDataToNative, andwindow.webkit.messageHandlersappear nowhere in the app source.Created with PostHog Code from an inbox report.
spent a lot of water and tokens to review your slop
Greptile Summary
This PR adds a targeted PostHog filter for benign Capacitor iOS teardown errors. The main changes are:
TypeErrorevents containingwindow.webkit.messageHandlers.sendPageHideMessageorsendDataToNativebefore dropping the event.Confidence Score: 5/5
Safe to merge with minimal risk.
The change is isolated to PostHog event filtering and uses narrow matching on exception type, message, and Capacitor bridge frames.
No files require special attention.
What T-Rex did
Important Files Changed
before_sendfilter for Capacitor iOS teardown exceptions while preserving existing error-noise filters.Sequence Diagram
%%{init: {'theme': 'neutral'}}%% sequenceDiagram participant WK as iOS WKWebView participant Cap as Capacitor native-bridge.js participant PH as posthog-js capture_exceptions participant BS as before_send filter participant ET as PostHog error tracking WK->>Cap: pagehide during teardown Cap->>Cap: "sendPageHideMessage -> sendDataToNative" Cap-->>PH: TypeError for window.webkit.messageHandlers PH->>BS: $exception event with exception_list BS->>BS: require TypeError + message + bridge frame alt all exception entries match Capacitor teardown BS-->>PH: return null PH--xET: event dropped else any genuine chained exception remains BS-->>PH: return event PH->>ET: send exception event end%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%% sequenceDiagram participant WK as iOS WKWebView participant Cap as Capacitor native-bridge.js participant PH as posthog-js capture_exceptions participant BS as before_send filter participant ET as PostHog error tracking WK->>Cap: pagehide during teardown Cap->>Cap: "sendPageHideMessage -> sendDataToNative" Cap-->>PH: TypeError for window.webkit.messageHandlers PH->>BS: $exception event with exception_list BS->>BS: require TypeError + message + bridge frame alt all exception entries match Capacitor teardown BS-->>PH: return null PH--xET: event dropped else any genuine chained exception remains BS-->>PH: return event PH->>ET: send exception event endReviews (1): Last reviewed commit: "fix: drop benign Capacitor iOS teardown ..." | Re-trigger Greptile