我如何让Chrome以编程方式使用我的麦克风? [英] How do i allow Chrome to use my microphone programatically?

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

问题描述

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



这是显示的弹出窗口:





我曾尝试过:

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

但没有用。

我也试过

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

它也行不通!我想这不是一个普通的警报。



有用的链接:



java和ruby的Chrome选项



Chromedriver github



我如何以编程方式授予他们权限?



是否有任何标记或其他方法?

解决方案

每次运行selenium时都会加载一个新配置文件,因此您不会在会话之间保留对首选项和网站权限所做的更改。要修正这个问题,我们需要告诉Selenium加载哪个配置文件。第1步。找到您的Chrome首选项文件: www.forensicswiki.org/wiki/Google_Chrome#Configuration

第2步。复制文件夹默认某处。我会假设它被复制到 / some / path / allow-mic / Default



这很容易):
复制之前默认使用Chrome访问 localhost:1337 并将麦克风设置为始终允许。

步骤3.编辑 allow-mic / Default / Preferences ,找到标签 profilecontent_settingsexceptions / p>

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

例外。您最终应该得到如下结果:

  ... 
profile:{
.. 。
content_settings:{
...
例外:{
...
media_stream_mic:{http:// localhost:1337 ,*:
{last_used:1470931206,
setting:1}},
...
},
},
},
...

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

  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);

您可以通过打开<$ c来检查正确的一组首选项(配置文件路径) $ c> chrome:// version / 。


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

This is the popup that shows up:

I have tried:

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

but it didn't work.

I also tried

    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.

Useful links:

Chrome startup arguments list

Chrome options for java and ruby

Chromedriver github

How do i give them permissions programatically?

Is there any flag or some other way around this?

解决方案

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.

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

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

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

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} },

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

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

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);

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

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

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