October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

Puppeteer Screenshot Example with TypeScript

A runnable Puppeteer TypeScript example for saving page screenshots, with options for full-page and element captures, readiness waits, output formats, and troubleshooting.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Puppeteer’s Page.screenshot() to save a TypeScript screenshot: launch the browser, open a page, navigate to the target URL, and await the capture. The example below saves a PNG and closes the browser even if navigation or capture fails.

Take a page screenshot with Puppeteer in TypeScript

import puppeteer from 'puppeteer';

async function main(): Promise<void> {
  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();
  }
}

void main();

Save this as a TypeScript file in a project with Puppeteer installed, then run it using your TypeScript runner or build setup. On success, screenshot.png is written to the process’s current working directory. The try/finally ensures the browser is closed after the capture or if an awaited operation throws.

The capture is asynchronous: await page.screenshot() before using its result or relying on the saved file. This follows Puppeteer’s documented page workflow; see the Page API.

Choose what to capture

Current viewport

The basic example captures the page’s current viewport. Puppeteer’s default screenshot format is PNG. With path: 'screenshot.png', the file extension is used to infer the image type.

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

Full page

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

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

fullPage defaults to false. Full-page capture does not, by itself, guarantee that content loaded only during scrolling or after application-specific events has appeared; handle those readiness needs separately.

One element

For a single element, locate it and call its screenshot method. For example:

Rank #2
TypeScript Programming Language - Software Engineer & Coder T-Shirt
  • TypeScript implements a superset of syntax for strictly typed development, facilitating deep static analysis and enhanced development environment integration. The compiler translates source into standard script formats, ensuring parity across any runtime.
  • TypeScript is ideal for front-end developers, full-stack engineers, and software architects who build large-scale web applications. It serves those looking to improve code excellence, reduce bugs through static checking, and maintain complex projects more.
  • Lightweight, Classic fit, Double-needle sleeve and bottom hem
const card = await page.$('.product-card');
if (!card) {
  throw new Error('Could not find .product-card');
}
await card.screenshot({ path: 'product-card.png' });

ElementHandle.screenshot() attempts to scroll an element into view if it is hidden. See the Puppeteer Screenshots guide for page and element examples.

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

A selected region

Use clip to capture a specified region of the page or element, rather than the full viewport or a whole element. The region’s geometry must be appropriate for the page being captured; consult the ScreenshotOptions API for the option’s shape and details.

Wait for the page to be ready

page.goto() resolves according to its navigation wait condition. For pages where network activity is a useful readiness signal, Puppeteer’s guide demonstrates networkidle2:

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

Do not treat that condition as proof that every page is visually complete. An application may fetch data later, animate elements, or reveal lazy-loaded images only after scrolling. If the target has a known readiness signal, wait for it explicitly—for example, a selector that appears when the relevant content is ready:

await page.goto('https://example.com', { waitUntil: 'networkidle2' });
await page.waitForSelector('.report-ready');
await page.screenshot({ path: 'report.png', fullPage: true });

Choose the navigation condition and any page-specific check for the site you are capturing. A network-idle wait is a navigation strategy, not a universal guarantee about application state.

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

Set format, quality, and output handling

The screenshot options include path, fullPage, clip, type, quality, omitBackground, and encoding. The default image type is PNG. Quality is a value from 0 to 100 and does not apply to PNG. The available formats and option constraints are documented in the ScreenshotOptions reference.

For example, save a JPEG with a quality setting:

await page.screenshot({
  path: 'screenshot.jpg',
  type: 'jpeg',
  quality: 80
});

For a transparent background, use omitBackground: true where the page and chosen output format support the result:

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

Page.screenshot() returns image bytes as a Uint8Array by default, as well as writing to a path when one is provided. With encoding: 'base64', the documented overload returns a string:

const bytes = await page.screenshot();
const base64 = await page.screenshot({ encoding: 'base64' });

Use returned bytes when you want to send or process the image in code instead of saving it directly to a file. Refer to the Page.screenshot() API for return types and supported options.

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

Common problems and fixes

  • No output file: Check the process’s current working directory and ensure the awaited screenshot call completed without throwing. When specifying a relative path, it is relative to that working directory.
  • Navigation hangs or fails: The target may not reach the chosen navigation condition, or the site may be unavailable to the browser. Choose an appropriate waitUntil condition for the page and handle navigation errors rather than assuming a screenshot was produced.
  • Screenshot is blank or missing content: The page may need an application-specific selector or another readiness check. A navigation wait alone does not establish that all visual content is ready.
  • Full-page capture omits lazy content: Content may load only after scrolling or another interaction. Trigger the page behavior required to load it before capturing, and verify the target content exists.
  • Element capture fails: Check that the selector matches an element after navigation. The example explicitly checks for a missing element before invoking its screenshot method.
  • Quality setting has no effect: The quality option does not apply to PNG; choose a supported lossy type such as JPEG if you need a quality setting.

Browser setup, reliability, and cost

Puppeteer gives you control over Chromium and the page lifecycle, but your script must launch and manage that browser, choose readiness conditions, and handle site-specific behavior. Screenshot work also consumes the time and resources needed to run the browser and load the target page. The cited API documentation describes screenshot calls and options; it does not establish a universal runtime or cost figure, which depends on your environment and the pages you capture.

Or skip the browser setup

For a direct API capture, send one GET request with the URL and your API key. See the ScreenshotNeo documentation for request parameters and response details.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.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 of those steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server offers take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients. The free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 screenshots.

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

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.

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 *

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.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
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.