CKTIS / JavaScript
cancelIdleCallback(): canceling a pending callback
cancelIdleCallback(handle) cancels a pending callback scheduled by requestIdleCallback(). It requires the request identifier, not the callback function itself.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
window.cancelIdleCallback(handle)window.cancelIdleCallback(handle) takes the numeric identifier returned by requestIdleCallback() in the same window. It removes the pending callback, including one already eligible to run. It returns undefined.
If the identifier matches no pending request, the method does nothing. It cannot interrupt a callback that has started or undo its effects.
This is a Window Web API, not an ECMAScript-defined function. Check both methods for availability; Node 24 in a repository does not establish browser support.
The example cancels the request immediately after scheduling, before yielding control to the browser. Store the identifier so that you can cancel work that is no longer needed.
Examples
(() => {
if (typeof window === "undefined" ||
typeof window.requestIdleCallback !== "function" ||
typeof window.cancelIdleCallback !== "function") {
console.log("Idle callbacks unavailable");
return;
}
const handle = window.requestIdleCallback(() => {
console.log("Unexpected callback");
});
window.cancelIdleCallback(handle);
console.log("Cancellation requested");
})();Result
Cancellation requested
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.