How To Enable Media Device Access In Edge Browser Using Selenium?
Solution 1:
I have reproduced the problem on my machine, but I think this is a Windows behavior, and we can't set using selenium.
From this article, we can see that:
How to allow a website to use your camera or microphone while browsing in Microsoft Edge
You can use your camera and microphone for websites in Microsoft Edge. However, even when your camera and microphone are enabled for Microsoft Edge, you will still need to give individual websites permission before they can use your camera and microphone. Here’s how:
- Go to a website that wants to use your microphone and/or camera.
- If a dialog box appears asking if you want to give the website permission to use your camera or microphone, select Allow once or Always allow, or close the dialog box to block access.
After allowed the permission, we can find this permission under the Manage permissions (Edge browser setting => Advanced => Manage permissions), screenshot as below:
From your description, when Edge browser exit, you will clear sessions, cookie and cache, if you don't want to allow, the permission every time, you could uncheck the Website Permissions option (screenshot as below), the permission prompts will only show when we first visit the page.
Solution 2:
I've found a solution which works quite well. Instead of trying to click the button to allow media devices, I can add the site to Edge's list of media devices allowed sites in the registry. I can then visit a site requiring media devices almost instantly after and no popup.
The registry path you want is
HKEY_CURRENT_USER\SOFTWARE\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppContainer\Storage\microsoft.microsoftedge_8wekyb3d8bbwe\MicrosoftEdge\MediaCapture\AllowDomains
Which appears to be the same on all Windows 10 machines I test on.
In there you want to create a DWORD key of the protocol and IP/FQDN, e.g. http://10.0.0.2
or https://example.com
, and the value Edge sets when you allow a domains is 3
, so I use that.
In my particular case I've switched to IronPython so I can easily hook into Windows API calls. Here is a snippet of my code to make this work.
from Microsoft.Win32import Registry
def add_edge_media_domain(domain):
path ="HKEY_CURRENT_USER\\SOFTWARE\\Classes\\Local Settings\\Software\\Microsoft\\Windows\\CurrentVersion\\AppContainer\\Storage\\microsoft.microsoftedge_8wekyb3d8bbwe\\MicrosoftEdge\\MediaCapture\\AllowDomains"Registry.SetValue(path, domain, 3)
Before I call driver.get(url)
I call add_edge_media_domain(trim_url(url))
where trim_url
just cuts the path part off the URL.
Post a Comment for "How To Enable Media Device Access In Edge Browser Using Selenium?"