SamuelScheit / puppeteer-stream

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

[QUESTION] How to stop recording on button click #64

Closed Sed9yDataBank closed 1 year ago

Sed9yDataBank commented 1 year ago

Puppeteer navigates to a certain web page and starts recording it. I want to be able to stop the recording when an external user click on a button on that certain webpage. Is This possible? (I tried setting an Event Listener but it doesn't work)

Currentley in README there is this but it is not what I want / stopping the recording withsetTimeout

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

You could expose a function from node inside the browser process and then stop the stream on invocation:

page.exposeFunction("buttonSubmit", () => {
    stream.destroy()
})

and inside the page you have a button

<button onclick="buttonSubmit()" />