puppeteer-stream icon indicating copy to clipboard operation
puppeteer-stream copied to clipboard

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

Open TalkLounge opened this issue 10 months ago • 0 comments

The Fixes

Headless: "new"

  • Adds --mute-audio to defaultArgs, so ignore it again
  • Needs to be added as flag, see https://github.com/SamuelScheit/puppeteer-stream/issues/4#issuecomment-1441422042
  • For linux, --ozone-override-screen-size flag must be set, see https://github.com/SamuelScheit/puppeteer-stream/issues/4#issuecomment-1584382305

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();
})();
  1. Clone this pull request into parent folder
  2. Install dependencies npm i --save-dev
  3. Run npm run build
  4. 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
  1. Open command line, navigate to step 1 project and execute node index.js
  2. Confirm browser and program close without error

TalkLounge avatar Apr 23 '24 16:04 TalkLounge