Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto allow webcam access using 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.

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?

like image 981
Jay Avatar asked Jan 15 '18 14:01

Jay


1 Answers

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()
})()
like image 126
user2080739 Avatar answered Sep 23 '22 17:09

user2080739