Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 通过Selenium Chromedriver自动授权访问Chrome 48中的视频和音频_Java_Google Chrome_Selenium_Selenium Chromedriver - Fatal编程技术网

Java 通过Selenium Chromedriver自动授权访问Chrome 48中的视频和音频

Java 通过Selenium Chromedriver自动授权访问Chrome 48中的视频和音频,java,google-chrome,selenium,selenium-chromedriver,Java,Google Chrome,Selenium,Selenium Chromedriver,我想通过Chromedriver功能自动授权访问Chrome中的视频和音频 根据(相当古老的)答案,我尝试了以下方法: DesiredCapabilities capabilities = DesiredCapabilities.chrome(); ChromeOptions options = new ChromeOptions(); Map<String, Object> prefs = new HashMap<>(); // with this chrome st

我想通过Chromedriver功能自动授权访问Chrome中的视频和音频

根据(相当古老的)答案,我尝试了以下方法:

DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
Map<String, Object> prefs = new HashMap<>();

// with this chrome still asks for permission
prefs.put("profile.managed_default_content_settings.media_stream", 1);
prefs.put("profile.managed_default_content_settings.media_stream_camera", 1);
prefs.put("profile.managed_default_content_settings.media_stream_mic", 1);

// and this prevents chrome from starting
prefs.put("profile.content_settings.exceptions.media_stream_mic.https://*,*.setting", 1);
prefs.put("profile.content_settings.exceptions.media_stream_mic.https://*,*.last_used", 1);
prefs.put("profile.content_settings.exceptions.media_stream_camera.https://*,*.setting", 1);
prefs.put("profile.content_settings.exceptions.media_stream_camera.https://*,*.last_used", 1);

// and this prevents chrome from starting as well
prefs.put("profile.content_settings.pattern_pairs.https://*,*.media_stream.video", "Allow");
prefs.put("profile.content_settings.pattern_pairs.https://*,*.media_stream.audio", "Allow");

options.setExperimentalOption("prefs", prefs);
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
DesiredCapabilities=DesiredCapabilities.chrome();
ChromeOptions选项=新的ChromeOptions();
Map prefs=新的HashMap();
//使用此chrome仍需要获得许可
prefs.put(“profile.managed\u default\u content\u settings.media\u stream”,1);
prefs.put(“profile.managed\u default\u content\u settings.media\u stream\u camera”,1);
prefs.put(“profile.managed\u default\u content\u settings.media\u stream\u mic”,1);
//这可以防止铬启动
prefs.put(“profile.content\u settings.exceptions.media\u stream\u mic.https://*,*.setting”,1);
prefs.put(“profile.content\u settings.exceptions.media\u stream\u mic.https://*,*。上次使用的内容”,1);
prefs.put(“profile.content\u settings.exceptions.media\u stream\u camera.https://*,*.setting”,1);
prefs.put(“profile.content\u settings.exceptions.media\u stream\u camera.https://*,*。上次使用的”,1);
//这也阻止了铬的启动
prefs.put(“profile.content\u settings.pattern\u pairs.https://*,*.media\u stream.video”,“Allow”);
prefs.put(“profile.content\u settings.pattern\u pairs.https://*,*.media\u stream.audio”,“Allow”);
选项。设置实验选项(“prefs”,prefs);
能力。设置能力(ChromeOptions.CAPABILITY,选项);

关于如何正确授予权限,有什么想法吗?

我认为它需要特定于站点,以下内容适合我: prefs.put(“profile.content\u settings.exceptions.media\u stream\u camera.”、“.setting”、“1”); prefs.put(“profile.content\u settings.exceptions.media\u stream\u mic.”、“.setting”、“1”)

此外,我认为该网站需要在单引号,否则它将无法正确解析


试一试。

面临类似问题,解决方法如下:

ChromeOptions options = new ChromeOptions();
options.addArguments("--use-fake-ui-for-media-stream=1");
driver = new ChromeDriver(options);
也可以使用以下方法更改默认摄影机:

Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("media.default_video_capture_Device", "\\\\?\\root#media#0002#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\\global");
options.setExperimentalOption("prefs", prefs);
Map prefs=new HashMap();
prefs.put(“媒体默认视频捕获设备”,“根媒体0002”{65e8773d-8f56-11d0-a3b9-00a0c9223196}\\global”);
选项。设置实验选项(“prefs”,prefs);

摄像头代码可以从设置窗口(使用开发工具检查)或Chrome目录中的首选项文件中获取。

存在安全限制,因为默认情况下无法设置媒体首选项。 但是,通过在首选项中启用所需的设置(如Commo#1中所述),我们有一个解决方法 1.使用“/path/to/chrome--user data dir=/give/some/path/for/profileDir”手动运行chrome。 2.转到显示视频允许或阻止弹出消息的所需URL 3.点击允许按钮 4.去chrome://settings/content ->单击“媒体”部分->下的“管理异常”按钮,您将发现URL已添加到“管理异常”框中 5.现在,使用下面的代码将此用户数据目录传递给chromedriver

Java代码-

ChromeOptions options = new ChromeOptions(); 
options.addArguments("user-data-dir=/path/to/the/saved/profileDir");
WebDriver driver = new ChromeDriver(options);

不,这并不是修复它的原因,我使用的是一个已经设置好的用户配置文件:final ChromeOptions options=new ChromeOptions();options.addArguments(“--user data dir=/path/to/some/profile/that/allows/video”);