ImageCapture: grabFrame() method

The grabFrame() method of the ImageCapture interface takes a snapshot of the live video in a MediaStreamTrack and returns a Promise that resolves with an ImageBitmap containing the snapshot.

Syntax

js
grabFrame()

Parameters

None.

Return value

A Promise that resolves to an ImageBitmap object.

Exceptions

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.

Examples

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.

js
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);
    });
}

Specifications

Specification
MediaStream Image Capture
# dom-imagecapture-grabframe

Browser compatibility

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
Chrome – Full support
Chrome 59 (Release date: 2017-06-05)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 46 (Release date: 2017-06-22)
footnote Full support
Safari – Full support
Safari 26 (Release date: 2025-09-15)
footnote Full support
Chrome Android – Full support
Chrome Android 59 (Release date: 2017-06-06)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Full support
Opera Android 43 (Release date: 2017-09-27)
footnote Full support
Safari on iOS – Full support
Safari on iOS 26 (Release date: 2025-09-15)
footnote Full support
Samsung Internet – Full support
Samsung Internet 7 (Release date: 2018-03-16)
footnote Full support
WebView Android – Full support
WebView Android 59 (Release date: 2017-06-06)
footnote Full support
WebView on iOS – Full support
WebView on iOS 26 (Release date: 2025-09-15)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support