Sarah German
Sarah German

Reputation: 172

Selenium ChromeDriver - Remember "Always Allow" setting for getUserMedia webcam access

I've got a page running on a local webserver, on an https page, that uses the getUserMedia API to do some photobooth-style webcam stuff.

In ChromeDriver, the browser won't remember the "Always allow" setting for allowing webcam access. I'm given the option, and it remembers that preference while the browser's running, but once I quit/re-open, the prompt returns.

I'm running Chromedriver 26.0.1383.0.

Does anybody know how to make that preference stick around permanently?

Upvotes: 1

Views: 4419

Answers (2)

dey.shin
dey.shin

Reputation: 990

I had the same issue. I solved it by doing the following in C#

var driverService = ChromeDriverService.CreateDefaultService();
var options = new ChromeOptions();

options.AddArgument("use-fake-device-for-media-stream");
options.AddArgument("use-fake-ui-for-media-stream");

var ChromeDriver = new ChromeDriver(driverService, options);

It's very similar to siddhadev's suggestion. Figured I'd add a codding sample showing how Chrome Options can be used within Selenium.

Hope this helps!

Upvotes: 2

siddhadev
siddhadev

Reputation: 16631

Try using HTTPS, than you should be able to remember/skip the prompt.

As an alternative you could override the security policy with the --disable-web-security command line option or use a faked device --use-fake-device-for-media-stream (which should be enough for testing).

Give it a try by creating a file test.html containing

<!DOCTYPE HTML>
<video autoplay/>
<script>
  navigator.webkitGetUserMedia({audio:true,video:true},
    function(stream){
      document.querySelector('video').src =
        URL.createObjectURL(stream);
    });
</script>

and than kill all chrome instances and start chrome like this:

 chrome.exe --use-fake-device-for-media-stream --disable-web-security test.html

Upvotes: 2

Related Questions