如何允许Chrome以编程方式使用我的麦克风? [英] How do I allow Chrome to use my microphone programmatically?

查看:215
本文介绍了如何允许Chrome以编程方式使用我的麦克风?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试运行一些使用webdriverjs和chromedriver进行的测试,但它们需要麦克风权限.

I am currently trying to run some tests made with webdriverjs and chromedriver but they need microphone permissions.

这是显示的弹出窗口:

我尝试过:

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

但是没有用.

我也尝试过

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

它也不起作用!我想这不是一个普通的警报.

it did not work either! I guess that this is not an ordinary alert.

有用的链接:

Chrome启动参数列表

Java和ruby的Chrome选项

Chromedriver github

如何通过编程方式授予他们权限?

这附近是否有任何标志或其他方式?

推荐答案

每次运行selenium时,都会加载一个新的配置文件,因此在会话之间不会保留对首选项和网站权限所做的更改.要对此进行修改,我们需要告诉selenium要加载哪个配置文件.

A fresh profile is loaded each time you run selenium, hence changes you make to the preferences and website permissions are not preserved between sessions. To amend this we need to tell selenium which profile to load.

第1步.找到您的Chrome偏好设置文件: www.forensicswiki.org/wiki/Google_Chrome#Configuration

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

步骤2.将文件夹Default复制到某处.我假设它已复制到/some/path/allow-mic/Default.

Step 2. Copy the folder Default somewhere. I will assume it is copied to /some/path/allow-mic/Default.

替代步骤3(这更容易): 复制Default之前,请使用Chrome浏览localhost:1337并将麦克风设置为始终允许.

Alternative Step 3 (this is easier): Before copying Default visit localhost:1337 with Chrome and set mic to always allow.

第3步.编辑allow-mic/Default/Preferences,找到彼此之间的标签"profile""content_settings""exceptions"并添加

Step 3. Edit allow-mic/Default/Preferences, find the tags "profile", "content_settings" and "exceptions" within each other and add

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

"exceptions".您应该以如下形式结束:

to "exceptions". You should end up with something like:

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

第4步: 配置selenium以使用编辑的首选项:

Step 4: Configure selenium to use the edited 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);

您可以通过打开chrome://version/来检查是否使用了正确的首选项集(配置文件路径).

You can check that the correct set of preferences (Profile path) are in use by opening chrome://version/.

这篇关于如何允许Chrome以编程方式使用我的麦克风?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