fix(browser): stop Firefox cross-compartment throws escaping exception autocapture - #4797
fix(browser): stop Firefox cross-compartment throws escaping exception autocapture#4797posthog[bot] wants to merge 2 commits into
Conversation
Firefox throws on every read, write and call that touches an object from another compartment or from a destroyed document. The exception autocapture wrappers touch handlers they do not own, so those throws escaped into the page and stopped the site's own error handler from running. Guard the delegation to the original handler, the __POSTHOG_INSTRUMENTED__ marker write, the initial handler read and the teardown, in all three wrappers. The handler is probed inside the guard and called outside it, so errors from a reachable handler still reach the page. Generated-By: PostHog Desktop Task-Id: 8ec3954c-fe15-42e5-925c-17f1fb20455b
🦔 PostHog Review reviewed this pull requestFound 0 must fix, 1 should fix, 0 consider. Published 1 finding (view the review). Resolved comments: 1 fixed |
Replay incident risk checkThis diff touches code involved in past incidents. This is a heads-up, not a verdict: read the matched sections of INCIDENTS.md and answer their review questions before merging. For a judgment on whether this diff has the same failure mode, run the |
|
Size Change: +619 B (0%) Total Size: 20.5 MB 📦 View Changed
ℹ️ View Unchanged
|
posthog-js Compliance ReportDate: 2026-09-05 01:40:19 UTC ✅ All Tests Passed!26/26 tests passed Capture Tests✅ 26/26 tests passed View Details
|
|
PostHog Review alpha 🦔 If you find any issues helpful - please reply "valid", "invalid", etc., for evaluation purposes 🙏 |
Teardown ran the cosmetic marker deletion and the functional handler restore inside one guard, with the cosmetic statement first. Deleting __POSTHOG_INSTRUMENTED__ needs a property access on the wrapper, which throws on a frozen or unreachable handler -- the same condition this PR guards elsewhere. The throw skipped the restore, leaving the wrapper installed while the observer cleared its unwrap reference, so capture continued after stopExceptionAutocapture() and repeated start/stop cycles stacked wrappers. Give each statement its own guard so a failed delete cannot skip the restore. Generated-By: PostHog Desktop Task-Id: c673b56f-a635-46ab-8ec4-8e47b564cec6
Problem
window.onerroron Firefox. That pollutes the customer's error tracking and stops the customer's own error handler from running, on every site that loads the SDK.Permission denied to access object,Permission denied to access property "__POSTHOG_INSTRUMENTED__",Permission denied to access property "apply", and nowcan't access dead object. All Firefox.__POSTHOG_INSTRUMENTED__markerChanges
safelyguard, inwrapOnError,wrapUnhandledRejectionandwrapConsoleError.falseforonerror, the caller's default foronunhandledrejection.Release info Sub-libraries affected
Libraries affected
Checklist
If releasing new changes
pnpm changesetto generate a changeset file🤖 Agent context
Autonomy: Fully autonomous
error-wrapping-functions.test.ts. Each one fails onmainand passes here. The full browser unit suite passes, plus lint, format and typecheck.Proxythat throws on every read and call, which is what Firefox does to an object it has nuked.Created with PostHog Desktop from this inbox report.