10

I have a modal dialog box in my application which uses getUserMedia to display a video from the user's camera. This causes a "Deny/Allow" bar to appear. Let's say that the user closes the dialog before clicking "Deny" or "Allow". The bar remains, even though the elements that would be using it have disappeared.

Is there a way to notify the browser that it can hide the permission request even though the user never interacted with it?

Dave
  • 44,275
  • 12
  • 65
  • 105
Viper Bailey
  • 11,518
  • 5
  • 22
  • 33
  • No, and there is security reasons for it. Browser will ask every time the domain try to access it media, if the domain isn't in the allow/deny list yet. – Gabriel Gartz Jan 24 '13 at 02:59
  • I noticed that my question was ill-worded. It sounded like I was asking something other than what I was really asking. Hopefully my edit has clarified the question sufficiently. – Viper Bailey Jan 24 '13 at 03:28
  • I hope you don't mind, but I've reduced the question to a simpler form in the hope that somebody is more likely to answer. Your sub-problem of having multiple requests could be solved by using variables with greater scope, for example a global stream object and a global function which is called when access is granted. Then it doesn't matter which callback fires, because they will both have the same effect. – Dave Aug 23 '13 at 13:24
  • I looks like this is simply not possible. – Viper Bailey Oct 13 '14 at 15:52

2 Answers2

2

When the user closes your dialog box, reload the page to clear the permission request with:

  location.reload();

I've tested this in Firefox and Chrome 41 (Canary) and it works there.

Caveat: Chrome 39 (the current version as of this writing) appears to have a bug where this doesn't work so well. The first time I navigate to the page it wont work, but after refreshing the page manually once, it starts working.

I realize this answer may not be immediately useful, but once Chrome 41 ships it should work.

There's currently no way to clear the permission prompt without reloading the page.

jib
  • 40,579
  • 17
  • 100
  • 158
-4

I think you want something like this:

    $("body").on('click', "#stop_button", function(e) {
        e.preventDefault();
        mediaStream.stop();
     });

mediaStream is my global variable that was defined when I called getUserMedia

        navigator.getUserMedia(
            {
              video: true,
              audio: false
            },
            function(stream) {
              if (navigator.mozGetUserMedia) {
                video.mozSrcObject = stream;
              } else {
                var url = window.URL || window.webkitURL;
                video.src = url ? url.createObjectURL(stream) : stream;
              }
              mediaStream = stream;
              video.play();
            },
            function(error) {
              console.log("ERROR: " + error);
            }
        );

So in your example, you would call stop() on your media stream when the dialog was closed - you'd have to create an event handler for that.

Take a look at this Tutorial on getUserMedia for a full worked example and live demo.

craic.com
  • 3,786
  • 5
  • 22
  • 17
  • 3
    I haven't got a computer on-hand to test on, but I believe that this does not make the permissions banner disappear if the user has not yet allowed / denied it. At least, that was the case when I was trying this a few months ago. – Dave Jan 02 '14 at 23:38