Skip to content

fix(browser-utils): Handle NS_ERROR_NOT_INITIALIZED from setTimeout in Firefox - #25024

Open
sentry[bot] wants to merge 2 commits into
developfrom
seer/fix/browser-utils-settimeout-firefox
Open

sentry[bot] wants to merge 2 commits into
developfrom
seer/fix/browser-utils-settimeout-firefox

Conversation

@sentry

@sentry sentry Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Before submitting a pull request, please take a look at our
Contributing guidelines and verify:

  • If you've added code that should be tested, please add tests.
  • Ensure your code lints and the test suite passes (yarn lint) & (yarn test).
  • Link an issue if there is one related to your pull request. If no issue is linked, one will be auto-generated and linked.

This PR addresses an issue where getNativeImplementation('setTimeout') could cause an NS_ERROR_NOT_INITIALIZED error in Firefox.

Root Cause:
When window.setTimeout is wrapped (e.g., by a browser extension), @sentry/browser-utils attempts to get a native setTimeout implementation by creating a hidden iframe, extracting setTimeout from its contentWindow, and then immediately removing the iframe. If Replay's afterSendEvent hook later calls this cached setTimeout function, Firefox throws NS_ERROR_NOT_INITIALIZED because the function belongs to a detached window.

Fix:
The setTimeout wrapper in packages/browser-utils/src/getNativeImplementation.ts now includes a try/catch block. If calling the iframe-sourced setTimeout throws an error (like NS_ERROR_NOT_INITIALIZED), it falls back to window.setTimeout and caches this fallback for subsequent calls. This ensures that even if the native implementation from the iframe fails, the SDK can still use a functional setTimeout.

Regression Test:
A new test file, packages/browser-utils/test/getNativeImplementation.test.ts, has been added. This test simulates the Firefox behavior by mocking a wrapped window.setTimeout and an iframe setTimeout that throws NS_ERROR_NOT_INITIALIZED, verifying that the fallback mechanism works as expected.

Closes #issue_link_here

Fixes DOCS-BAX

@sentry <feedback>: Autofix iterates on these changes
@sentry stop iterating: Autofix stops iterating on this run

…n Firefox

Co-authored-by: sentry[bot] <39604003+sentry[bot]@users.noreply.github.com>
@sentry
sentry Bot requested a review from a team as a code owner October 3, 2026 20:00
@sentry
sentry Bot removed the request for review from a team October 3, 2026 20:00
@sentry sentry Bot assigned sergical Oct 3, 2026
@sentry
sentry Bot requested review from Lms24 and msonnb October 3, 2026 20:00
@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 29.52 kB - -
@sentry/browser - with treeshaking flags 27.68 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 27.57 kB - -
@sentry/browser (incl. Tracing) 51.45 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 51.46 kB - -
@sentry/browser (incl. Tracing, Profiling) 54.46 kB - -
@sentry/browser (incl. Tracing, Replay) 91.09 kB +0.06% +46 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 80.05 kB +0.03% +19 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 95.79 kB +0.06% +49 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 108.76 kB +0.05% +51 B 🔺
@sentry/browser (incl. Feedback) 47.04 kB - -
@sentry/browser (incl. sendFeedback) 34.57 kB - -
@sentry/browser (incl. FeedbackAsync) 39.68 kB - -
@sentry/browser (incl. Metrics) 30.54 kB - -
@sentry/browser (incl. Logs) 30.82 kB - -
@sentry/browser (incl. Metrics & Logs) 31.48 kB - -
@sentry/react 31.36 kB - -
@sentry/react (incl. Tracing) 53.8 kB - -
@sentry/vue 37.51 kB - -
@sentry/vue (incl. Tracing) 54.33 kB - -
@sentry/svelte 29.55 kB - -
@sentry/remix (Remix 3 client bundle) 55.78 kB - -
CDN Bundle 31.22 kB - -
CDN Bundle (incl. Tracing) 51.98 kB - -
CDN Bundle (incl. Logs, Metrics) 33.46 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 53.92 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 74.23 kB +0.03% +21 B 🔺
CDN Bundle (incl. Tracing, Replay) 89.59 kB +0.04% +29 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 91.56 kB +0.03% +23 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 95.74 kB +0.03% +22 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 97.73 kB +0.03% +21 B 🔺
CDN Bundle - uncompressed 92.14 kB - -
CDN Bundle (incl. Tracing) - uncompressed 154.49 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 98.71 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 160.45 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 228.36 kB +0.04% +76 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 274.3 kB +0.03% +76 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 280.24 kB +0.03% +76 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 288 kB +0.03% +76 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 293.93 kB +0.03% +76 B 🔺
@sentry/nextjs (client) 56.32 kB - -
@sentry/sveltekit (client) 51.87 kB - -
@sentry/core/server 40.59 kB - -
@sentry/core/browser 13.63 kB - -
@sentry/node 144.77 kB +0.02% +16 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 83.22 kB - -
@sentry/node - without tracing 93.32 kB +0.02% +10 B 🔺
@sentry/node - without channel injection 122.97 kB +0.01% +6 B 🔺
@sentry/aws-serverless 101.59 kB +0.01% +8 B 🔺
@sentry/cloudflare (withSentry) - minified 208.61 kB - -
@sentry/cloudflare (withSentry) 517.4 kB - -

View base workflow run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 3f04354. Configure here.

Comment thread packages/browser-utils/src/getNativeImplementation.ts

This branch has not been deployed

No deployments
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