The grabFrame() method of the ImageCapture interface takes a snapshot of the live video in a MediaStreamTrack and returns a Promise that resolves with a ImageBitmap containing the snapshot.
grabFrame()
None.
A Promise that resolves to an ImageBitmap object.
InvalidStateError DOMException
Thrown if readyState property of the MediaStreamTrack passing in the constructor is not live.
UnknownError DOMException
Thrown if the operation can't complete for any reason.
This example is extracted from this Simple Image Capture demo. It shows how to use the Promise returned by grabFrame() to copy the returned frame to a <canvas> element. For simplicity it does not show how to instantiate the ImageCapture object.
let grabFrameButton = document.querySelector("button#grabFrame");
let canvas = document.querySelector("canvas");
grabFrameButton.onclick = grabFrame;
function grabFrame() {
imageCapture
.grabFrame()
.then((imageBitmap) => {
console.log("Grabbed frame:", imageBitmap);
canvas.width = imageBitmap.width;
canvas.height = imageBitmap.height;
canvas.getContext("2d").drawImage(imageBitmap, 0, 0);
canvas.classList.remove("hidden");
})
.catch((error) => {
console.error("grabFrame() error: ", error);
});
}
| Specification |
|---|
| MediaStream Image Capture> # dom-imagecapture-grabframe> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
grabFrame |
59 | 79 | No | 46 | 26 | 59 | No | 43 | 26 | 7.0 | 59 | 26 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/ImageCapture/grabFrame