Search code examples
javascriptfirefoxconfigwebrtcgetusermedia

Read the value of Firefox' media.navigator.enabled in Javascript


I've been building a demo using getUserMedia() in Javascript to get the devices webcam and draw the video stream to a html5 canvas. For browsers that don't support getUserMedia() I'm defaulting back to a Flash version of the demo.

Now this all works fine in Chrome and Opera and almost in Firefox 18. However Firefox still has a problem - in the config file media.navigator.enabled is still set to false by default. This means that the user cannot make the choice whether to enable the camera or not and my script just waits for an answer that will never come.

Now obviously I cannot change or set this preference in the config file and I wouldn't want to. However is there anyway of getting the value of this flag so that i can just run a check before proceeding as in "if(media.navigator.enabled)..." ?

Otherwise I will have to always use Flash for Firefox, which would be a little bit of a shame.

The demo is here.


Solution

  • The media.navigator.enabled preference isn't something that is supposed to be switched on by the user. It's rather set to false because this feature is not mature enough in Firefox 18, it's included for testing only so far. The good news: it will be enabled by default in Firefox 20. Firefox 20 is supposed to be released on March 2nd and a few days later you can already assume that this feature is supported by Firefox (only a negligible number of Firefox users stay on old versions).

    The bad news: I don't think that you can handle older Firefox versions in a nice way. They also have the navigator.mozGetUserMedia() method but it simply doesn't do anything. You can choose between having a timeout (e.g. if neither the success nor the error callback were called within a minute switch to the Flash fallback) or user agent sniffing. The latter is ugly but probably the better solution for you:

    var match = /\brv:([\d\.]+)/.exec(navigator.userAgent);
    if (match && parseFloat(match[1]) < 20)
      alert("getUserMedia() not supported");
    

    Note that I explicitly sniff the Gecko version and not the Firefox version - there are more Gecko-based browsers out there, not just Firefox.