SamuelScheit / puppeteer-stream

A Library for puppeteer to retrieve audio and/or video streams
MIT License
335 stars 105 forks source link

stream doesn't work when "--use-fake-ui-for-media-stream" argument is passed #52

Closed imbdb closed 1 year ago

imbdb commented 2 years ago

I need to record a page which needs access to webcam and mic. After passing "--use-fake-ui-for-media-stream", stream is not working and recording results in a zero byte page.

example

const file = fs.createWriteStream(__dirname + "/test.webm");

async function test() {
    const browser = await launch(puppeteer, {
        defaultViewport: {
            width: 1920,
            height: 1080,
        },
        args:[
            "--use-fake-ui-for-media-stream"
        ]
    });

    const page = await browser.newPage();
    await page.goto("PAGE-THAT-NEEDS-MEDIA-PERMISSIONS");
    const stream = await getStream(page, { audio: true, video: true });
    console.log("recording");

    stream.pipe(file);
    setTimeout(async () => {
        await stream.destroy();
        file.close();
        console.log("finished");
    }, 1000 * 10);
}

test();
imbdb commented 2 years ago

Workaround We can use overridePermissions instead of the argument --use-fake-ui-for-media-stream

const context = browser.defaultBrowserContext()
await context.overridePermissions("<ORIGIN_OF_TEST_PAGE>", ['camera', 'microphone'])

replace <ORIGIN_OF_TEST_PAGE> with the origin you need to test

imbdb commented 1 year ago

Closing Issue as I think the workaround is the way to go.

Harsh4999 commented 1 year ago

You are saviour man