WebcamJS - Function does not work sometimes

0

I have this javascriptt function, which is when I take the webcam photo, it works, but has hours that the "webcam.snap ()" part does not work. I do not understand why, it has hours that it works, and has hours that do not, it does not return any errors in the console. Here's the code part:

function take_snapshot() {
  document.getElementById('upload_results').innerHTML = '<h1>Realizando Upload da Foto...</h1>';
  webcam.snap();
  document.getElementById('<%=btnFechaPopWebCam.ClientID%>').click();
}

So much so that it gets to hold the click of the DataPopWebCam, but it does not always perform the webcam.snap () function; And here is where I call the take_snapshot () function

<input type="button" value="Capturar" class="btn btn-default" onclick="take_snapshot();" />

Something strange happens, is that if I put the breakpoint it always works right, but when I do not put it, sometimes it does not work.

I've used this link as a reference.

    
asked by anonymous 06.02.2018 / 19:52

1 answer

0

According to the documentation , you need to pass a callback function as a parameter to be executed after snap .

To snap a picture, just call the webcam.snap () function, passing in a callback function. The data will be passed to your function as a Data URI, which you can then display in your web page, or submit to a server. Example:
Webcam.snap( function(data_uri) {
    document.getElementById('my_result').innerHTML = '<img src="'+data_uri+'"/>';
} );

    
06.02.2018 / 20:34