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

Use Puppeteer’s page.screenshot() method. Launch Chromium, open a page, wait until the content you need is ready, capture the viewport, full document, element, or rectangle, then close the browser. The examples below run with current Puppeteer releases and cover PNG, JPEG, transparency, in-memory data, dynamic pages, and common failures.

Install Puppeteer and create a first screenshot

Install Puppeteer in a Node.js project. The package downloads a compatible Chromium browser unless you are using a separately managed browser.

npm install puppeteer

Create screenshot.mjs:

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: 'screenshot.png' });
} finally {
  await browser.close();
}

Run it with node screenshot.mjs. path writes the file relative to the process’s current working directory. If you omit path, Puppeteer returns image data instead of creating a file. Always close the browser in a finally block so failed navigations do not leave Chromium processes running.

Choose the capture area

Viewport screenshot

The default captures only the currently visible viewport. Set its dimensions before navigation when you need repeatable output.

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.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
const page = await browser.newPage();
await page.setViewport({ width: 1440, height: 900, deviceScaleFactor: 1 });
await page.goto('https://example.com', { waitUntil: 'networkidle2' });
await page.screenshot({ path: 'viewport.png' });

fullPage is false by default, so content below the fold is not included.

Full-page screenshot

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

This requests the complete scrollable document rather than just the viewport. Very tall pages can produce large images; consider capturing a specific section or using a PDF when a single huge bitmap is impractical.

One element

Wait for the element, obtain its handle, and call screenshot() on that handle:

const card = await page.waitForSelector('.product-card');
if (!card) throw new Error('Product card was not found');
await card.screenshot({ path: 'product-card.png' });

Puppeteer attempts to scroll a hidden element into view before capturing it. A selector that matches nothing causes the wait to time out, so use the selector that exists in the page’s rendered DOM.

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

Fixed rectangle

Use clip when coordinates, rather than a DOM element, define the region:

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
await page.screenshot({
  path: 'header-corner.png',
  clip: { x: 0, y: 0, width: 600, height: 180 }
});

The rectangle is measured in CSS pixels within the page viewport. It is useful for stable canvas regions, but it is less resilient than an element selector when a layout changes.

Wait for the page that users will actually see

waitUntil: 'networkidle2' is a useful navigation baseline: it waits for navigation and for no more than two active network connections. It does not prove that a single-page application has finished rendering. Add an application-specific check for late content.

await page.goto('https://example.com/dashboard', { waitUntil: 'networkidle2' });
await page.waitForSelector('[data-testid="dashboard-ready"]');
await page.screenshot({ path: 'dashboard.png', fullPage: true });

For a known delay, use page.waitForTimeout() sparingly; a selector or other readiness signal is generally more reliable because it follows the application state rather than an arbitrary clock.

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

For element captures, waitForSelector() is both a readiness check and a guard against taking a screenshot before the component exists. If content is produced after the selector appears, wait for the component’s final state as well (for example, a “loaded” attribute or a stable result count).

PNG, JPEG, WebP, quality, and transparency

Puppeteer defaults to PNG. You can select a type explicitly or let the filename extension imply it.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
// JPEG; quality applies to JPEG and other supported lossy formats.
await page.screenshot({ path: 'page.jpg', type: 'jpeg', quality: 85 });

// Transparent PNG where the page permits transparency.
await page.screenshot({ path: 'transparent.png', omitBackground: true });
  • PNG: lossless and suitable for text, interfaces, and transparency. The quality option does not apply.
  • JPEG: smaller for photographic pages; choose a quality from 0 to 100 and expect some compression artifacts.
  • WebP: available when supported by the installed Chromium; specify type: 'webp' or use a .webp path.
  • Transparent output: use omitBackground: true. A page with an opaque CSS background will still appear opaque where that background is painted.

Keep the image in memory

When an upload, HTTP response, or test assertion needs bytes rather than a file, omit path. The normal binary result is a Uint8Array:

const bytes = await page.screenshot({ type: 'png' });
console.log(bytes.byteLength);
// send bytes to storage, a test matcher, or an HTTP response

For a data URL or JSON payload, request Base64:

const base64 = await page.screenshot({ encoding: 'base64', type: 'png' });
const dataUrl = `data:image/png;base64,${base64}`;

Do not combine an in-memory workflow with a path when your caller expects the returned bytes; choose one output mode deliberately.

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

Useful page controls before capture

Consistent viewport and device scale

await page.setViewport({
  width: 390,
  height: 844,
  deviceScaleFactor: 2,
  isMobile: true,
  hasTouch: true
});

Set the viewport before loading the URL so responsive breakpoints and layout-dependent scripts see the intended device.

Hide or alter page content

await page.addStyleTag({
  content: '.cookie-banner, .chat-widget, .advertisement { display: none !important; }'
});
await page.screenshot({ path: 'clean.png' });

Custom CSS is useful for deterministic tests, but verify that hiding an element does not change the layout you intend to document.

Run JavaScript before capture

await page.evaluate(() => {
  document.querySelectorAll('video').forEach(video => video.pause());
});

