How can I programmatically grant Chrome access to my microphone?

I am facing a challenge while running tests using webdriverjs and chromedriver as they require microphone permissions.

Here is the popup that keeps appearing:

https://i.sstatic.net/AYx67.png

Attempts made so far:

    chromedriver.start(['--disable-popup-blocking']);
    driver = new Webdriver.Builder()
    .withCapabilities(Webdriver.Capabilities.chrome())
    .build();

Unfortunately, these attempts did not yield any positive results.

Another approach taken:

    driver.wait(Until.alertIsPresent(), config.TIMEOUT, 'Alert did not show up');
    driver.switchTo().alert().accept();

Surprisingly, this method also failed! It seems like this alert is not an ordinary one.

Resources worth checking out:

List of Chrome startup arguments

Chrome options for java and ruby

Chromedriver on GitHub

How can microphone permissions be granted programmatically?

Are there any flags or alternative solutions to this issue?

Answer №1

Although it's a bit late, I'm sharing the steps on how to accomplish this for anyone else searching for the same information.

const webdriver = require('selenium-webdriver'), By = webdriver.By, until = webdriver.until,Builder= webdriver.Builder;

var chrome = require('selenium-webdriver/chrome');

var chromeOptions = new chrome.Options()
.addArguments('allow-file-access-from-files')
.addArguments('use-fake-device-for-media-stream')
.addArguments('use-fake-ui-for-media-stream');

var driver = new webdriver.Builder()
.forBrowser('chrome')
.setChromeOptions(chromeOptions);

driver = driver.build();

Answer №2

Every time selenium is run, a new profile is loaded which means any changes made to preferences and website permissions are not saved for future sessions. To address this issue, we must specify which profile selenium should use.

Step 1. Locate your Chrome preferences file: www.forensicswiki.org/wiki/Google_Chrome#Configuration

Step 2. Create a copy of the folder Default in a separate location, for example, /some/path/allow-mic/Default.

Alternative Step 3 (simpler method): Before copying the Default folder, visit localhost:1337 in Chrome and set microphone permission to always allow.

Step 3. Edit the file allow-mic/Default/Preferences, locate the tags "profile", "content_settings", and "exceptions" nested within each other, and add the following code snippet:

"media_stream_mic":{"http://localhost:1337,*":
                                          {"last_used":1470931206,
                                           "setting":1} },

within the "exceptions" section. The final structure should resemble:

...
"profile":{
     ...
     "content_settings": {
         ...
         "exceptions": {
             ...
             "media_stream_mic":{"http://localhost:1337,*":
                                      {"last_used":1470931206,
                                       "setting":1} },
             ...
         },
    },
},
...

Step 4: Configure selenium to utilize the updated preferences:

var chromedriver = require('chromedriver');
var Webdriver = require('selenium-webdriver');
var chrome = require('selenium-webdriver/chrome');

var opts = new chrome.Options();                   
opts.addArguments("user-data-dir=/some/path/allow-camera");

var driver = new chrome.Driver(opts);

You can confirm that the correct set of preferences (Profile path) is being used by navigating to chrome://version/.

Answer №3

If you are a Python user, here's a solution that I found effective:

import selenium
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument("--use-fake-ui-for-media-stream")
driver = webdriver.Chrome(chrome_options=options)

Answer №4

To enable audio-capture for a specific URL, you can white-list it by setting the hardware.audio_capture_allowed_urls preference in chromedriver.


...
chrome_options = Options()
prefs = {"hardware.audio_capture_allowed_urls" : ["example.org"]}
chrome_options.add_experimental_option("prefs",prefs)
driver = webdriver.Chrome(chrome_options=chrome_options)

Answer №5

Similarly, when utilizing Splinter

    import splinter as sp
    from selenium.webdriver.chrome.options import Options 
    chrome_options = Options() 
    chrome_options.add_argument("--use-fake-ui-for-media-stream") 
    Browser('chrome', ** {'executable_path':'chromedriver'},options=chrome_options)

Answer №6

To utilize the microphone functionality,

chrome_options = Options()

chrome_options.add_experimental_option('prefs',{'profile.default_content_setting_values.media_stream_mic':1})


driver = webdriver.Chrome(path,chrome_options=chrome_options)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Transform the dynamic JSON format into a key-value pair structure with nested children nodes

