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

Use page.screenshot() after navigating to a page. Puppeteer writes a PNG by default, can capture the full scrollable document or a clipped rectangle, and can return image bytes or a base64 string instead of creating a file. The examples below target the current Puppeteer Page API reference (version 25.12.0 shown by the official documentation) and are ready to run with modern Node.js.

Install Puppeteer and take your first screenshot

Create a project, install Puppeteer, and run this ES module:

  1. mkdir puppeteer-shots && cd puppeteer-shots
  2. npm init -y
  3. npm install puppeteer
  4. Add "type": "module" to package.json, then save the following as shot.js.
import puppeteer from 'puppeteer';

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

Run node shot.js. The script opens a browser, creates a tab represented by Puppeteer’s Page abstraction, navigates to https://example.com, saves screenshot.png in the current directory, and closes the browser. page.screenshot() captures the page as it is currently rendered, so wait for any application-specific content before calling it.

Choose the capture scope

Viewport screenshot

With no extra options, Puppeteer captures the visible viewport. Set the viewport before navigation when a predictable size matters:

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.
import puppeteer from 'puppeteer';

const browser = await puppeteer.launch();
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' });
await browser.close();

networkidle2 waits until network activity is low, but sites with analytics, streams, or polling may never become truly idle. In those cases, wait for a known selector or use a bounded delay instead.

Full-page screenshot

Pass fullPage: true to request the complete scrollable document rather than only the visible viewport:

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

Very tall pages can create large image files or exceed browser memory. For long reports, consider capturing sections with clip, producing a PDF, or reducing the viewport scale.

Capture one rectangle with clip

clip defines a page-coordinate rectangle. The values are CSS pixels measured from the page’s top-left corner:

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.
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: 'crop.png',
  clip: { x: 40, y: 80, width: 640, height: 360 },
});

The rectangle must have positive dimensions and fit the rendered page. For a component whose position changes, selecting the element directly is safer than hard-coding coordinates.

Screenshot a single element

Find an element with a selector, then use its bounding box as the clip. This works across Puppeteer versions and lets you validate that the element exists:

const card = await page.$('.pricing-card');
if (!card) throw new Error('Expected .pricing-card was not found');

const box = await card.boundingBox();
if (!box) throw new Error('The element is hidden or has no layout box');

await page.screenshot({
  path: 'pricing-card.png',
  clip: box,
});

If the element is below the fold, scroll it into view first. A fixed header, animation, or lazy-loaded image can also change the box between measurement and capture; disable motion or measure immediately before the screenshot.

Control PNG, JPEG, quality, and background

Goal Options Result
Default lossless image { path: 'shot.png' } PNG; quality does not apply.
Smaller photographic file type: 'jpeg', quality: 82 JPEG with quality from 0 to 100.
Transparent page background omitBackground: true Default white background is omitted where transparency is supported.
High-density rendering page.setViewport({ deviceScaleFactor: 2 }) Retina-style pixels; output dimensions and file size increase.
await page.screenshot({
  path: 'page.jpg',
  type: 'jpeg',
  quality: 82,
});

await page.screenshot({
  path: 'transparent.png',
  omitBackground: true,
});

PNG is the default type. JPEG quality is a 0–100 setting and is ignored for PNG. Use PNG for text, diagrams, and transparency; use JPEG when a lossy, usually smaller file is acceptable.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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.

Return bytes or base64 instead of saving a file

Omit path to keep the image in memory. The binary form is a Uint8Array; requesting base64 returns a string:

const bytes = await page.screenshot();
console.log(bytes instanceof Uint8Array, bytes.length);

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

Convert the bytes to a Node.js Buffer when an API or file-system library expects one:

const bytes = await page.screenshot({ type: 'png' });
const buffer = Buffer.from(bytes);
await import('node:fs/promises').then(fs => fs.writeFile('from-buffer.png', buffer));

Base64 increases payload size and memory use. Prefer bytes for uploads, and stream or write to disk when screenshots are large.

Reliable timing for real websites

Wait for a selector

await page.goto('https://example.com');
await page.waitForSelector('.hero-chart', { visible: true });
await page.screenshot({ path: 'chart.png' });

Wait for a bounded delay

await new Promise(resolve => setTimeout(resolve, 1500));
await page.screenshot({ path: 'after-delay.png' });

A selector expresses a useful condition; a delay is a fallback for animations or third-party widgets. Use both only when necessary, and keep delays bounded so failed pages do not stall a job indefinitely.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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

Disable animation before capture

await page.addStyleTag({
  content: `*, *::before, *::after {
    animation: none !important;
    transition: none !important;
    caret-color: transparent !important;
  }`,
});
await page.screenshot({ path: 'stable.png' });

Useful rendering patterns

Mobile or desktop dimensions

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

Viewport emulation changes layout; it does not guarantee that every browser API behaves exactly like a physical phone.

Hide an obstructing element

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

Click before capture

await page.click('[aria-expanded="false"]');
await page.waitForSelector('.menu-panel', { visible: true });
await page.screenshot({ path: 'open-menu.png' });

Use stable accessibility attributes or test IDs when available. A text selector tied to changing copy is more fragile.

Capture a page after authentication

await page.setCookie({
  name: 'session',
  value: process.env.SESSION_COOKIE,
  domain: 'example.com',
  path: '/',
  secure: true,
});
await page.goto('https://example.com/account');
await page.screenshot({ path: 'account.png' });

