2

Hi I'm using ImageCapture in javascript to capture a photo from device camera video on my webapp.

The feature works fine on desktop, but on my iphone(safari) I get this error:

Can't find variable: ImageCapture

Here is my code:

// get camera permission and start the stream
var stream, imageCapture; 
function getMediaStream() {
  if (!window.navigator.mediaDevices) {
    $("#unsupported").show();
    $("#valid-permissions").hide();
    $("#invalid-permissions").hide();
    $("#alternative-button").show();
    return; 
  } 
  window.navigator.mediaDevices.getUserMedia({video: {facingMode:'environment'}})
    .then(function(mediaStream)
  { 
    stream = mediaStream; 
    let mediaStreamTrack = mediaStream.getVideoTracks()[0];
    imageCapture = new ImageCapture(mediaStreamTrack);
    var video = document.querySelector('#webcam');
      video.srcObject = mediaStream;
      video.onloadedmetadata = function(e) {
        video.play();
    };
  })
  .catch(function (error) {
    // this alert gives me the error above
    alert(error.message);
     $("#valid-permissions").hide();
     $("#unsupported").hide();
     $("#invalid-permissions").show();
     $("#alternative-button").show();
 });
}
failedCoder
  • 1,346
  • 1
  • 14
  • 38

1 Answers1

4

It looks like ImageCapture is not a supported Web API in Safari (showing only ?s in the table provided here: https://developer.mozilla.org/en-US/docs/Web/API/ImageCapture#Browser_compatibility).

However, there is a polyfill available from Google Chrome Labs here: https://github.com/GoogleChromeLabs/imagecapture-polyfill

You may be able to use the polyfill to achieve your goals in Safari.

nabeards
  • 56
  • 4
  • not working today :( not safari, not chrome for iphone – Katya Pavlenko Nov 21 '20 at 12:01
  • @KatyaPavlenko the polyfill isn't working for you? The table in my first link above shows that iOS Safari still doesn't have this feature, therefore no iOS browser will have it (as they are all using UIWebViews or similar with the same or fewer features than iOS Safari). – nabeards Apr 14 '21 at 21:14