如题: 业务需要,需要音频通话,代码如下:
'''
chrome_options = Options()
# 无头模式启动
chrome_options.add_argument('--headless')
# 禁用显卡
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('lang=zh_CN.UTF-8')
# 最大化窗口
chrome_options.add_argument("start-maximized")
chrome_options.add_argument("--remote-debugging-port=9222")
# 不加载图片
chrome_options.add_argument('blink-settings=imagesEnabled=false')
# chrome_options.add_argument('--user-data-dir="C:\\Users\\xuym26145\\AppData\\Local\\Google\\Chrome\\User Data"')
# 允许麦克风,相机,不然无法通话 1 允许 2 禁止
chrome_options.add_experimental_option("prefs", {
"profile.default_content_setting_values.media_stream_mic": 1, # 开启麦克风
"profile.default_content_setting_values.media_stream_camera": 1,
"profile.default_content_setting_values.geolocation": 1,
"profile.default_content_setting_values.notifications": 1,
"profile.managed_default_content_settings.images": 2 # 不加载图片,加快访问速度
})
capa = DesiredCapabilities.CHROME
capa["pageLoadStrategy"] = "none" # 懒加载模式,不等待页面加载完毕
driver = webdriver.Chrome(executable_path= "chromedriver.exe",desired_capabilities=capa, options=chrome_options) # 关键!记得添加
wait = WebDriverWait(driver, 20) # 等待的最大时间 20s
'''
现在不开无头模式,可以实现语音,因为设置允许了麦克风 1 为允许,但是开了无头模式,怎么滴都就是不生效,开 debug 看界面也是不行,求大佬解惑???
1
p1094358629 OP 困扰了我两天,中不得解,如有大侠江湖救济,必当感激不尽,甚至可有偿喝茶
|
2
p1094358629 OP !!!!!!!!!挽尊
|
3
13k 2019-12-20 15:02:58 +08:00
老版本说是 it's not possible to control permissions in headless mode currently
|
4
p1094358629 OP @13k 老哥 这个日志哪儿看的??
|
5
13k 2019-12-20 15:07:52 +08:00
给你个链接 github.com/Michael-Overall/CodeTalker/blob/chrome-headless/Research/chromeHeadlessMicInput.md
看最后那个 section:On Windows |
6
p1094358629 OP @13k 谢谢! 作者说的其实我有尝试,并未 success.
作者最后说了: and this was invalid because Chrome had no history of this new file being accessed. |
7
lxk11153 2020-04-29 05:12:22 +08:00
类似这种配置都是哪看来的?我怎么没看到官方文档?
profile.default_content_setting_values.images |