3

i think having an unexpected getUserMedia behaviour in Safari and i would like to know if i miss something.

In Chrome/Firefox if i dont allow the first getUserMedia({audio: true, video: true}) prompt every next call to it will fail with the error: NotAllowedError: The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission. and this seems fine.

However in safari if i dont allow the first getUserMedia call the second one with the same constraints will prompt again, any other constraints will fail with the previous error.

I created a simple reproduction repository here that you can run on each browser to compare (you must refuse the first prompt in order to reproduce the bug). Weirdly the same code works every time on jsfiddle only for safari and keep the same behaviour for other browser (due to the iframe where the code is running i guess)

Here a recording of me reproducing my issue to better understand.

GetUserMedia call order:

// 1: press "Not allow"
getUserMedia({ video: true, audio: true });

// 2: will prompt again (that's the bug) and press "Allow"
getUserMedia({ video: true, audio: true });

// 3: will fail (that's the expected behaviour)
getUserMedia({ video: true, audio: true });

// 3bis: will fail too (that's the expected behaviour)
getUserMedia({ video: {deviceId: {exact: 'aValidDeviceId' }}, audio: {deviceId: {exact: 'aValidDeviceId' }} });

Do i miss something or is this indeed a bug with safari ?

Best regards

Adam Soto
  • 174
  • 2
  • 14
  • What's the problem here? Why does your code care when Safari fails with `"NotAllowedError"`? – jib May 29 '21 at 19:48

2 Answers2

1

There's nothing wrong in Safari here. A browser is a "user agent" in the eyes of specifications, which say:

This is intentionally vague about the details of the permission UI and how the UA infers user intent. UAs should be able to explore lots of UI within this framework.

There's no singular permission model on the web. This is a good thing.

If you find yourself writing code that relies on how one browser works in regards to permissions, stop and rethink.

Any code that relies on Safari responding with "NotAllowedError" in a predictable manner, is likely trying to socially engineer an outcome, perhaps to help users through what browser buttons to click to enable the access your site needs to operate correctly.

But browsers cannot distinguish your actions from those of a malicious website, and they need some slack to protect users.

Therefore, the correct way to react to a "NotAllowedError" is to assume it came from the user. In cases where it comes from the user agent, assume the agent is acting in the interest of its user.

If you suspect a user agent is mistaken, please file a bug on that particular user agent so it can improve.

Permissions are tricky.

The web is unique in allowing safe browsing of uncurated, even malicious sites.

The browser ("user agent") is the only trusted party deemed to be acting in the best interest of its user when it comes to permissions. Sites cannot be trusted to manage them.

But browsers differ quite a bit in how they manage their users' permissions. This includes how they react when a user has been bothered enough in their view. This is because the ideal tradeoff between convenience and privacy has not been found yet. Therefore, differentiation and innovation in this area is good, and it is too early to calcify it.

Disclaimer: Permissions are evolving

Browsers aren't perfect. Web developers bear the brunt of this imperfection and differentiation, and cannot be faulted for wishing things were simpler. After all, most of us work on non-malicious websites.

So perhaps there are times when socially engineering around some browser is warranted (after you've filed bugs on it). But on stackoverflow I think we first owe to give the "correct" answer, and preface everything else as workarounds.

jib
  • 40,579
  • 17
  • 100
  • 158
0

It's not a bug exactly. It's expected behavior. Safari, unlike Chrome(ium) and Firefox, does not persist users' acceptance or rejection of permission to access media.

It asks again next time when the user says "yes" as well as when she says "no".

It would be nice if Safari's media stuff was predictable for developers accustomedto the other browsers, but that's not the way it is.

O. Jones
  • 103,626
  • 17
  • 118
  • 172
  • Thanks for your answer :) i figured out too that is not predictable but my wonder is about when refusing the first prompt only the second call to getUserMedia prompt again all the others will fail with NotAllowedError regardless of the answer you gave – Adam Soto Apr 30 '21 at 12:09
  • I hit that situation once when I was pressed for time. I didn't have time to run it down. I *think* going into Settings / Privacy / Safari and clearing out camera permissions will reset things. But there's no way you can reasonably ask a website user to do that. – O. Jones Apr 30 '21 at 12:42
  • Yeah definitely not a viable solution (even do the problem i mention appear from the first visit page), would dream that once refused all the next call fail like Chrome or Firefox to have consistency at least. I added a reproduction video to better understand the situation in the original question – Adam Soto Apr 30 '21 at 13:08