Check if user has webcam or not using JavaScript only?

javascript

Solution

You can use a new HTML5 API to check if they give you permission to use the webcam. After all, if they deny permission, they might as well not have a webcam, from the code's perspective.

See `navigator.getUserMedia()`.

EDIT:

navigator.getMedia = ( navigator.getUserMedia || // use the proper vendor prefix
                       navigator.webkitGetUserMedia ||
                       navigator.mozGetUserMedia ||
                       navigator.msGetUserMedia);

navigator.getMedia({video: true}, function() {
  // webcam is available
}, function() {
  // webcam is not available
});

Problem

Is it possible to figure out whether a user has a webcam or not using only JavaScript? I don't want to use any plugin for this.

Original source