Let’s say I’m using the getUserMedia javascript api in a browser. The browser asks the user for permission to use the camera or the microphone.
How can I detect when the browser is asking for these permissions, so I can explain to the user why the app is asking for permission?
As far as I know this isn’t directly possible, however you should be able infer that the user is seeing a prompt.
Presumably, since you are writing the javascript, you decide when you’re going to call
getUserMedia(), so you can offer additional explanation as part of the process that leads up to this. A well designed page should explain what’s going on well enough that the user knows what’s happening before they’re prompted to turn over control of their webcam.That said, you can infer that a user is seeing the permission prompt when you’ve sent the request, but have not received either an error callback or a success callback. Given that, you could set a timer at the same time that you first prompt for permission that fires if there is no success or error returned for a few seconds, in which case you could reasonably assume that the user has been presented with the browser prompt but not yet responded.