Bug 195093 - Safari 12.1 : Issue with navigator.mediaDevices.enumerateDevices
Summary: Safari 12.1 : Issue with navigator.mediaDevices.enumerateDevices
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebRTC (show other bugs)
Version: Safari 12
Hardware: Unspecified macOS 10.14
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-02-27 01:56 PST by Pradeep Kumar
Modified: 2019-05-24 08:32 PDT (History)
3 users (show)

See Also:


Attachments
Not working safari 12.1 (252.01 KB, image/png)
2019-02-27 01:56 PST, Pradeep Kumar
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Pradeep Kumar 2019-02-27 01:56:58 PST
Created attachment 363082 [details]
Not working safari 12.1

Hi Safari team,

I'm facing issue with `navigator.mediaDevices.enumerateDevices` in Safari 12.1 as not able to get the device Ids when website permission is set to ask for devices. When we set website permission to allow for devices, it works.
However, the same is working on Safari 12.0. So, I'm suspecting something has been introduced in Safari 12.1.

Below is the test code executed into Safari console for testing :
{
navigator.mediaDevices.enumerateDevices().then(function(devices) {
          devices.forEach(function(device) {
            console.log(device.kind + ": " + device.label + " id = " + device.deviceId);
          });
        })
}
Comment 1 youenn fablet 2019-02-27 09:36:50 PST
Hi Pradeep,

You are right.
We changed a bit our fingerprinting enumerateDevices mitigation.
I would be interested in your feedback there.

Device IDs should now remain stable after getUserMedia is granted even after page reload.
The device IDs will only be communicated after getUserMedia being granted.
That should allow picking the same device as previously as follows:

let stream;
let deviceId = window.localStorage.getItem('preferredMicrophoneId');
const constraint = deviceId ? {audio : {deviceId: {exact: deviceId}}} : {audio: true};
try {
    stream = await navigator.mediaDevices.getUserMedia(constraint);
} catch (e) {
   // In case of overconstrainederror, call getUserMedia({audio: true})
}
deviceId = stream.getAudioTracks()[0].getSettings().deviceId;
window.localStorage.setItem('preferredMicrophoneId', deviceId);
Comment 2 Pradeep Kumar 2019-02-28 00:38:51 PST
(In reply to youenn fablet from comment #1)
> Hi Pradeep,
> 
> You are right.
> We changed a bit our fingerprinting enumerateDevices mitigation.
> I would be interested in your feedback there.
> 
> Device IDs should now remain stable after getUserMedia is granted even after
> page reload.
> The device IDs will only be communicated after getUserMedia being granted.
> That should allow picking the same device as previously as follows:
> 
> let stream;
> let deviceId = window.localStorage.getItem('preferredMicrophoneId');
> const constraint = deviceId ? {audio : {deviceId: {exact: deviceId}}} :
> {audio: true};
> try {
>     stream = await navigator.mediaDevices.getUserMedia(constraint);
> } catch (e) {
>    // In case of overconstrainederror, call getUserMedia({audio: true})
> }
> deviceId = stream.getAudioTracks()[0].getSettings().deviceId;
> window.localStorage.setItem('preferredMicrophoneId', deviceId);

Hi Youenn,
Thanks for quick reply. The work around, you are suggesting, it works.
Comment 3 youenn fablet 2019-05-24 08:32:43 PDT
*** Bug 198148 has been marked as a duplicate of this bug. ***