Looking to convert a dynamic JSON structure into a tree node: { "video": { "width": 1920, "height": 1080, "video_codec": "H264", "CBR": "4337025", "frame_rate& ...

Configuring Proxy Settings for WebpackDevServer

I need assistance setting up a proxy using WebpackDevServer in my React/Node chrome extension. Currently, my server is running on localhost:4000, and the React frontend is on localhost:5000. When trying to access the route /api/user/ticket using Axios, I ...

In order to activate the input switch in Next.Js, it is necessary to initiate a

Currently, I am working on implementing an on-off switch in Next.Js. To seek assistance, I referred to this helpful video tutorial: https://www.youtube.com/watch?v=1W3mAtAT7os&t=740s However, a recurring issue I face is that whenever the page reloads, ...

Struggling to get a basic HTML form to function with JavaScript commands

In my form, there are two input fields and a button. Upon clicking the button, a JavaScript function is triggered which multiplies the values entered in the inputs. The result is then displayed in a <p> element and evaluated through an if else statem ...

Removing background color and opacity with JavaScript

Is there a way to eliminate the background-color and opacity attributes using JavaScript exclusively (without relying on jQuery)? I attempted the following: document.getElementById('darkOverlay').style.removeProperty("background-color"); docume ...

Is it the right time to implement a JavaScript framework?

Is there a need for using JavaScript frameworks like Angular or React if you are not developing single-page websites or components that receive live updates? ...

Ways to clear dropdown selection in Vue based on a specific condition?

I am currently developing a dropdown menu for selecting visit status options, which include "pending," "canceled," "rejected," and "approved." In the case of an approved visit status, I would like the dropdown selection to only display the options for "can ...

The error message "Adyencheckout is not a constructor" is popping up in my

Struggling to implement the Adyen dropin payment UI in NextJS and facing issues initializing the Adyen dropin component. Attempting to dynamically import Adyen web to avoid window is not defined error, but uncertain on how to use it as a constructor after ...

launch hyperlink in bootstrap popup

I have a challenge with showcasing multiple videos in a single modal without creating separate modals for each button. The function I found was effective with an older version of Bootstrap, but it no longer works with Bootstrap 3.3.7. Below is the HTML co ...

Type inference in TypeScript with transitivity

Consider this code snippet for illustration: function foo(t: "number"): number function foo(t: "string"): string function foo(t: "boolean"): boolean function foo(t: "number" | "string ...

Angular 2 encountered a fatal error: Issues with parsing the template:

Here is the code snippet I am currently working with: <div class="container"> <div [hidden]="loggedIn"> <md-grid-list cols="6" [style.margin-top]="'20px'"> <md-grid-tile [colspan]="1"></md-grid-tile> I have already ...

What is the reason for being able to access `$scope` and `this` using the controller as syntax?

Creating an Angular controller with the controller as syntax: <body ng-controller="ctrl as myCtrl"> <p>Accessed via scope resolution: {{ foo }} </p> <p>Accessed via controller resolution: {{ myCtrl.foo }}</p> </body> ...

Locating Elements in Selenium Using Text or Attribute Matching

Is there a wildcard I can use in Selenium to find an element based on a string that can be contained in the element's text or any attribute? I want to avoid using multi-condition OR logic. Currently, I'm using the following code which works: dri ...

I am looking to identify which tabs are active based on the current day using vuejs

With 7 tabs on my Vue.js page, I aim to activate the tab corresponding to the current day. However, I am facing a challenge where only the active tab is being highlighted and not allowing me to navigate to others after applying if-else statements. How can ...

What is the best way to ensure a navigation link stops scrolling at the bottom of a navbar that is set to position: sticky?

I am utilizing Bootstrap 5 for my website, and I have a sticky-top attribute on my navbar. When I click on one of the links in the navigation bar, the page scrolls to that section, but some of the content goes behind the navbar. I am looking for a way to m ...

Next.js is able to generate a unique URL that strictly handles code execution without any visual elements

Currently, I am in the process of developing a new website using NextJS. One issue that has come up involves a password reset verification endpoint. After a user initiates a password reset, it is sent to the API for processing and then redirected back to ...

Creating a React functional component that updates state when a specific window breakpoint is reached

Having an issue with my code when it hits the 960px breakpoint. Instead of triggering once, it's firing multiple times causing unexpected behavior. Can someone help me troubleshoot this problem? const mediaQuery = '(max-width: 960px)'; con ...

Creating a dynamic search feature that displays results from an SQL database with a dropdown box

Is there a way to create a search bar similar to those seen on popular websites like YouTube, where the search results overlay the rest of the page without displacing any content? I've searched extensively on Google and YouTube for tutorials on databa ...

Jquery Click function malfunctioning on testing environment

I'm facing a bit of challenge and could really use some assistance. I have this code snippet that functions perfectly in my test document, but once it's uploaded to the live server, everything loads correctly except for the fadeOut click function ...

Having trouble with setting up the next image configuration for graphcms' images

I've been using graphcms solely for my image assets and trying to integrate them into my Next JS (v12.0.1) frontend. However, I keep getting the error message hostname not configured in next.config.js, even though I have already specified it in my nex ...