SamuelScheit / puppeteer-stream

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

Implement new headless mode && Fix still rarely occurring TargetCloseError && Update doc accordingly #157

Closed TalkLounge closed 4 months ago

TalkLounge commented 5 months ago

The Fixes

Headless: "new"

TargetCloseError

This error still rarely occurs for me. So I added the optional option closeDelay to launch options, which adds an additional delay between the last browser interaction and browser closing

Doc

Mention new headless mode and does some cleanup

How to test in debugging

  1. Create a new node project
  2. Install puppeteer-stream: npm i puppeteer-stream
  3. Create index.js file and set the content to
    
    const { launch, getStream, wss } = require("puppeteer-stream");
    const fs = require("fs");

(async () => { const browser = await launch({ executablePath: "C:/Program Files/Google/Chrome/Application/chrome.exe", headless: "new", closeDelay: 500, defaultViewport: { width: 1920, height: 1080 } }); const page = await browser.newPage(); await page.goto("https://www.youtube.com/embed/DzivgKuhNl4?autoplay=1"); const stream = await getStream(page, { audio: true, video: true });

const file = fs.createWriteStream(__dirname + "/" + parseInt(Math.random() * 100) + ".webm");
stream.pipe(file);

await new Promise(r => setTimeout(r, 10000));
await stream.destroy();
file.close();
await browser.close();
(await wss).close();

})();

4. Clone this pull request into parent folder
5. Install dependencies ```npm i --save-dev```
6. Run ```npm run build```
7. Replace this files with the according ones in the node_modules/puppeteer-stream folder of the step 1 project

dist/PuppeteerStream.d.ts dist/PuppeteerStream.js


8. Open command line, navigate to step 1 project and execute ```node index.js```
9. Confirm browser and program close without error
SamuelScheit commented 4 months ago

Thank you very much for your contribution. It is now published in the latest version 3.0.14