Reputation: 101
I tried to run this script to detect audio devices in Mozilla Firefox v50.1.0 on Ubuntu 16.04. [1]
navigator.mediaDevices.enumerateDevices()
.then(function(devices) {
devices.forEach(function(device) {
console.log(device.kind + ": " + device.label +
" id = " + device.deviceId);
});
})
.catch(function(err) {
console.log(err.name + ": " + err.message);
});
It detects only input devices, but no output. Works in Chrome and Opera, but not in Firefox.
By the way, I needed to manually add my page's domain to media.getusermedia.screensharing.allowed_domains in Firefox's about:config to get popup window prompting to allow sharing my devices. Why is this necessary?
Upvotes: 3
Views: 4156
Reputation: 338
Just in case this is still useful for somebody, I fixed it just by adding this line
await navigator.mediaDevices.getUserMedia({audio: true, video: false})
above
const mediaDevices: MediaDeviceInfo[] = await navMediaDevices.enumerateDevices()
.
Just like this:
await navigator.mediaDevices.getUserMedia({audio: true, video: false});
const mediaDevices: MediaDeviceInfo[] = await navMediaDevices.enumerateDevices();
console.log("mediaDevices:", mediaDevices)
Upvotes: 2
Reputation: 42490
Enumeration and selection of output devices (speakers) are not implemented yet in Firefox.
Update: Starting with Firefox 63, the feature is behind a pref. If you turn on media.setsinkid.enabled
in about:config then output devices are included in enumerateDevices similar to how Chrome does it (requires microphone permission).
However, requiring microphone permission to access speakers never made a lot of sense. It's a permission escalation that effectively renders the feature useless outside of web conferencing.
There are also fingerprinting (tracking) concerns with the existing API, as it exposes ongoing information about the user's system to sites after just a single use of microphone in Chrome.
Firefox and Safari never added setSinkId
for those reasons. The latest version of the spec adds selectAudioOutput which addresses those concerns, and is likely what will be implemented.
By the way, I needed to manually add my page's domain ...
There's no domain whitelist requirement for sharing cameras & microphones in Firefox. Never was. There won't be for output devices either, once they're implemented.
The domain whitelist you mention is only for screen sharing, the sharing of one's desktop. Even that requirement has been removed as of Firefox 52, where it's been replaced by a warning.
Screen sharing devices aren't enumerated with enumerateDevices
, so maybe not what you're after, but I'll cover the reason anyway:
The reason for that whitelist (now warning) is a security risk inherent specifically in sharing one's browser window on the web. In short, such sharing allows a site to see the pixels of sites it summons from other domains, doing an end-run around cross-origin protections. A malicious site could use this to pop up your private information from other sites you're logged in to, effectively browsing as you, and capturing the result, stealing your private data.
You can read more about this in my blog.
Upvotes: 7