puppeteer-stream
puppeteer-stream copied to clipboard
Implement new headless mode && Fix still rarely occurring TargetCloseError && Update doc accordingly
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
- Create a new node project
- Install puppeteer-stream:
npm i puppeteer-stream
- 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();
})();
- Clone this pull request into parent folder
- Install dependencies
npm i --save-dev
- Run
npm run build
- 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
- Open command line, navigate to step 1 project and execute
node index.js
- Confirm browser and program close without error