Auto allow webcam access using Puppeteer for Node.js

隐身守侯 提交于 2019-12-10 20:00:02

问题


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.

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.

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?


回答1:


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()
})()


来源:https://stackoverflow.com/questions/48264537/auto-allow-webcam-access-using-puppeteer-for-node-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!