Unable to allow website camera and microphone access with Selenium ChromeDriver

Viewed 923

I am trying to automate the process of joining a conference call but I'm running into issues with video and audio permissions. I want to allow selenium access to video and audio.

enter image description here

After searching online for a solution for over a day, here's what I've tried with zero success:

1.Using just setChromeOptions:

let driver = new Builder()
        .usingServer("http://127.0.0.1:4444/wd/hub/")
        .forBrowser("chrome")
        .setChromeOptions({
            "prefs": {
                "profile.default_content_setting_values.media_stream_mic": 1,
                "profile.default_content_setting_values.media_stream_camera": 1
            },
            "args": ["--use-fake-device-for-media-stream", "--use-fake-ui-for-media-stream"]
        })
        .build();

This doesn't seem to do anything. I'm not getting any error when I run this but it's not helping either.

  1. Using capabilites:
let driver = new Builder()
        .usingServer("http://127.0.0.1:4444/wd/hub/")
        .forBrowser("chrome")
        .withCapabilities({ "browserName": "Chrome", "chromeOptions": {
            "args": ["--use-fake-device-for-media-stream", "--use-fake-ui-for-media-stream"]
            }
        })
        .build();

Which gives me this error which I haven't been able to figure out how to resolve: enter image description here

I really need this to work and I can't seem to find a way. Any help is highly appreciated.

Node version: v15.5.1

1 Answers

The following preferences should do the trick:

Python

prefs = {
    "hardware.audio_capture_enabled": True,
    "hardware.video_capture_enabled": True,
    "hardware.audio_capture_allowed_urls": ["https://www.omegle.com"],
    "hardware.video_capture_allowed_urls": ["https://www.omegle.com"]
}

options.add_experimental_option("prefs", prefs)

driver = webdriver.Chrome(options=options)
driver.get('https://www.omegle.com/')

NodeJS

let driver = new Builder()
    .usingServer("http://127.0.0.1:4444/wd/hub/")
    .forBrowser("chrome")
    .setChromeOptions({
        "prefs": {
           "hardware.audio_capture_enabled": true,
           "hardware.video_capture_enabled": true,
           "hardware.audio_capture_allowed_urls": ["https://www.omegle.com"],
           "hardware.video_capture_allowed_urls": ["https://www.omegle.com"]
        }   
    })
    .build();
driver.get('https://www.omegle.com/');

Note: Remember to change the example URL with your own!

Related