更新时间:2023-01-14 23:33:03
我找到了一个非常有效的解决方案.我可以将站点添加到 Edge 在注册表中允许的媒体设备站点列表中,而不是尝试单击按钮以允许媒体设备.然后,我几乎可以立即访问需要媒体设备的网站,并且不会弹出任何窗口.
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.
你想要的注册表路径是
HKEY_CURRENT_USER\SOFTWARE\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppContainer\Storage\microsoft.microsoftedge_8wekyb3d8bbwe\MicrosoftEdge\MediaCapture\AllowDomains
这在我测试过的所有 Windows 10 机器上似乎都一样.
Which appears to be the same on all Windows 10 machines I test on.
在那里您要创建协议和 IP/FQDN 的 DWORD 键,例如http://10.0.0.2
或 https://example.com
,Edge 在允许域时设置的值为 3
,所以我用那个.
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.
在我的特殊情况下,我已切换到 IronPython,因此我可以轻松地连接到 Windows API 调用.这是我用来完成这项工作的代码片段.
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.Win32 import 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)
在我调用 driver.get(url)
之前,我调用了 add_edge_media_domain(trim_url(url))
,其中 trim_url
只是切断了路径部分网址.
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.