W3cubDocs

/DOM

MediaDeviceInfo

The MediaDevicesInfo interface contains information that describes a single media input or output device. The list of devices obtained by calling navigator.mediaDevices.enumerateDevices() is an array of MediaDeviceInfo objects, one per media device.

Properties

MediaDeviceInfo.deviceIdRead only
Returns a DOMString that is an identifier for the represented device that is persisted across sessions. It is un-guessable by other applications and unique to the origin of the calling application. It is reset when the user clears cookies (for Private Browsing, a different identifier is used that is not persisted across sessions).
MediaDeviceInfo.groupIdRead only
Returns a DOMString that is a group identifier. Two devices have the same group identifier if they belong to the same physical device — for example a monitor with both a built-in camera and a microphone.
MediaDeviceInfo.kindRead only
Returns an enumerated value that is either "videoinput", "audioinput" or "audiooutput".
MediaDeviceInfo.labelRead only
Returns a DOMString that is a label describing this device (for example "External USB Webcam").

For security reasons, the label field is always blank unless an active media stream exists or the user has granted persistent permission for media device access. The set of device labels could otherwise be used as part of a fingerprinting mechanism to identify a user.

Methods

None.

Example

Here's an example that uses enumerateDevices() to get a list of devices.

if (!navigator.mediaDevices || !navigator.mediaDevices.enumerateDevices) {
  console.log("enumerateDevices() not supported.");
  return;
}

// List cameras and microphones.

navigator.mediaDevices.enumerateDevices()
.then(function(devices) {
  devices.forEach(function(device) {
    console.log(device.kind + ": " + device.label +
                " id = " + device.deviceId);
  });
})
.catch(function(err) {
  console.log(err.name + ": " + error.message);
});

This might produce:

videoinput: id = csO9c0YpAf274OuCPUA53CNE0YHlIr2yXCi+SqfBZZ8=
audioinput: id = RKxXByjnabbADGQNNZqLVLdmXlS0YkETYCIbg+XxnvM=
audioinput: id = r2/xw1xUPIyZunfV1lGrKOma5wTOvCkWfZ368XCndm0=

or if one or more media streams are active, or if persistent permissions have been granted:

videoinput: FaceTime HD Camera (Built-in) id=csO9c0YpAf274OuCPUA53CNE0YHlIr2yXCi+SqfBZZ8=
audioinput: default (Built-in Microphone) id=RKxXByjnabbADGQNNZqLVLdmXlS0YkETYCIbg+XxnvM=
audioinput: Built-in Microphone id=r2/xw1xUPIyZunfV1lGrKOma5wTOvCkWfZ368XCndm0=

Specifications

Specification Status Comment
Media Capture and Streams
The definition of 'MediaDevicesInfo' in that specification.
Candidate Recommendation Initial definition

Browser compatibilityUpdate compatibility data on GitHub

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
Basic support 55
55
For earlier versions, this interface is available through the adapter.js polyfill
Yes 39 No ?
?
This interface is available in Opera through the adapter.js polyfill.
No
deviceId 55
55
For earlier versions, this interface is available through the adapter.js polyfill
12 39 No ?
?
This interface is available in Opera through the adapter.js polyfill.
No
groupId 55
55
For earlier versions, this interface is available through the adapter.js polyfill
12 39 No ?
?
This interface is available in Opera through the adapter.js polyfill.
No
kind 55
55
For earlier versions, this interface is available through the adapter.js polyfill
12 39 No ?
?
This interface is available in Opera through the adapter.js polyfill.
No
label 55
55
For earlier versions, this interface is available through the adapter.js polyfill
12 39 No ?
?
This interface is available in Opera through the adapter.js polyfill.
No
toJSON ? ? ? ? ? ?
Mobile
Android webview Chrome for Android Edge Mobile Firefox for Android Opera for Android iOS Safari Samsung Internet
Basic support 55
55
For earlier versions, this interface is available through the adapter.js polyfill
55
55
For earlier versions, this interface is available through the adapter.js polyfill
Yes 39 ?
?
This interface is available in Opera through the adapter.js polyfill.
No 6.0
deviceId 55
55
For earlier versions, this interface is available through the adapter.js polyfill
55
55
For earlier versions, this interface is available through the adapter.js polyfill
Yes 39 ?
?
This interface is available in Opera through the adapter.js polyfill.
No 6.0
groupId 55
55
For earlier versions, this interface is available through the adapter.js polyfill
55
55
For earlier versions, this interface is available through the adapter.js polyfill
Yes 39 ?
?
This interface is available in Opera through the adapter.js polyfill.
No 6.0
kind 55
55
For earlier versions, this interface is available through the adapter.js polyfill
55
55
For earlier versions, this interface is available through the adapter.js polyfill
Yes 39 ?
?
This interface is available in Opera through the adapter.js polyfill.
No 6.0
label 55
55
For earlier versions, this interface is available through the adapter.js polyfill
55
55
For earlier versions, this interface is available through the adapter.js polyfill
Yes 39 ?
?
This interface is available in Opera through the adapter.js polyfill.
No 6.0
toJSON ? ? ? ? ? ? ?

See also

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/MediaDeviceInfo