Node.JS Puppeteer Project to Record Screen and Save It as MP4 Video File Using FFMPEG Library

You are currently viewing Node.JS Puppeteer Project to Record Screen and Save It as MP4 Video File Using FFMPEG Library

Node.js Puppeteer Project to Record Screen and Save it as MP4 Video File Using FFMPEG Library

const puppeteer = require("puppeteer");
 
const { PuppeteerScreenRecorder } = require("puppeteer-screen-recorder");
(async () => {
  // insitiate puppetter
 
  const browser = await puppeteer.launch({
    headless: false,
    args: ["--autoplay-policy=no-user-gesture-required"],
  });
 
  const page = await browser.newPage();
 
  // record this video file
 
  const recorder = new PuppeteerScreenRecorder(page);
 
  await recorder.start("output.mp4");
 
  await page.goto("https://google.com");
 
  await page.waitForSelector(
    "body > div.L3eUgb > div.o3j99.ikrT4e.om7nvf > form > div:nth-child(1) > div.A8SBwf > div.RNNXgb > div > div.a4bIc > input"
  );
 
  await page.type('input[aria-label="Search"]', "Coding Shiksha");
 
  await page.keyboard.press("Enter");
 
  await page.waitForTimeout(4000); // 4 seconds
 
  await page.type('input[aria-label="Search"]', "Programming Tutorials");
 
  await page.keyboard.press("Enter");
 
  await page.waitForTimeout(4000); // 4 seconds
 
  // stop the recording
 
  await recorder.stop();
 
  await browser.close();
})();

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply