SamuelScheit / puppeteer-stream

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

browser closes immediately after starting stream #42

Closed mmohammadi9812 closed 2 years ago

mmohammadi9812 commented 2 years ago

Hi there I'm trying to use this library to record a page, but it gets closed after stream starts piping to file

this is the code:

const puppeteer = require('puppeteer');
const puppeteerStream = require("puppeteer-stream");
const fs = require("fs");

const executablePath = 'somepath';
const file = fs.createWriteStream(__dirname + "/demo-2.webm");
(async () => {
  const browser = await puppeteerStream.launch({
    executablePath,
    args: [
      '--autoplay-policy=no-user-gesture-required',
      '--no-sandbox',
    ],
  });
  const [ page ] = await browser.pages();
  await page.goto("http://localhost:3000");
  const stream = await puppeteerStream.getStream(page, { audio: true, video: true });
  console.log("recording");

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

  await browser.close();
})()

I tried the ffmpeg example too, but in both cases, as soon as I see recording on console, the browser closes without any error or warning on console

thanks for this library, and I'd appreciate if anyone can help

mmohammadi9812 commented 2 years ago

Ok, I came to this from an stack overflow question, but I think I'm in the wrong place and didn't read description properly Sorry, closing