15

I tried the following attribute capture to set the input element to try to select the front facing camera. user is front facing, and environment is back facing.

However, while experimenting with Chrome (latest) on mobile (Pixel 1, latest OS), the back camera is still selected.

I used an example snippet:

<form action="server.cgi" method="post" enctype="multipart/form-data">
  <input type="file" name="image" accept="image/*" capture="user">
  <input type="submit" value="Upload">
</form>

(from https://w3c.github.io/html-media-capture/#the-capture-attribute)

I am able to change accept to require video on my phone, so that and other attributes work, but not the capture attribute.

EDIT: Am using the latest Android Chrome browser. The following page implies that iOS and older versions of Android Chrome cannot use capture altogether, but otherwise can use capture. https://caniuse.com/#search=html-media-capture

imagineerThat
  • 5,293
  • 7
  • 42
  • 78
  • 1
    Surely it's possible that Chrome just hasn't implemented that functionality? – jhpratt Jul 17 '19 at 17:41
  • Yes, it is possible, but I am not able to prove it. Added edit to post for more info. Wish this was documented more clearly. – imagineerThat Jul 21 '19 at 20:58
  • I would say the "proof" is that it's not working. I'll try to find some _official_ documentation one way or the other. – jhpratt Jul 21 '19 at 22:03
  • Ok. I am new to HTML. Not working isn't a good litmus for a novice, when many things can break when implemented incorrectly. – imagineerThat Jul 22 '19 at 04:32
  • Ah, I assumed you were relatively experienced based on the type of thing you were trying to do. As a rule of thumb, though, a code example from the W3C spec should absolutely work if implemented. – jhpratt Jul 22 '19 at 04:33
  • Thanks. Good to know that this is the exception. – imagineerThat Jul 22 '19 at 04:39

3 Answers3

8

I cloned the chromium repository today (2019-07-21). I then used ripgrep to get a list of files that do not contain capture. After passing that list to rm, I removed any directories that were either empty or clearly irrelevant (such as telemetry). Going through the remaining ~50 files was a relatively trivial task.

Hopefully the Chrome team will get around to implementing this in the future, but there is currently no indication that this behavior is supported in official documentation, official blog posts, or the code itself.

I know it's not the answer you'd like to hear, but those are the facts as I've found them.

jhpratt
  • 6,841
  • 16
  • 40
  • 50
2

Would it be Chrome specifically that hinders the code from working properly? I suggest using a different browser such as Firefox in order to test this theory. If it does succeed on Firefox, then the simple answer is: Chrome has yet to implement it yet.

Fallen13
  • 21
  • 3
  • Thanks. Firefox does not produce the desired behavior as well (it's documented anyways). This page implies that iOS Safari and older versions of Android Chrome cannot use `capture` altogether (I am on latest Android), but otherwise can use `capture`. https://caniuse.com/#search=html-media-capture – imagineerThat Jul 21 '19 at 20:53
  • Answers should be more than a guess, _especially_ with a bounty attached. – jhpratt Jul 21 '19 at 21:47
2

Here are some tests, I included user agent:

Didn't worked with :

  • Android Chrome: Mozilla/5.0 (Linux; Android 6.0; Ilium X510) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.143 Mobile Safari/537.36
  • Android Firefox: Mozilla/5.0 (Android 6.0; Mobile; rv:68.0) Gecko/68.0 Firefox/68.0

Worked with :

  • IPhone Chrome: Mozilla/5.0 (iPhone; CPU iPhone OS 12_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/75.0.3770.103 Mobile/15E148 Safari/605.1
  • IPhone Safari: Mozilla/5.0 (iPhone; CPU iPhone OS 12_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1.1 Mobile/15E148 Safari/604.1

In Summary:

  • All tested iPhone navigators displayed the front camera view when capture is user, and back camera view if it is environment.
  • Both tested Android navigators displayed always the back camera view.

So regardless the information in the accepted answer, it doesn't seem to be a browser issue. It would be helpful if it works correctly with an Android device and a specific browser.

I hope other people can share tests on their Android devices, in particular on working ones, displaying front camera view while testing the capture="user" attribute-value.

G_real
  • 1,137
  • 1
  • 18
  • 28
  • It _is_ a browser issue. The specification says that this should work, and it doesn't. And there is _zero_ code in Chrome, which is the one in question. – jhpratt Jul 24 '19 at 23:35
  • still it works well at Chrome in iPhone, despite the zero code in chrome. Perhaps this exclusive code for iOS is not documented. – CARLOS AGUIRRE Jul 30 '19 at 16:31
  • That's because all browsers on iPhone use Safari's engine, per Apple's requirements. Note that I didn't search for _documentation_, but the code itself, as well. – jhpratt Jul 30 '19 at 19:50