我想通过Chromedriver功能自动授予Chrome中视频和音频的访问权限.
根据this(相当古老)的答案我尝试了以下内容:
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
Map 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);
有关如何正确授予权限的任何想法?