如何停止Chrome/Edge/Chromium/等。从任何其他浏览器(包括铬等)窗口阻止对相机的访问
我在Java中使用Selenium 4来控制Chrome和Edge以及其他浏览器,以测试视频通话应用程序。我有一个测试,我可以一次启动2个不同的浏览器,以使它们与彼此进行交流。我正在使用obs为虚拟网络摄像头提供可自定义的供稿,以便可以为任何一个浏览器切换输入。
当我启动2个铬家族浏览器时,我会发现一个问题,即(一次)我启动的第一个可以获取并显示摄像机的完整列表,而另一个则没有显示出来 - 即使在等待15分钟之后。如果我作为浏览器启动Firefox和Chrome,那么他们都可以访问网络摄像头列表(但仅当Firefox首先访问网络摄像头时)。
由于不计划在WebApp的第一个版本中支持Firefox,因此将大部分是Chromium Family浏览器供我测试(我在Windows上,所以此时我无法测试Safari)。有人知道为什么会发生这种情况以及如何解决吗?
我如何开始Chrome:
ChromeOptions chromeOptions= new ChromeOptions();
chromeOptions.addArguments("use-fake-ui-for-media-stream");
chromeDriver = new ChromeDriver(chromeOptions);
如何开始边缘:
EdgeOptions edgeOptions= new EdgeOptions();
edgeOptions.addArguments("use-fake-ui-for-media-stream");
edgeDriver = new EdgeDriver(edgeOptions);
如何开始Firefox:
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.addPreference("browser.cache.disk.enable", false);
firefoxOptions.addPreference("browser.cache.disk.capacity", 0);
firefoxOptions.addPreference("browser.cache.disk.smart_size.enabled", false);
firefoxOptions.addPreference("browser.cache.disk.smart_size.first_run", false);
firefoxOptions.addPreference("browser.sessionstore.resume_from_crash", false);
firefoxOptions.addPreference("browser.startup.page", 0);
firefoxOptions.addPreference("media.navigator.permission.disabled", true);
firefoxOptions.addPreference("device.storage.enabled", false);
firefoxOptions.addPreference("media.gstreamer.enabled", false);
firefoxOptions.addPreference("browser.startup.homepage", "about,blank");
firefoxOptions.addPreference("browser.startup.firstrunSkipsHomepage", false);
firefoxOptions.addPreference("extensions.update.enabled", false);
firefoxOptions.addPreference("app.update.enabled", false);
firefoxOptions.addPreference("network.http.use-cache", false);
firefoxOptions.addPreference("browser.shell.checkDefaultBrowser", false);
firefoxDriver = new FirefoxDriver(firefoxOptions);
I am using Selenium 4 in java to control Chrome and Edge and other browsers in order to test a video call app. I have a test where I'm starting up 2 different browsers at once in order to get them to communicate with each-other. I am using OBS to provide virtual webcams with customizable feeds so that I can switch input for either browser.
When I start up 2 Chromium-family browsers I get an issue that only the first one I launch (at a time) can get and show the full list of cameras while the other one shows nothing - even after waiting 15+ minutes. If I launch Firefox and Chrome as my browsers then they both can access the webcam list (but only if Firefox accesses the webcams first).
Since Firefox is not planned to be supported for the first version of the webapp, that leaves mostly chromium family browsers for me to test with (I'm on windows so I can't test safari at this point). Does anyone know why this is happening and how I could fix it?
How I start Chrome:
ChromeOptions chromeOptions= new ChromeOptions();
chromeOptions.addArguments("use-fake-ui-for-media-stream");
chromeDriver = new ChromeDriver(chromeOptions);
How I start Edge:
EdgeOptions edgeOptions= new EdgeOptions();
edgeOptions.addArguments("use-fake-ui-for-media-stream");
edgeDriver = new EdgeDriver(edgeOptions);
How I start Firefox:
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.addPreference("browser.cache.disk.enable", false);
firefoxOptions.addPreference("browser.cache.disk.capacity", 0);
firefoxOptions.addPreference("browser.cache.disk.smart_size.enabled", false);
firefoxOptions.addPreference("browser.cache.disk.smart_size.first_run", false);
firefoxOptions.addPreference("browser.sessionstore.resume_from_crash", false);
firefoxOptions.addPreference("browser.startup.page", 0);
firefoxOptions.addPreference("media.navigator.permission.disabled", true);
firefoxOptions.addPreference("device.storage.enabled", false);
firefoxOptions.addPreference("media.gstreamer.enabled", false);
firefoxOptions.addPreference("browser.startup.homepage", "about,blank");
firefoxOptions.addPreference("browser.startup.firstrunSkipsHomepage", false);
firefoxOptions.addPreference("extensions.update.enabled", false);
firefoxOptions.addPreference("app.update.enabled", false);
firefoxOptions.addPreference("network.http.use-cache", false);
firefoxOptions.addPreference("browser.shell.checkDefaultBrowser", false);
firefoxDriver = new FirefoxDriver(firefoxOptions);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论