ImageCapture: takePhoto() method

The takePhoto() method of the ImageCapture interface takes a single exposure using the video capture device sourcing a MediaStreamTrack and returns a Promise that resolves with a Blob containing the data.

Syntax

js
takePhoto()
takePhoto(photoSettings)

Parameters

photoSettings Optional

An object that sets options for the photo to be taken. The available options are:

fillLightMode

The flash setting of the capture device, one of "auto", "off", or "flash".

imageHeight

The desired image height as an integer. The user agent selects the closest height value to this setting if it only supports discrete heights.

imageWidth

The desired image width as an integer. The user agent selects the closest width value to this setting if it only supports discrete widths.

redEyeReduction

A boolean indicating whether the red-eye reduction should be used if it is available.

Return value

A Promise that resolves with a Blob.

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 takePhoto() to copy the returned Blob to an <img> element. For simplicity it does not show how to instantiate the ImageCapture object.

js
let takePhotoButton = document.querySelector("button#takePhoto");
let canvas = document.querySelector("canvas");

takePhotoButton.onclick = takePhoto;

function takePhoto() {
  imageCapture
    .takePhoto()
    .then((blob) => {
      console.log("Took photo:", blob);
      img.classList.remove("hidden");
      img.src = URL.createObjectURL(blob);
    })
    .catch((error) => {
      console.error("takePhoto() error: ", error);
    });
}

Specifications

Specification
MediaStream Image Capture
# dom-imagecapture-takephoto

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
takePhoto
Chrome – Partial support
Chrome 59 – 59 (Release date: 2017-06-05)
footnote Partial support
footnote photoSettings parameter not supported.
Chrome – Full support
Chrome 60 (Release date: 2017-07-25)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – No support
Firefox 35 (Release date: 2015-01-13)
disabled
disabled From version 35 users must explicitly set the dom.imagecapture.enabled preference to true. To change preferences in Firefox, visit about:config.
Opera – Partial support
Opera 46 – 46 (Release date: 2017-06-22)
footnote Partial support
footnote photoSettings parameter not supported.
Opera – Full support
Opera 47 (Release date: 2017-08-09)
footnote Full support
Safari – Full support
Safari 18.4 (Release date: 2025-03-31)
footnote Full support
Chrome Android – Partial support
Chrome Android 59 – 59 (Release date: 2017-06-06)
footnote Partial support
footnote photoSettings parameter not supported.
Chrome Android – Full support
Chrome Android 60 (Release date: 2017-08-01)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Partial support
Opera Android 43 – 43 (Release date: 2017-09-27)
footnote Partial support
footnote photoSettings parameter not supported.
Opera Android – Full support
Opera Android 44 (Release date: 2017-12-11)
footnote Full support
Safari on iOS – Full support
Safari on iOS 18.4 (Release date: 2025-03-31)
footnote Full support
Samsung Internet – Partial support
Samsung Internet 7 – 7.4 (Release date: 2018-03-16)
footnote Partial support
footnote photoSettings parameter not supported.
Samsung Internet – Full support
Samsung Internet 8 (Release date: 2018-07-18)
footnote Full support
WebView Android – Partial support
WebView Android 59 – 59 (Release date: 2017-06-06)
footnote Partial support
footnote photoSettings parameter not supported.
WebView Android – Full support
WebView Android 60 (Release date: 2017-08-01)
footnote Full support
WebView on iOS – Full support
WebView on iOS 18.4 (Release date: 2025-03-31)
footnote Full support

Legend

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

Full support
Full support
Partial support
Partial support
No support
No support
User must explicitly enable this feature.
Has more compatibility info.