Keep credentials in environment variables or a secret manager, never in source control. Respect the site’s access rules and privacy requirements.

One script that selects PNG, JPEG, full-page, or an element

import puppeteer from 'puppeteer';

const browser = await puppeteer.launch();
try {
  const page = await browser.newPage();
  await page.setViewport({ width: 1365, height: 900, deviceScaleFactor: 1 });
  await page.goto(process.env.TARGET_URL ?? 'https://example.com', {
    waitUntil: 'domcontentloaded',
    timeout: 45_000,
  });
  await page.waitForSelector('body', { visible: true, timeout: 15_000 });

  const selector = process.env.SELECTOR;
  const options = {
    path: process.env.OUTPUT ?? 'screenshot.png',
    type: process.env.TYPE === 'jpeg' ? 'jpeg' : 'png',
    ...(process.env.TYPE === 'jpeg' ? { quality: 82 } : {}),
    ...(process.env.FULL_PAGE === 'true' ? { fullPage: true } : {}),
  };

  if (selector) {
    const element = await page.$(selector);
    if (!element) throw new Error(`Selector not found: ${selector}`);
    const box = await element.boundingBox();
    if (!box) throw new Error('Selected element has no visible layout box');
    options.clip = box;
    delete options.fullPage;
  }
  await page.screenshot(options);
} finally {
  await browser.close();
}

Example: TARGET_URL=https://example.com FULL_PAGE=true node shot.js. For a component, set SELECTOR=.hero; an element clip and full-page mode are mutually exclusive in this script.

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.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting Puppeteer screenshots

  • “Cannot find package puppeteer.” Run npm install puppeteer in the same project and execute the script from that directory.
  • Browser fails to launch in CI or Docker. Install the OS libraries required by the bundled Chromium, use a compatible container image, and inspect the launch error. Do not add --no-sandbox unless your isolated environment specifically requires it and you understand the security trade-off.
  • Screenshot is blank or missing content. Navigate with an appropriate waitUntil, then wait for the application’s content selector. Check console errors and network failures.
  • Cookie dialog, chat bubble, or ad covers the page. Click the consent control or hide the known selector with CSS before capture.
  • Full-page image is truncated. Confirm the page has finished lazy-loading, scroll through content if the site loads on intersection, and try a current Puppeteer release. Extremely tall documents may exceed practical image limits.
  • Element clip throws or is empty. Verify the selector, wait for visibility, call scrollIntoView, and re-read boundingBox() immediately before capture.
  • JPEG has no quality change. Ensure type: 'jpeg'; quality is not applicable to PNG.
  • Different results on repeated runs. Fix viewport and device scale, disable animation, set a deterministic timezone or locale where relevant, and wait for fonts and images.
  • Navigation times out. Increase the timeout only when justified, use domcontentloaded instead of network idle for pages with persistent connections, and log the URL and failure stage.

Performance, reliability, and cost considerations

  • Reuse one browser process for multiple pages, but close each page and browser in a finally block so failures do not leak Chromium processes.
  • Use viewport captures or element clips when a full document is unnecessary; they consume less memory and produce smaller files.
  • Set explicit navigation and selector timeouts. A timeout is safer than an unbounded worker that holds a queue slot forever.
  • Cache deterministic screenshots by URL, viewport, and relevant state. Do not cache pages containing private or rapidly changing data without a clear retention policy.
  • Run concurrent captures conservatively. Each page uses CPU and memory, and high concurrency can cause slow rendering or out-of-memory crashes.
  • Record the URL, viewport, options, Puppeteer version, elapsed time, and error category. This makes visual differences diagnosable rather than mysterious.

Or skip the browser setup

ScreenshotNeo provides a GET-based screenshot API when you do not want to maintain Chromium, navigation waits, cookie handling, or image-storage code. It removes cookie/consent banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers report the page verdict and billing status. Its MCP server exposes take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients.

For the complete option list and parameter names, see the ScreenshotNeo API documentation. A one-call WebP capture:

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

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}`);

ScreenshotNeo supports full-page and element captures, dark mode, device presets or custom viewports, retina scale, PDF output, custom CSS and JavaScript, clicks, waits, request blocking, headers, cookies, user agents, authorization, timezone, geolocation, transparent backgrounds, resizing, chosen cache TTLs, signed links, asynchronous webhooks, bulk capture of up to 100 URLs per call, usage reporting, and an OpenAPI specification. Every feature is available on every plan. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account.

Quick decision guide

Need Best Puppeteer option
Visible browser area page.screenshot({ path })
Entire scrollable page fullPage: true
One component Measure the element and pass its boundingBox() as clip
Small photographic file JPEG with an explicit quality
Upload without disk I/O Omit path and use the returned Uint8Array
Automation without browser infrastructure ScreenshotNeo’s API or MCP server

Frequently Asked Questions

Does Puppeteer screenshot include browser chrome or the operating-system window frame?

No. It captures the rendered web page inside the tab, not the surrounding browser application or desktop.

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

Can I combine fullPage and clip in one screenshot call?

Treat them as alternative capture scopes: fullPage requests the document, while clip requests a rectangle. Choose one, or make separate calls.

Why is my screenshot different from what I see manually?

Automated viewport dimensions, device scale, timing, cookies, fonts, animations, locale, and logged-in state can differ from your interactive browser session. Make those inputs explicit and wait for the same content condition.

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.