使用Puppeteer for Node.js自动允许网络摄像头访问 [英] Auto allow webcam access using Puppeteer for Node.js

查看:390
本文介绍了使用Puppeteer for Node.js自动允许网络摄像头访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设置一个涉及启动网络摄像头视频会话的测试.

I'm setting up a test that involves starting a webcam video session.

到目前为止,一切正常,除了授予对网络摄像头的访问权限外,不需要任何用户交互.

So far all is working fine and doesn't require any user interaction except for granting access to the webcam.

当我正在使用的第三方库发出呼叫时:navigator.mediaDevices.getUserMedia({audio: true, video: true}) 浏览器将打开提示,要求用户允许访问.

When the third party library I'm using makes the call: navigator.mediaDevices.getUserMedia({audio: true, video: true}) the browser opens a prompt asking the user to allow access.

我正在寻找一种无需用户干预即可授予访问权限的方法.

What I'm looking for is a way to grant access without user interaction.

我已经尝试过操纵人偶的page.on('dialog'...,但是网络摄像头访问提示没有被调用.

I've tried puppeteer's page.on('dialog'... but that doesn't get called for the webcam access prompt.

请让我知道您有什么想法吗?

Please let me know if you have any ideas?

推荐答案

Google Chrome浏览器具有启动选项--use-fake-ui-for-media-stream,该选项允许用户跳过getUserMedia的提示. 您可以使用如下所示的puppeteer进行设置.

Google Chrome has a launch option --use-fake-ui-for-media-stream that allows the user to skip a prompt of getUserMedia. And you can set it with puppeteer like below.

const puppeteer = require('puppeteer')
;(async () => {
    const browser = await puppeteer.launch({
        args: [ '--use-fake-ui-for-media-stream' ]
    })
    const page = await browser.newPage()
    await page.goto('http://localhost/start-video-test.html')
    const startVideoButton = await page.$('#startVideoButton')
    startVideoButton.click()
    // video session starts without prompt
    return browser.close()
})()

这篇关于使用Puppeteer for Node.js自动允许网络摄像头访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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