Call getUserMedia from web extension


(Bernardogiordano) #1

Hello everyone,
I’m facing an issue related to calling navigator.mediaDevices.getUserMedia from a web extension. I need to acquire the microphone, so this is a pretty important portion of my extension.

When I call getUserMedia from a standard web page, I get the user media prompt which the user can use to grant access to the microphone. I’m not able to get it displayed when I’m calling getUserMedia from the webextensions javascript instead.

Note: the call to getUserMedia is not in a background script nor into a content script, it’s just inside a javascript which is loaded from the html of the webextension.
Also, I’m not sure if I need special permissions to do so, but looking at the full list of available permissions, I don’t see nothing that reminds me of microphone acquire.

Thanks in advance


(Martin Giger) #2

Anything you want to use in your background page (or mostly a popup or sidebar) that would generate a doorhanger prompt needs to be requested as permission instead. See for example the geolocation permission at https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions

The webRTC permission hasn’t been implemented so far due to realizing an UI that shows microphopne/camera usage in a way that the user understands it’s coming from an extension. If you use getUserMedia on a website Firefox shows persistent UI that clues you in to what tab is actually accessing the camera or microphone.

Further, you can’t just close an extension background page like a tab, so that’s a bit more complicated, too.

That’s at least how I understood the challenges.

There’s probably a couple of bugs about this on bugzilla that I’m not finding right now…


(Bernardogiordano) #3

Thank you for your reply.

So, as far as I’m understanding the situation, there currently is no way to implement what I’d like to do because it’s not possible with Firefox yet. Did I understand that correctly?

Is there any workaround or different approach to get this to work in other ways? I imagine it would take quite a while to get designed and implemented directly in Firefox.


(Martin Giger) #4

You should be able to make that call from an extension page open in a tab or a content script just fine, of course it is then bound to that tab being open.