How to Record Videos with Puppeteer: A Simple Step-by-Step Guide

Post by
Usama Shabbir
How to Record Videos with Puppeteer: A Simple Step-by-Step Guide

The puppeteer screen recorder has become an essential tool for many developers, marketers, and businesses for recording videos of websites or web applications. Whether you're showcasing your product, performing usability testing, or tracking website performance, capturing video interactions on a webpage can be incredibly useful. While there are various tools available for this task, Puppeteer offers a powerful solution for developers who need complete control over browser interactions and want to automate video recording.

Puppeteer is a Node.js library developed by Google that provides a high-level API to control a headless Chrome or Chromium browser. The puppeteer script allows you to automate tasks such as web scraping, screenshot capturing, and even video recording of web pages. Although it’s a fantastic tool for developers, setting up video recording with Puppeteer can be a bit complex, as it requires integration with other tools likeFFmpegto actually capture the video.

In this guide, we will walk you through the process of recording videos with Puppeteer step by step. From setting up the environment to configuring video capture, we’ll cover all the technical aspects of achieving this functionality. However, while Puppeteer offers full flexibility, it also comes with a lot of setup and maintenance.

That’s whereScreenshotAPI.netcomes in. After we discuss how to record videos using Puppeteer, we’ll also show you how ScreenshotAPI.net simplifies this process through a simple API, allowing you to capture videos with just a few lines of code—no complex setup or additional tools required.

By the end of this blog, you’ll have a clear understanding of the method to record videos using Puppeteer, and how ScreenshotAPI.net can help you simplify the process when you need an easier, more automated solution.

What is Puppeteer?

Image

Puppeteer is a Node.js library that provides a high-level API for controlling a headless version of Chrome or Chromium. Developed by Google, Puppeteer enables developers to automate browser tasks like rendering web pages, taking screenshots, generating PDFs, and performing web scraping. Its power lies in its ability to interact with the browser in a programmatic way, simulating real user behavior such as clicking, scrolling, and typing.

Unlike traditional automation tools, Puppeteer operates in headless mode by default. This means that it can run without displaying a user interface, which is perfect for automated tasks and server-side operations. However, you can also use Puppeteer in full browser mode if you need to see the browser's actions in real time.

When it comes to video recording, Puppeteer is a flexible and powerful tool. However, it doesn’t provide native support for video capture out of the box. Instead, you would need to integrate Puppeteer with additional libraries like FFmpeg to actually record a video of the page as it renders. While this gives you complete control over the process, it also adds complexity, as you’ll need to handle the setup and manage additional dependencies.

In the next section, we'll explore why you might want to use the newpuppeteer-screen-recorderrecord videos with Puppeteer and how it can be an ideal choice for developers who need detailed control over the video capture process.

Why Record Videos with Puppeteer?

Image

Recording videos of websites or web applications is incredibly useful in various scenarios, especially for developers, marketers, and businesses. By recording interactions or capturing the state of a website at a given moment, you can gain valuable insights into user behavior, monitor website performance, or even create tutorials and demonstrations.

Using chrome devtools, Puppeteer is an excellent tool for recording videos because it gives developers full control over browser interactions, allowing them to automate complex tasks and precisely control the video recording process. Here are some of the key reasons why Puppeteer is a great choice for video recording:

1. Full Control Over Browser Interactions

Puppeteer allows you to automate every aspect of the browser, which means you can simulate user interactions like clicking buttons, scrolling, filling out forms, and navigating between pages. This is ideal for recording dynamic interactions on your site that would be difficult to capture with a simple screen recorder.

You can script specific actions to be performed during the video capture, making it perfect for recording user journeys, testing workflows, or simulating real-world use cases.

2. Record Full Pages, Not Just the Viewport

One of the major advantages of Puppeteer is the ability to capture full-page videos rather than just the visible portion of the page. This means you can record the entire website, including areas that are outside the viewport (like parts of the page that require scrolling). It’s particularly useful for websites with long or infinite-scrolling content.

Capturing full-page content ensures that every element of the site is recorded and can be replayed in its entirety, which is crucial for website audits or capturing complete user interactions.

3. Simulate Real User Behavior

Video recording with Puppeteer can simulate real user actions, which is useful for both performance testing and user experience evaluation. For example, you can record a user journey as they navigate through your website—clicking on buttons, scrolling down a page, or interacting with pop-ups.

This level of detail is helpful for UX testing and tracking issues that only appear during certain actions, such as navigation glitches or content rendering problems.

