javascript – How to catch the getUserMedia Write Permit and Deny event?


The function that determines the moment when the user gives permission for recording can be placed in gotStream (see the main.js file for links). But the user can take and reject his confirmation of the permission to write and this will break everything. How to capture this moment?

I don’t want to use the timer, because it’s a load, and while it has time to work, who knows what will happen to the script during recording (when access is abruptly terminated)


Option 1 : Use ssl – this prevents the write request from being asked again.

If your app is running from SSL (https://), this permission will be persistent. That is, users won't have to grant/deny access every time. Information .

Option 2: catch error.

We have a function: navigator.getUserMedia(constraints, successCallback, errorCallback); hence:

navigator.getUserMedia (
   // constraints
      video: true,
      audio: true
   // successCallback
   function(localMediaStream) {
      var video = document.querySelector('video');
      video.src = window.URL.createObjectURL(localMediaStream);
      video.onloadedmetadata = function(e) {
         // Do something with the video here.

   // errorCallback
   function(err) {
    if(err === PERMISSION_DENIED) {
      // Explain why you need permission and how to update the permission setting

Option 3: Use Option 1 + Option 2

PS: A similar question has already been discussed here .

Scroll to Top