This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The MediaDevices interface provides access to connected media input devices like cameras and microphones, as well as screen sharing. In essence, it lets you obtain access to any hardware source of media data.


Inherits properties from its parent EventTarget.

Event handlers

The event handler for the devicechange event. This event is delivered to the MediaDevices object when a media input or output device is attached to or removed from the user's computer.


Inherits methods from its parent EventTarget.

Registers an event handler to a specific event type.
Obtains an array of information about the media input and output devices available on the system.
Returns an object conforming to MediaTrackSupportedConstraints indicating which constrainable properties are supported on the MediaStreamTrack interface. See Capabilities and constraints in Media Capture and Streams API (Media Stream) to learn more about constraints and how to use them.
With the user's permission through a prompt, turns on a camera or screensharing and/or a microphone on the system and provides a MediaStream containing a video track and/or an audio track with the input.
Removes an event listener.


'use strict';

// Put variables in global scope to make them available to the browser console.
var video = document.querySelector('video');
var constraints = window.constraints = {
  audio: false,
  video: true
var errorElement = document.querySelector('#errorMsg');

.then(function(stream) {
  var videoTracks = stream.getVideoTracks();
  console.log('Got stream with constraints:', constraints);
  console.log('Using video device: ' + videoTracks[0].label);
  stream.onremovetrack = function() {
    console.log('Stream ended');
  }; = stream; // make variable available to browser console
  video.srcObject = stream;
.catch(function(error) {
  if ( === 'ConstraintNotSatisfiedError') {
    errorMsg('The resolution ' + + 'x' + + ' px is not supported by your device.');
  } else if ( === 'PermissionDeniedError') {
    errorMsg('Permissions have not been granted to use your camera and ' +
      'microphone, you need to allow the page access to your devices in ' +
      'order for the demo to work.');
  errorMsg('getUserMedia error: ' +, error);

function errorMsg(msg, error) {
  errorElement.innerHTML += '<p>' + msg + '</p>';
  if (typeof error !== 'undefined') {


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

Browser compatibility

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!
Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 47 (Yes) 36.0 (36.0) No support 30 No support
enumerateDevices() 51 ? ? No support 38 No support
getSupportedConstraints() 53 ? 44 (44) No support 40 No support
ondevicechange and devicechange events (Yes) ? 51 (51)[1] No support (Yes) No support
Stereo audio capture ? ? 55 (55) No support ? No support
Feature Android Webview Chrome for Android Edge Firefox Mobile (Gecko) Firefox OS IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support 47 47 (Yes) 36.0 (36.0) 2.2 No support 30 No support No support
enumerateDevices() 51 51 ? ? ? No support 38 No support No support
getSupportedConstraints() 53 52 ? 50.0 (50) ? No support 40 No support No support
ondevicechange and devicechange events (Yes) (Yes) ? 51.0 (51)[1] ? No support (Yes) No support No support
Stereo audio capture ? ? ? No support ? No support ? No support No support

[1] Support for the devicechange event and for MediaDevices.ondevicechange landed in Firefox 51, but only for Mac, and disabled by default. It can be enabled by setting the preference media.ondevicechange.enabled to true. Support for this event was added for Linux and Windows—and it was enabled by default—starting in Firefox 52.

See also