4. Automate the Video Recording Process

Puppeteer is perfect for automating repetitive tasks. Once set up, Puppeteer can continuously capture videos as part of your continuous integration (CI) workflow, allowing you to test and record multiple pages across different browsers and devices automatically. This makes it especially useful for projects where frequent or bulk video recording is needed.

5. Flexibility and Customization

Since Puppeteer is a code-based tool, it offers complete flexibility when it comes to customizing how the video is recorded. You can set up specific delays, choose which elements to capture, control the screen resolution, and even choose between full-page or viewport-only video capture.

Developers can tailor the new recording process based on their specific needs, making Puppeteer ideal for testing scenarios that require precision and control.

How to Record Videos with Puppeteer

Image

Recording videos with Puppeteer requires a bit more effort than just taking screenshots. Since Puppeteer doesn’t natively support video capture, you’ll need to integrate it with tools like FFmpeg to record the browser screen. Below is a step-by-step guide on how to set up Puppeteer and record videos of your webpage.

Step 1: Install Puppeteer

Before you can start recording videos, you need to install Puppeteer and set up a Node.js project. If you haven’t already, run the following command to install Puppeteer via npm:

npm install puppeteer

This command will install Puppeteer and download a compatible version of Chromium, which you will use for browser automation.

Step 2: Launch Puppeteer in Non-Headless Mode

By default, Puppeteer runs in headless mode, meaning it operates without displaying the browser interface. To record a video, we need to launch the browser in non-headless mode (i.e., the browser will be visible on the screen while performing actions).

Here’s how to launch Puppeteer in non-headless mode:

