Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon 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 NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
FREEDOM251

Freedom251 › Blog › JavaScript

How to Generate JPEG Screenshots of HTML Pages with Puppeteer

By Freedom251 Team · · 4 min read

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

Use Puppeteer’s page.screenshot() method with type: 'jpeg' and a filename ending in .jpg to save an HTML page as a JPEG. Set quality from 0 to 100 if you want to control JPEG compression, and use fullPage: true for a full-document capture.

Generate and save a JPEG screenshot

The example below launches Chromium, opens a page, waits for a navigation condition, captures the full page as a JPEG, and closes the browser even if capture fails. The option combination is based on Puppeteer’s documented API; it is illustrative rather than a tested run.

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', { waitUntil: 'networkidle2' });
  await page.screenshot({
    path: 'page.jpg',
    type: 'jpeg',
    quality: 85,
    fullPage: true,
  });
} finally {
  await browser.close();
}

The core flow—launch, create a page, navigate, take a screenshot, and close the browser—is shown in the Puppeteer screenshots guide. Its navigation wait is an example, not a guarantee that every application has finished rendering the content you need.

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

Choose the output and capture area

JPEG format and quality

Set type: 'jpeg' to select JPEG explicitly. Puppeteer also documents png and webp as screenshot formats; the intended format can be inferred from the output path extension, but specifying the type makes your choice clear. The ScreenshotOptions reference documents quality as a value from 0 to 100. It applies to JPEG, not PNG, and the API does not identify a universally best value. Choose a value for your use case and inspect the resulting image.

Viewport, full page, or a clipped region

  • Omit fullPage or set it to false to capture the current viewport; false is the documented default.
  • Set fullPage: true to capture the full page.
  • Use clip when you need a defined region. Puppeteer documents captureBeyondViewport as defaulting to false when there is no clip and true otherwise.

The options reference describes these capture controls. If you are choosing between JPEG, PNG, and WebP, the documentation establishes the available formats and controls, but does not publish comparative file-size or visual-quality measurements.

Save to disk or use the returned image data

Providing path writes the screenshot to that location. Without a path, page.screenshot() returns image data as a Uint8Array by default; the API also supports returning a base64 string when base64 encoding is requested. See the Page.screenshot() method reference.

Rank #2
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option

Capture just one HTML element

Use the element’s handle when the desired output is a component rather than the page or a clipped viewport region:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const element = await page.$('.product-card');
if (!element) {
  throw new Error('Could not find .product-card');
}
await element.screenshot({
  path: 'product-card.jpg',
  type: 'jpeg',
  quality: 85,
});

Puppeteer’s screenshots guide says an element screenshot scrolls the element into view if it is hidden. The element screenshot API reports an error if the handle is detached, so make sure the element still belongs to the page when you capture it.

Make the captured state predictable

A screenshot records what the page has rendered at capture time. Wait for the state you actually need—not just navigation to finish. Puppeteer’s guide uses waitUntil: 'networkidle2' in its navigation example, but a navigation wait condition alone does not guarantee that application-specific content, delayed images, or an interaction-dependent state is ready. When needed, wait for a meaningful selector or perform the interaction before taking the screenshot.

Troubleshooting

  • The saved file is not JPEG: use type: 'jpeg' and a .jpg path. The type can be inferred from the extension, but setting both avoids ambiguity.
  • The page is incomplete: wait for the relevant content or application state before calling screenshot(). A navigation wait condition is not proof that all desired content has appeared.
  • The element capture throws: verify the selector found an element and that it has not been removed from the page before the screenshot call.
  • Quality has no effect: quality is a JPEG option and does not apply to PNG.
  • No file appears: check that the screenshot call has a writable path. Without one, Puppeteer returns image data rather than saving a file.

Or skip the browser setup

ScreenshotNeo provides a screenshot API: one GET request can return a screenshot or PDF. Its capture flow accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before the shot; those steps can be disabled. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify the page verdict and billing status in headers. It also offers an MCP server with take_screenshot, get_page_info, and capture_pdf tools for AI agents and other MCP clients.

Example request (see the ScreenshotNeo API documentation):

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. See ScreenshotNeo for the service details. Sign up for 1,000 free screenshots a month with no card.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Documentation version

The Puppeteer API references consulted displayed version 25.12.0. Puppeteer’s documentation is rolling, so check the linked API pages for the current reference when applying this code to a later release.

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.

JavaScriptJPEGPuppeteerscreenshotsWeb development

Leave a Reply

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

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.

Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
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.