10

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?

Jay
  • 3,373
  • 6
  • 38
  • 55
  • Suspect a security block here. Not sure whether any browser will allow a web cam access without user interaction – Rippo Jan 18 '18 at 07:15

1 Answers1

28

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()
})()
user2080739
  • 396
  • 3
  • 3