const puppeteer = require('puppeteer'); (async () => {	const browser = await puppeteer.launch({ headless: false });  // Set headless to false to view the browser	const page = await browser.newPage();  // Open a new page 	// Navigate to the page you want to record	await page.goto('https://example.com');  	// Perform any other actions, like waiting for elements to load, interacting with the page, etc. })();

Step 3: Capture Video with FFmpeg

Puppeteer doesn't have built-in support for video recording, so we use FFmpeg to capture the browser window. FFmpeg is a powerful tool used to handle multimedia files, including video capture and editing.

Install FFmpeg in your project:

npm install fluent-ffmpeg

Next, set up FFmpeg to record the screen:

const ffmpeg = require('fluent-ffmpeg'); (async () => {	const browser = await puppeteer.launch({ headless: false });	const page = await browser.newPage();	await page.goto('https://example.com'); 	// Start FFmpeg to record the screen	ffmpeg()		.input('screen-capture-stream')  // Link to Puppeteer's screen capture		.output('output-video.mp4')  // Save the video as output-video.mp4		.run(); 	// Additional actions or navigation can be performed here })();

You’ll need to connect Puppeteer with FFmpeg’s screen-capturing capabilities to record the video. FFmpeg will handle the recording, while Puppeteer simulates user actions within the browser.

Step 4: Save the Video

Once your script is running and recording, you can save the video to a specific location. In the example above, the video is saved asoutput-video.mp4. You can adjust the file path and format depending on your requirements (e.g., you can choose different formats like .avi, .mov, or .webm).

FFmpeg also provides several customization options for adjusting the quality, resolution, and frame rate of the video. For example, to record at a higher quality or set the resolution, you can add parameters like this:

ffmpeg()	.input('screen-capture-stream')	.output('output-video.mp4')	.videoCodec('libx264')	.size('1280x720')  // Set video resolution	.fps(30)  // Set frame rate	.run();

Step 5: Stop the Recording

Once the required actions or video length are recorded, you can stop the video recording. FFmpeg allows you to end the capture when necessary and save the final video.

Saving and Storing Videos

Image

Once you’ve successfully recorded a video using Puppeteer and FFmpeg, the next step is saving and storing the recorded video file. In this section, we’ll explore how to specify the location for saving your video files and how to manage file formats and naming conventions to organize your recordings effectively.

1. Specifying the File Path

When using FFmpeg to record the video, you need to specify the file path where the video will be saved. By default, if you don’t provide a path, the video will be saved in the same directory where you run your script. However, you can specify any file path you'd like for better organization.

For example, to save the video in a specific directory, you can set the output path like this:

ffmpeg()	.input('screen-capture-stream')	.output('./videos/output-video.mp4')  // Save video in the 'videos' directory	.run();

This command will save the video in a folder named videos within your project directory. If the folder doesn't exist, FFmpeg will create it automatically.

2. Choosing the Video Format

FFmpeg supports a variety of video formats such asMP4,WebM, andAVI. By default, Puppeteer will save the video in MP4 format, but you can change it to another format if needed. For example, if you want to save the video as aWebMfile, you can change the output extension:

ffmpeg()	.input('screen-capture-stream')	.output('./videos/output-video.webm')  // Save video in WebM format	.run();

You can also specify additional options like the codec or the container format if needed:

ffmpeg()	.input('screen-capture-stream')	.output('./videos/output-video.mp4')	.videoCodec('libx264')  // Specify video codec	.run();

3. Organizing Video Files

When recording multiple videos, it’s essential to have a system for naming and storing files to avoid confusion. You can automatically generate names for each video based on timestamps or URLs to keep your files organized.

Here’s how you can generate unique filenames for each video by including a timestamp in the filename:

const date = new Date().toISOString().replace(/[:.]/g, '-');  // Get timestampconst filename = `video-${date}.mp4`;  // Use timestamp in the file name ffmpeg()	.input('screen-capture-stream')	.output(`./videos/${filename}`)	.run();

This will create video files likevideo-2025-05-31T12-30-00.mp4, ensuring that each video has a unique name based on when it was recorded.

4. Video Compression and Quality

If you need to reduce the size of your video files, FFmpeg provides several options for compression. You can adjust the video bitrate, resolution, and other parameters to balance between video quality and file size.

For example, to reduce the video quality and make the file size smaller, you can adjust the bitrate:

ffmpeg()	.input('screen-capture-stream')	.output('./videos/output-video.mp4')	.videoBitrate('500k')  // Set video bitrate to 500kbps	.run();

You can also set the resolution to lower the video’s quality and perform audio recording to reduce the file size:

ffmpeg()	.input('screen-capture-stream')	.output('./videos/output-video.mp4')	.size('640x360')  // Set resolution to 640x360	.run();

5. Storing Videos in the Cloud

If you need to store your videos remotely or for longer-term access, you can upload them to cloud storage platforms likeAmazon S3,Google Cloud Storage, orDropbox. Most of these platforms offer APIs that you can integrate with your script to automatically upload videos once they’re recorded.

For example, you can use theAWS SDKfor Node.js to upload the video to Amazon S3:

const AWS = require('aws-sdk');const fs = require('fs');const s3 = new AWS.S3(); const uploadParams = {	Bucket: 'your-bucket-name',	Key: 'videos/output-video.mp4',	Body: fs.createReadStream('./videos/output-video.mp4')}; s3.upload(uploadParams, (err, data) => {	if (err) {		console.log('Error uploading video:', err);	} else {		console.log('Video uploaded successfully:', data.Location);	}});

This way, you can automate the process of recording videos and storing them securely in the cloud, making them easily accessible when needed.

Why Use ScreenshotAPI.net Instead

Image

While Puppeteer offers great flexibility and control when it comes to video recording, it also comes with its own set of challenges. Setting up Puppeteer, integrating with tools like FFmpeg, and managing dynamic content can be time-consuming and complex. For developers or businesses who need a simpler and more automated solution, ScreenshotAPI.net offers a great alternative.

Here’s howScreenshotAPI.netsimplifies video recording and content capturing tasks:

1. No Complex Setup Required

One of the biggest hurdles of using Puppeteer for video recording is the need for additional libraries, like FFmpeg, and the complexity of setting up and managing everything. With ScreenshotAPI.net, you don’t need to worry about installing dependencies, configuring the environment, or writing complex code.

ScreenshotAPI.net simplifies the process with a straightforward API that you can integrate with just a few lines of code. There’s no need to manually handle video recording or configure video capture settings.

Example API call to capture a video:

const axios = require('axios'); axios.get('https://api.screenshotapi.net/screenshot', {	params: {		token: 'YOUR_API_KEY',		url: 'https://example.com',		video: true  // Capture video with this parameter	}}).then(response => {	console.log('Video recorded and saved:', response.data);});

With this simple call, you can record a video of any webpage no need to worry about managing headless browser instances or integrating third-party libraries.

2. Full Automation

ScreenshotAPI.net provides full automation for tasks like video recording, taking screenshots, and more. Once you integrate the API into your project, it can automatically capture videos of your pages at regular intervals, as part of your automation workflows.

Whether you need to record videos of competitor websites, track pricing changes, or monitor your own site for updates, ScreenshotAPI.net handles the repetitive work automatically.

3. Scalable and Flexible

For businesses that need to scale their video recording needs—whether it’s recording multiple pages or generating videos for a large number of URLs ScreenshotAPI.net offers the scalability to meet those demands. It’s designed to handle bulk requests with ease, allowing you to capture videos from hundreds or thousands of pages in no time.

Additionally, ScreenshotAPI.net supports features like custom viewport sizes, device emulation, and geolocation-based recording, giving you the flexibility to capture videos in a variety of scenarios, all through simple API parameters.

4. Less Resource-Intensive

Running Puppeteer and FFmpeg for video recording can be resource-intensive, especially if you need to capture videos from many websites simultaneously. ScreenshotAPI.net operates on a robust cloud infrastructure, meaning the heavy lifting is done on the backend. This frees up your resources and ensures your system’s performance remains optimal, even when handling large volumes of video capture tasks.

5. Cost-Effective and Easy to Integrate

For smaller businesses or individual developers, setting up Puppeteer for video recording might feel like overkill, especially when they don’t need all the customization that Puppeteer offers. ScreenshotAPI.net provides a range of affordable pricing plans, including options for audio, starting with a free plan that allows up to 100 screenshots per month. The paid plans are also very cost-effective, offering a high value for features like video capture and automatic screenshot generation.

Integrating ScreenshotAPI.net into your project is simple, thanks to its well-documented API and quick setup process. You won’t need to spend time writing complex scripts or managing multiple dependencies.

6. Built-In Security and Compliance

Security is a priority for many businesses when dealing with sensitive data or client information. ScreenshotAPI.net ensures that your data is securely handled, with HTTPS encryption for all API requests. Moreover, the service complies with industry standards to protect your data and privacy, giving you peace of mind while using the API for video recording or screenshots.

How ScreenshotAPI.net Compares to Puppeteer for Video Recording

Image

Here’s a quick comparison of Puppeteer and ScreenshotAPI.net for video recording tasks:

FeaturePuppeteerScreenshotAPI.net

Ease of Use

Requires setup and integration with FFmpeg

Simple API calls with minimal setup.

Flexibility

Full control over recording process.

Limited customization but simpler for general use.

Scalability

Handles multiple pages with custom setup.

Fully scalable with bulk and automation support.

Resource Usage

High system resource usage.

Low resource usage (cloud-based).

Cost

Free to use but complex to implement.

Affordable pricing with easy-to-use plans.

Support for Dynamic Content

Handles dynamic content with extra effort.

Automatically handles most content types.

Conclusion

In this guide, we’ve walked through how Puppeteer can be used to record videos of websites, from setting up the environment to capturing dynamic content. While Puppeteer gives you full control and flexibility, it also comes with its challenges—setting up FFmpeg, managing resources, and handling dynamic elements require extra steps and technical expertise.

On the other hand, ScreenshotAPI.net offers a much simpler and more efficient solution for businesses and developers who need to automate video recording. With just a few API calls, ScreenshotAPI.net enables you to capture videos of entire webpages, handle geolocation and dynamic content, and even scale video recording for multiple URLs all without needing to manage complex dependencies or deal with resource-intensive setups.

By using ScreenshotAPI.net, you can:

  • Automate video recording with minimal setup.
  • Capture videos of both static and dynamic content.
  • Save time and resources by offloading the recording process to a reliable, cloud-based service.
  • Integrate video recording seamlessly into your existing workflows.

Whether you prefer the fine-grained control of Puppeteer or the ease and scalability of ScreenshotAPI.net, both solutions offer powerful tools for automating web video capture. If you’re looking for a more streamlined, no-code solution that simplifies video recording without sacrificing functionality, ScreenshotAPI.net is the way to go.

Ready to simplify your video recording process? Sign up forScreenshotAPI.netand start automating today.

Frequently Asked Questions

Can Puppeteer record video?

No, Puppeteer does not have built-in video recording capabilities, but you can use external tools like FFmpeg to record the screen during Puppeteer sessions.

How do I record a video of my screen?

You can record your screen using software likeOBS Studio,Camtasia, orFFmpeg.

How do you record actions for Puppeteer?

Puppeteer doesn’t natively support recording actions, but you can log interactions and use screen recording tools like FFmpeg to capture video.

How do I capture a video from a webpage?

To capture a video of a webpage, you can use Puppeteer for automation and FFmpeg for screen recording.

©2025 ScreenshotAPI. All Rights Reserved.