October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

How to Return a Puppeteer Screenshot as a Buffer in Node.js

Convert Puppeteer’s default screenshot bytes to a Node.js Buffer with Buffer.from(await page.screenshot()).

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Puppeteer’s default screenshot output and wrap its bytes with Node.js: const screenshotBuffer = Buffer.from(await page.screenshot()); Puppeteer documents the default result as a Uint8Array; Buffer.from() converts it to a Node.js Buffer. You do not need a file path to get the bytes.

Return screenshot bytes as a Buffer

Here is a complete ES module example. It navigates to a page, captures the default PNG screenshot in memory, converts the returned bytes to a Buffer, and closes the browser even if navigation or capture fails.

As an Amazon Associate I earn from qualifying purchases.

import puppeteer from 'puppeteer';

const browser = await puppeteer.launch();
try {
  const page = await browser.newPage();
  await page.goto('https://example.com');

  const screenshotBuffer = Buffer.from(await page.screenshot());
  // Pass screenshotBuffer to another function or API.
  console.log(Buffer.isBuffer(screenshotBuffer)); // true
} finally {
  await browser.close();
}

In CommonJS, replace the import with const puppeteer = require('puppeteer');. The capture and conversion line stays the same. The Puppeteer 25.12.0 API documents the default screenshot result as Promise<Uint8Array>; the resulting Buffer is created by Node.js.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Why the default result is not already a Buffer

page.screenshot() resolves to binary image bytes represented as a Uint8Array by default. Node.js Buffers are a byte-oriented subclass of Uint8Array, but if your receiving code specifically expects a Buffer, explicitly use Buffer.from(await page.screenshot()).

Do not set encoding: 'base64' for this path. That option changes the result to a base64 string, not binary bytes. If you specifically need base64 text, convert it back with Buffer.from(base64, 'base64'); otherwise, keep the default binary result.

Save the screenshot to a file as well

Use path when you want Puppeteer to write an image file. It is not required for an in-memory Buffer.

import puppeteer from 'puppeteer';

const browser = await puppeteer.launch();
try {
  const page = await browser.newPage();
  await page.goto('https://example.com');

  const screenshotBuffer = Buffer.from(
    await page.screenshot({ path: 'screenshot.png' })
  );
} finally {
  await browser.close();
}

The Puppeteer screenshot guide demonstrates saving with path. If you only need bytes for an upload or further processing, omit it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose the capture options you need

The examples above use the defaults: PNG output, a viewport screenshot, and the regular page background. Puppeteer 25.12.0 documents the following relevant options and behaviors in its screenshot options API.

  • Capture the full page: pass { fullPage: true }. Without a clip, fullPage defaults to false.
  • Capture a region: pass a clip rectangle to screenshot a specified area. The full-page default applies when there is no clip.
  • Select an image type: set type to 'png', 'jpeg', or 'webp'. PNG is the default.
  • Set lossy-image quality: use quality for JPEG or WebP output; quality does not apply to PNG.
  • Make the background transparent: pass { omitBackground: true } where the selected format supports transparency.
  • Return base64 text: set encoding: 'base64'; this returns a string, which you can decode with Buffer.from(value, 'base64') if a Buffer is needed.
  • Capture an element: call elementHandle.screenshot(). Puppeteer scrolls the element into view when needed; its default return is also a Uint8Array, so wrap it with Buffer.from().

Example: full-page WebP Buffer

const screenshotBuffer = Buffer.from(
  await page.screenshot({ fullPage: true, type: 'webp', quality: 80 })
);

Example: element screenshot Buffer

const element = await page.$('.report');
if (!element) throw new Error('Could not find .report');

const screenshotBuffer = Buffer.from(await element.screenshot());

Common problems and fixes

  • You received a string instead of bytes: check for encoding: 'base64'. Remove it for the default binary output, or decode the string with Buffer.from(value, 'base64').
  • Your upload library rejects the value: verify that the screenshot was converted with Buffer.from(await page.screenshot()) and that you are passing the Buffer itself, not a base64 string or a path.
  • You expected a file to appear: an in-memory capture does not write one. Add path: 'screenshot.png' to the screenshot options when file output is also wanted.
  • The image is only the visible viewport: set fullPage: true to capture the full page rather than the default viewport area.
  • The page or element is missing from the image: confirm navigation completed and, for element captures, check that the selector matched before calling screenshot().

Or skip the browser setup

If you need a screenshot returned by an API rather than captured in your own Puppeteer process, ScreenshotNeo returns an image or PDF from one GET request. See the API documentation for options.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo accepts cookie and consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed. Its MCP server gives AI agents screenshot and PDF capture tools. The Free plan includes 1,000 shots a month with no card; paid plans start at $5 for 3,000 shots.

Sign up free for 1,000 screenshots a month—no card required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Frequently Asked Questions

Does Puppeteer return a Buffer from page.screenshot()?

No. In Puppeteer 25.12.0 the documented default result is a Uint8Array; use Buffer.from() when your code needs a Node.js Buffer.

Do I need the path option to get screenshot bytes?

No. Omit path for an in-memory result. Add path only when you also want Puppeteer to save the image to a file.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.