The correct solution is to use <input type="file" ...
as answered in several other stack overflow posts.
For example, if you want to just have the built-in camera app get launched, just create element:
<input type="file" name="image" accept="image/*" capture="environment">
You can use the 'file' input as-is or you can hide it and launch it from another button you can hide the input element and call it from javascript (eg jQuery: $('#inpTakePhoto#').click()
). Note, that the event must be triggered by the user and cannot be fired automatically as it will likely get blocked for security reasons.
The input - file control can be configured to use just the camera or even allow user to select from other sources by using the multiple
flag. Its very powerful and easy to use.
For the record, I went down the rabbit hole of getUserMedia
and this is definitely not the correct answer for most people. getUserMedia
is really for developers who want to develop an end-to-end camera app. It requires that the developer implement all the main camera features like pinch zoom, switch camera, and I'm not even sure if the flash settings can get accessed.