Use page-side code only for changes that are safe in your capture environment. Never place secrets in scripts that execute in an untrusted page context.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

A reusable production-style function

import puppeteer from 'puppeteer';

export async function capture(url, output, options = {}) {
  const browser = await puppeteer.launch({ headless: true });
  try {
    const page = await browser.newPage();
    await page.setViewport(options.viewport ?? {
      width: 1365,
      height: 768,
      deviceScaleFactor: 1
    });
    await page.goto(url, {
      waitUntil: options.waitUntil ?? 'networkidle2',
      timeout: options.navigationTimeout ?? 30000
    });
    if (options.readySelector) {
      await page.waitForSelector(options.readySelector, {
        timeout: options.selectorTimeout ?? 30000
      });
    }
    await page.screenshot({
      path: output,
      fullPage: options.fullPage ?? false,
      type: options.type,
      quality: options.quality,
      omitBackground: options.omitBackground ?? false
    });
  } finally {
    await browser.close();
  }
}

await capture('https://example.com', 'example.png', {
  fullPage: true,
  readySelector: 'body'
});

In a queue or web service, create an explicit timeout policy, limit concurrent browsers, and remove temporary files after upload. A browser per URL is simple and isolates failures; reusing a browser can reduce startup overhead but requires careful page cleanup and concurrency limits.

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

Troubleshooting incomplete or failed screenshots

The file is blank or shows the wrong page

  • Log the final URL after goto(); redirects may have sent the page elsewhere.
  • Check navigation errors, authentication requirements, and response status in your application logs.
  • Wait for the selector or application-ready state that proves the real content has rendered.
  • Confirm that you did not request an element or clip outside the rendered page.

Dynamic content is missing

Network idle can occur before client-side rendering completes. Wait for a stable, page-specific selector or state. If the content is inside an iframe, obtain the correct frame and query it there; a selector in the top-level page cannot find nodes inside a frame.

Element screenshot times out

Verify the selector, increase the selector timeout only when the page legitimately loads slowly, and check whether the element is created only after a click or login. A hidden element that is never attached cannot be captured.

Full-page output is unexpectedly short

Make sure fullPage: true is set on the screenshot call. If a site uses an inner scrolling container, the document itself may not be tall; capture that container as an element or adjust the page before capture.

Chromium will not launch in CI

Use the Chromium revision installed with your Puppeteer version or configure an approved executable path. Containerized Linux environments may also require the browser dependencies and sandbox policy mandated by your CI platform. Avoid disabling the sandbox unless your environment’s security review specifically permits it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

Images or fonts are still loading

Wait for a page-specific ready signal and, when appropriate, wait for fonts:

await page.evaluate(async () => {
  if (document.fonts) await document.fonts.ready;
});

Lazy-loaded images may require scrolling or an application trigger before they exist. Capture only after the page reports that those images are loaded.

Performance, reliability, and cost decisions

  • Reduce work: use a viewport or element capture instead of a full document when that is all the consumer needs.
  • Control memory: large full-page PNGs consume more memory; JPEG or WebP can reduce file size when lossless output is unnecessary.
  • Make retries safe: use deterministic output names or temporary files, and close every page and browser on both success and failure.
  • Stabilize comparisons: fix viewport, device scale, timezone, locale, fonts, animation state, and readiness conditions before visual regression tests.
  • Respect access controls: provide authentication through your controlled test environment and follow the target site’s terms and robots or security requirements.

Or skip the browser setup

ScreenshotNeo returns a website screenshot or PDF from one GET request. It accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be disabled. Only clean shots are billed: bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers identify the page verdict and billing result.

It also offers an MCP server for AI agents, including Claude, Cursor, and other MCP clients, with take_screenshot, get_page_info, and capture_pdf tools. Features include full-page lazy-image loading, CSS-selector element capture, dark mode, device presets or custom viewports, retina scale, PDF controls, custom CSS and JavaScript, pre-capture clicks, selector or network-idle waits, request/resource blocking, headers, cookies, user agents, Authorization, timezone and geolocation, transparent backgrounds, resizing, configurable-TTL caching, signed links, asynchronous jobs with signed webhooks, bulk capture for up to 100 URLs per call, a usage API, an OpenAPI specification, and compatible parameter names used by other screenshot APIs.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo documentation for authentication and options. The same request in Python:

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)

And Node.js:

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

The Free plan includes 1,000 screenshots each month with no card. Paid plans start at $5 for 3,000 shots; every feature is available on every plan. Create a free ScreenshotNeo account.

Frequently Asked Questions

Which Puppeteer method captures a screenshot?

Use Page.screenshot() for a page, or ElementHandle.screenshot() for one DOM element.

Can Puppeteer capture a screenshot without saving a file?

Yes. Omit path and use the returned Uint8Array, or request encoding: 'base64' for a Base64 string.

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

What does Puppeteer’s fullPage option do?

It requests the entire scrollable document instead of the current viewport; it does not automatically capture an inner scrolling container.

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.