Skip to content

Shadow: 🐛 Handle null deadline in taskQueue requestIdleCallback (v1)#93

Open
allspain wants to merge 1 commit into
shadow/4497/v1-basefrom
shadow/4497/v1
Open

Shadow: 🐛 Handle null deadline in taskQueue requestIdleCallback (v1)#93
allspain wants to merge 1 commit into
shadow/4497/v1-basefrom
shadow/4497/v1

Conversation

@allspain
Copy link
Copy Markdown
Owner

Shadow Review — PR #4497 v1

Source: DataDog/browser-sdk#4497
Commit: e236bef6147d7c57c14b83ddf6186d9e0d09beac
Timestamp: 2026-04-17T09:03:09Z


Original PR Description

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.
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.

2 participants