prasanaworld/puppeteer-screen-recorder

How can I add an event listener to stop recording

Closed this issue · 1 comments

  • **I'm submitting a **
    [x] question about how to use this project

  • Summary

I want to stop recording only when an element is clicked on the webpage (not by Puppeteer)

Hi @Sed9yDataBank,

Thanks for reaching out. I believe this question is not specific to puppeteerScreenRecorder library.

But I'm happy to answer the problem your trying to resolve, you could expose a function using exposeFunction and bind it to button which your trying to hook, and in the callback of the exposed function you can trigger recorder.stop()

Sample code

const recorder = new PuppeteerScreenRecorder(page);
await recorder.start('./report/video/simple.mp4'); 
....
await page.exposeFunction('SomeButtonclickHandler',  ({ type, detail }) => {
    recorder.stop();
});

// listen for events of type 'status' and
// pass 'type' and 'detail' attributes to our exposed function
await page.evaluateOnNewDocument(() => {
    window.addEventListener('status',  window.SomeButtonclickHandler);
});