files/en-us/web/api/htmlvideoelement/cancelvideoframecallback/index.md
{{APIRef("HTML DOM")}}
The cancelVideoFrameCallback() method of the {{domxref("HTMLVideoElement")}} interface cancels a previously-registered video frame callback.
cancelVideoFrameCallback(id)
id
None ({{jsxref("undefined")}}).
This example shows how to use cancelVideoFrameCallback() to cancel a previously-registered video frame callback.
let videoCallbackId = null;
function updateCanvas(now, metadata) {
// Do something with the frame
// …
// Re-register the callback to run on the next frame
// It's important to update the videoCallbackId on each iteration
// so you can cancel the callback successfully
videoCallbackId = video.requestVideoFrameCallback(updateCanvas);
}
// Initial registration of the callback to run on the first frame
videoCallbackId = video.requestVideoFrameCallback(updateCanvas);
// …
// Cancel video frame callback using the latest videoCallbackId
if (videoCallbackId !== null) {
video.cancelVideoFrameCallback(videoCallbackId);
}
{{Specifications}}
{{Compat}}
requestVideoFrameCallback() on developer.chrome.com (2023)