I would like to automatically grant access to video and audio in Chrome via Chromedriver capabilities.
Based on this (pretty old) answer I tried the following:
There is a security limitation because of which media preferences cannot be set by default. However, we have a workaround by enabling the required settings in preferences (As mentioned in commen#1) 1. Run chrome manually with "/path/to/chrome --user-data-dir=/give/some/path/for/profileDir". 2. Go to your required URL where it shows Video allow or block popup message 3. Click on Allow button 4. Go to chrome://settings/content -> click on Manage exception button under Media section -> Here, you will find that the URL has been added to the manage exception box 5. Now, pass this user data directory to chromedriver with the use of below code
Java Code -
ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=/path/to/the/saved/profileDir");
WebDriver driver = new ChromeDriver(options);
I think it needs to be site specific, the following works for me: prefs.put("profile.content_settings.exceptions.media_stream_camera.'https://somewebsite.com:443,'.setting", "1"); prefs.put("profile.content_settings.exceptions.media_stream_mic.'https://somewebsite.com:443,'.setting", "1");
Also, I think the website needs to be in single quotes or it won't parse right.
Give that a shot.
Faced similar issue, solved with this:
ChromeOptions options = new ChromeOptions();
options.addArguments("--use-fake-ui-for-media-stream=1");
driver = new ChromeDriver(options);
You can also change default camera using this method:
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);
Camera code could be obtained from settings window (inspect with dev tools) or from preferences file in Chrome directory.