Skip to content

🐛 Handle null deadline in taskQueue requestIdleCallback#4497

Merged
thomas-lebeau merged 1 commit intomainfrom
thomas.lebeau/requestIdleCallback-null-deadline-repro
Apr 17, 2026
Merged

🐛 Handle null deadline in taskQueue requestIdleCallback#4497
thomas-lebeau merged 1 commit intomainfrom
thomas.lebeau/requestIdleCallback-null-deadline-repro

Conversation

@thomas-lebeau
Copy link
Copy Markdown
Collaborator

@thomas-lebeau thomas-lebeau commented Apr 17, 2026

Motivation

Some page-injected requestIdleCallback polyfills (e.g. setTimeout(cb, 0) in some WKWebViews) invoke the callback without an IdleDeadline argument. The current implementation assumes deadline is always defined and throws when accessing deadline.didTimeout, breaking the task queue.

Observed in SDK self-telemetry (US3, last 7d): ~89k TypeErrors across 6 customer orgs, 100% WebKit (iOS Mobile Safari, desktop Safari, Chrome Mobile iOS, and in-app WKWebViews), ~99.8% on SDK v6.32.0.

Sample stack trace:

TypeError: null is not an object (evaluating 'e.didTimeout')
  at e @ https://www.datadoghq-browser-agent.com/us3/v6/datadog-rum.js:1:73320
  at u @ https://www.datadoghq-browser-agent.com/us3/v6/datadog-rum.js:1:12650
  at <anonymous> @ https://www.datadoghq-browser-agent.com/us3/v6/datadog-rum.js:1:12602

Mapped to source: `taskQueue.ts` `run()` → `monitor.ts` `callMonitored` → `monitor.ts` wrapper.

Changes

  • Accept `IdleDeadline | null` in the task queue `run` callback
  • Treat a missing deadline the same as `didTimeout` (fall back to `MAX_EXECUTION_TIME_ON_TIMEOUT` budget)
  • Add unit test covering the null-deadline case

Test instructions

  • `yarn test:unit --spec packages/core/src/tools/taskQueue.spec.ts`
  • Manually: override `window.requestIdleCallback` with `(cb) => setTimeout(cb, 0)` before SDK init and verify no runtime error.

Checklist

  • Tested locally
  • Tested on staging
  • Added unit tests for this change.
  • Added e2e/integration tests for this change.
  • Updated documentation and/or relevant AGENTS.md file

- Some polyfills (e.g. `setTimeout(cb, 0)` in certain WKWebViews) invoke
  the idle callback with no argument, causing a crash when reading
  `deadline.didTimeout`. Fall back to the timeout execution budget when
  `deadline` is null.
@thomas-lebeau thomas-lebeau marked this pull request as ready for review April 17, 2026 09:02
@thomas-lebeau thomas-lebeau requested a review from a team as a code owner April 17, 2026 09:02
@thomas-lebeau thomas-lebeau merged commit 1c2dd80 into main Apr 17, 2026
24 checks passed
@thomas-lebeau thomas-lebeau deleted the thomas.lebeau/requestIdleCallback-null-deadline-repro branch April 17, 2026 09:59
@github-actions github-actions bot locked and limited conversation to collaborators Apr 17, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants