Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
JavaScript

How to Take Screenshots with Puppeteer and JavaScript

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

Use Puppeteer’s page.screenshot() method. Launch a browser, navigate to the page, wait until the content you need is ready, capture the viewport or a chosen part of the page, and close the browser. Set fullPage: true for a full-document image; use an element handle for a single DOM element. The examples below show how to save PNG and JPEG files, return screenshot data in memory, and diagnose blank or incomplete captures.

Take a basic screenshot with Puppeteer

Puppeteer’s official Screenshots guide recommends Page.screenshot() for capturing screenshots. The basic sequence is to launch the browser, create a page, navigate to a URL, capture it, and close the browser. This ES module example saves a PNG in the current working directory:

import puppeteer from 'puppeteer';

const browser = await puppeteer.launch();

try {
  const page = await browser.newPage();
  await page.goto('https://example.com');
  await page.screenshot({ path: 'screenshot.png' });
} finally {
  await browser.close();
}

Run it in a Node.js project where Puppeteer is installed and ES modules are enabled. Replace the example URL and output filename with your own. The finally block closes the browser even if navigation or capture throws an error, which avoids leaving the launched browser process open when a step fails.

The default capture is the visible viewport, not the entire document. The path option writes the image to disk; a relative path such as screenshot.png is resolved from the current working directory. PNG is the default image type, and Puppeteer can also infer an image type from a filename extension.

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

Choose what part of the page to capture

Decide whether the desired result is the current viewport, the full document, one element, or a fixed rectangle. Puppeteer documents each as a distinct capture approach.

Capture target How to request it Use it when
Current viewport page.screenshot({ path: 'viewport.png' }) You need what is visible within the page’s current viewport.
Full document page.screenshot({ path: 'full.png', fullPage: true }) You need a long page rather than just its initially visible area.
One DOM element Wait for a selector, then call screenshot() on its element handle. You need a component, image, banner, or other selected element.
Fixed rectangle Pass a clip rectangle in the screenshot options. You know the region to capture by its coordinates and dimensions.

Capture a full page

Set fullPage to true to request a screenshot of the full page rather than the viewport:

await page.screenshot({ path: 'full-page.png', fullPage: true });

This changes the capture extent; it does not by itself ensure that every element in a dynamic application has finished rendering. If content appears only after an application-specific action or readiness condition, wait for that condition before taking the screenshot.

Capture one element

Use page.waitForSelector() to wait for the target, then call screenshot() on the returned element handle:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const logo = await page.waitForSelector('#logo');

if (!logo) {
  throw new Error('Could not find #logo');
}

await logo.screenshot({ path: 'logo.png' });

Replace #logo with a selector that identifies an element on the target page. Puppeteer’s Screenshots guide notes that an element screenshot attempts to scroll a hidden element into view. Waiting for the selector helps avoid trying to capture before the element exists; it is not a substitute for waiting on application state if the element exists before its final content is ready.

Capture a rectangle

When you know the specific region you want, pass a clip rectangle in ScreenshotOptions. A clipped capture is appropriate for a fixed area; an element handle is generally the clearer choice when the target is a DOM element. The rectangle’s coordinates and dimensions must match the region you intend to capture.

Wait for the page content you need

A successful navigation does not necessarily mean a web application has completed all of its own rendering. Puppeteer’s guide demonstrates navigation with waitUntil: 'networkidle2', which can be a useful baseline:

await page.goto('https://example.com', {
  waitUntil: 'networkidle2'
});
await page.screenshot({ path: 'page.png' });

For content that renders later, wait for a condition specific to the page before calling screenshot(). For example, if a results panel is the content you need, wait for its selector rather than assuming that navigation alone means it is ready:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
await page.goto('https://example.com/results', {
  waitUntil: 'networkidle2'
});

await page.waitForSelector('.results-panel');
await page.screenshot({ path: 'results.png' });

The selector is an example and must match the page being captured. For a single-element image, wait for the selector and call element.screenshot() instead. Choose the readiness condition based on the application: navigation establishes that the browser has reached the page, while an application-specific check establishes that the particular content you want is present.

Save PNG, JPEG, or transparent output

Puppeteer’s screenshot options let you choose an output path, image type, quality for supported formats, and whether to omit the page background. PNG is the default. JPEG quality is an integer from 0 to 100; the quality option does not apply to PNG.

// PNG (the default image type)
await page.screenshot({ path: 'page.png' });

// JPEG with a quality setting
await page.screenshot({
  path: 'page.jpg',
  type: 'jpeg',
  quality: 85
});

// Transparent background where supported
await page.screenshot({
  path: 'transparent.png',
  omitBackground: true
});

Choose PNG when you want the documented default and do not need a lossy-format quality setting. Choose JPEG when that format suits your use case and set its quality deliberately. Use omitBackground: true when you need transparency and the capture supports it.

Return screenshot data instead of writing a file

If another part of your program needs the screenshot directly, omit path and use the appropriate Page.screenshot() overload. With encoding: 'base64', Puppeteer returns a base64 string. The binary overload returns a Uint8Array.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
// Base64 string
const base64 = await page.screenshot({ encoding: 'base64' });

// Binary image data
const bytes = await page.screenshot();

Use the base64 form when the next step specifically needs encoded text. Use the binary form when the next step accepts image bytes. The API describes Page.screenshot() as capturing a screenshot of the page; check the Puppeteer Page API and ScreenshotOptions documentation for the option details supported by the version you have installed. The ScreenshotOptions documentation page identifies its documented version as Puppeteer 25.12.0; that label describes the documentation page, not necessarily the version installed in your project.

Common problems and fixes

  • The image is blank or missing the expected content. Confirm that navigation reached the intended URL, then wait for the selector or application-ready state associated with the missing content before capturing.
  • The image cuts off below the visible area. The default capture is the viewport. Set fullPage: true if you want the full document.
  • The screenshot contains the wrong region. Match the capture mode to the target: viewport for what is currently visible, full-page mode for the document, an element handle for a component, or a clip rectangle for a known region.
  • The element screenshot fails or captures too early. Check that the selector identifies the intended element and wait for it with page.waitForSelector(). If it exists before its content is ready, wait for a separate application-specific condition as well.
  • The expected image file is not where you looked. Check the current working directory when using a relative path, or provide the intended output location.
  • The browser remains open after an error. Keep browser shutdown in a finally block so it runs if navigation or capture fails.
  • The JPEG quality setting has no effect. The documented quality option is for formats that support it; it is not applicable to PNG.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Performance, reliability, and cost considerations

Wait for the necessary condition, not an arbitrary delay

Navigation completion is a useful starting point, but late-rendered content needs an application-specific readiness check. Waiting for the selector or state that matters makes the reason for taking the screenshot explicit and helps avoid capturing too early. Use a delay only when the page genuinely requires one; the documented guidance emphasizes navigation and readiness checks rather than assuming that every page behaves alike.

Keep the browser lifecycle explicit

A screenshot run includes browser launch, page creation, navigation, capture, and shutdown. Closing the browser after capture—and arranging for it to close on errors—makes the lifecycle clear. Puppeteer’s official basic example and Page API use this launch, page, navigation, screenshot, and close sequence.

Plan cost around where the browser runs

The cited Puppeteer screenshot documentation describes a browser automation API and screenshot options; it does not establish a general screenshot price or a usage benchmark. The practical cost depends on the environment in which you choose to run your browser automation. Assess that environment’s own hosting and resource costs rather than treating the screenshot call as a priced hosted capture service.

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

Or skip the browser setup

If your goal is an image or PDF from a URL rather than running a browser yourself, ScreenshotNeo provides a website screenshot API and MCP server. Its one-request API can return a PNG, JPEG, WebP, or PDF. For a JavaScript client, the Node.js example below sends a request to the API:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://example.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

The API documentation is at screenshotneo.com/docs/. Equivalent request examples:

cURL

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

Python

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://example.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
  • Before capture, ScreenshotNeo accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets. Each of those steps can be turned off.
  • Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing. Each response includes X-Page-Verdict and X-Billed headers to report the page verdict and billing status.
  • Its MCP server offers take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and any MCP client.
  • The Free plan includes 1,000 screenshots per month with no card required. Paid plans start at $5 for 3,000 screenshots; yearly billing gives two months free. Every feature is available on every plan.

Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month with no card.

Frequently Asked Questions

Can Puppeteer take screenshots of pages that require authentication?

Puppeteer’s screenshot method captures a page in the browser context you create. The screenshot documentation covered here does not specify an authentication workflow, so the exact setup depends on how the target site authenticates.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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

Does a successful screenshot prove that a page is visually correct?

No. A screenshot is an image of the page state at capture time; it does not by itself verify that the rendered content matches your expectations.

Where can I check the exact screenshot options for my Puppeteer release?

Consult the Puppeteer Page API and ScreenshotOptions documentation for the version used by your project; the documentation page’s displayed version may differ from your installed package.

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.

Read next

Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

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.