Use Puppeteer’s Page.screenshot() method and pass a path: await page.screenshot({ path: 'screenshot.png' });. Puppeteer writes the image to that path, inferring the format from the filename extension. A relative path is resolved from the Node.js process’s current working directory.
This complete example launches Chromium, opens a page, saves a PNG, and always closes the browser:
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 from a project that has Puppeteer installed (for example, after npm install puppeteer). The resulting screenshot.png is created in the directory from which the Node.js process was started, not necessarily beside the script file.
Save a screenshot to a known location
Use an absolute path when location matters
The ScreenshotOptions.path property accepts a string. Relative paths use the process working directory; absolute paths remove that ambiguity.
#1 Best Overall
- 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 path from 'node:path';
import puppeteer from 'puppeteer';
const output = path.resolve(process.cwd(), 'artifacts', 'homepage.webp');
const browser = await puppeteer.launch();
try {
const page = await browser.newPage();
await page.goto('https://example.com');
await page.screenshot({ path: output, type: 'webp' });
console.log(`Saved ${output}`);
} finally {
await browser.close();
}
Create the artifacts directory before running this script if it does not already exist. Puppeteer can write the file only where the operating-system user running Node has permission.
Understand what happens when path is omitted
Without path, Puppeteer does not save anything to disk. The method returns image data instead. The documented default return type is a Promise<Uint8Array>; with encoding: 'base64', it returns a string (Page.screenshot() API).
const bytes = await page.screenshot();
await fs.promises.writeFile('from-bytes.png', bytes);
const base64 = await page.screenshot({ encoding: 'base64' });
await fs.promises.writeFile('from-base64.txt', base64, 'utf8');
For an ordinary file, passing path is simpler and avoids choosing your own file-writing code.
Choose the part of the page to capture
Viewport screenshot
The basic call captures what is visible in the current viewport. Set the viewport before navigation or capture when you need a repeatable width and height:
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →await page.setViewport({ width: 1440, height: 900, deviceScaleFactor: 1 });
await page.goto('https://example.com');
await page.screenshot({ path: 'viewport.png' });
The screenshot API uses the page’s current viewport; changing it changes responsive layout, wrapping, and which content is visible.
Rank #2
- 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.
Full-page screenshot
Set fullPage: true to capture the complete scrollable document rather than only the viewport:
await page.screenshot({
path: 'full-page.png',
fullPage: true
});
Very long pages can produce large images and take longer to encode and write. If a page loads content while scrolling, wait until that content is present before taking the shot.
Capture a rectangular region with clip
Use clip when you need coordinates rather than an entire page:
await page.screenshot({
path: 'region.png',
clip: { x: 120, y: 80, width: 800, height: 500 }
});
The rectangle is measured in CSS pixels from the page’s coordinate system. Keep the rectangle inside the rendered page to avoid surprising results.
Save one DOM element
For a component, locate it and call ElementHandle.screenshot():
Rank #3
- 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.
const card = await page.waitForSelector('.pricing-card');
if (!card) throw new Error('Pricing card was not found');
await card.screenshot({ path: 'pricing-card.png' });
Puppeteer scrolls the element into view when needed. The call throws if the element has been detached from the DOM, which can happen when a front-end framework re-renders the component. In that case, find the selector again immediately before capturing.
Control image format, quality, and background
Let the extension select the format
Puppeteer infers the image type from the filename extension. PNG is the documented default; use an explicit type when you want the choice to be obvious:
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutePC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11await page.screenshot({ path: 'page.png', type: 'png' });
await page.screenshot({ path: 'page.jpg', type: 'jpeg', quality: 85 });
await page.screenshot({ path: 'page.webp', type: 'webp' });
The quality value ranges from 0 to 100 and does not apply to PNG. JPEG quality changes file size and visual detail, so choose it according to whether the file is for archival use, visual regression, or a web preview.
Keep or remove the background
Set omitBackground: true to hide Puppeteer’s default white background and permit transparency where the page supports it:
await page.screenshot({
path: 'logo.png',
omitBackground: true
});
Transparency is most useful for isolated interface elements or logos. A normal page with its own opaque CSS background will still appear opaque.
Rank #4
- 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
Make the capture reliable in automation
Wait for the page state you actually need
page.goto() returning means navigation reached its selected completion condition; it does not guarantee that a client-rendered chart, image, or font has finished. Wait for a specific selector or application signal before calling screenshot():
await page.goto('https://example.com/dashboard');
await page.waitForSelector('[data-ready="true"]');
await page.screenshot({ path: 'dashboard.png', fullPage: true });
A selector wait is preferable to an arbitrary delay when the page exposes a reliable readiness marker. If the site has no such marker, use a deliberately chosen delay and document why it is needed.
Always close the browser
Wrapping the work in try/finally prevents failed navigation or file writes from leaving Chromium processes behind. This matters in CI, where leaked processes can exhaust memory and make later jobs fail.
Coordinate concurrent screenshots
The Page API notes that some operations in the same BrowserContext, including creating or closing a page, wait for an in-progress screenshot. page.bringToFront() does not wait for existing screenshot operations (Page class reference). If you capture several pages concurrently, use separate pages deliberately and await each screenshot promise before closing its page or context.
Common errors and fixes
| Symptom | Likely cause | Fix |
|---|---|---|
| No file appears | path was omitted, or you are checking a different directory. |
Pass path explicitly and log process.cwd(). Remember that relative paths use the process working directory. |
ENOENT or a file-system error |
The parent directory does not exist. | Create the directory first with fs.promises.mkdir(dir, { recursive: true }), then capture. |
| Permission denied | The Node process cannot write to the selected location. | Choose a writable directory or correct its permissions; do not assume the script’s directory is writable. |
| Element screenshot throws about a detached node | The page re-rendered after you obtained the element handle. | Call waitForSelector again immediately before element.screenshot(). |
| Only the top of a long page is present | The call captured the viewport. | Add fullPage: true, or use clip for a deliberate region. |
| JPEG/WebP output is unexpectedly large or soft | Format and quality do not match the use case. | Use PNG for lossless output; for JPEG, adjust quality from 0–100. Quality has no effect on PNG. |
| Transparent output has a white-looking area | The page or element paints its own opaque background. | Use omitBackground: true and remove or override the element’s background with page CSS. |
| Browser remains running after a failure | Cleanup was skipped when navigation or capture threw. | Put capture code in try and browser.close() in finally. |
Performance, file size, and repeatability
- Capture only what you need. A viewport or clipped region is cheaper to encode and store than a very tall full-page image.
- Choose the format deliberately. PNG preserves detail but can be large; JPEG with a suitable quality value reduces size for photographic pages; WebP is another supported output choice when your downstream tools accept it.
- Stabilize layout inputs. Set a known viewport and device scale, wait for the content that matters, and use the same URL state, cookies, and authentication for comparable runs.
- Use deterministic names. Include a route, viewport, or build identifier in filenames so parallel jobs do not overwrite one another.
- Await writes before cleanup. When Puppeteer receives
path, await the screenshot promise before closing the page or browser.
Or skip the browser setup
If you only need a URL turned into an image or PDF, ScreenshotNeo provides a single HTTP request instead of managing Chromium. It is the first alternative to try when you want clean captures: it accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before the capture. Only clean shots are billed; bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and each response identifies the result with X-Page-Verdict and X-Billed headers.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →One request saves the response directly to a file:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp
See the ScreenshotNeo documentation for authentication and all parameters. Equivalent examples:
Best Value
- 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.
import requests
r = requests.get(
"https://api.screenshotneo.com/v1/shot",
params={"access_key": "YOUR_API_KEY", "url": "https://example.com"},
timeout=90,
)
r.raise_for_status()
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://example.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`Screenshot failed: ${res.status}`);
const fs = await import('node:fs/promises');
await fs.writeFile('shot.webp', Buffer.from(await res.arrayBuffer()));
Options available without writing browser code
- Full-page capture with lazy images loaded, one element by CSS selector, dark mode, 12 device presets or a custom viewport, and retina scale.
- PNG, JPEG, WebP, or PDF output; PDF supports paper size, margins, landscape mode, and page ranges.
- Custom CSS and JavaScript, a click before capture, hidden selectors, and waits for a selector, delay, or network idle.
- Blocking for ads, trackers, requests, or resource types; custom headers, cookies, user agent, and
Authorization; timezone and geolocation. - Transparent backgrounds, image resizing, a chosen cache TTL, signed links for public
<img>tags, asynchronous jobs with signed webhooks, bulk capture of up to 100 URLs per call, a usage API, and an OpenAPI specification.
An MCP server supplies take_screenshot, get_page_info, and capture_pdf tools to Claude, Cursor, and other MCP clients, so an AI agent can request captures directly. Parameter names used by other screenshot APIs also work, which can simplify migration.
| Plan | Included shots | Price |
|---|---|---|
| Free | 1,000 per month | $0, no card |
| Starter | 3,000 | $5 |
| Growth | 15,000 | $15 |
| Pro | 60,000 | $39 |
| Scale | 250,000 | $99 |
| Business | 1,000,000 | $249 |
Yearly billing gives two months free, and every feature is included on every plan. Start with 1,000 free screenshots a month with no card, then move to paid plans starting at $5 for 3,000 shots if your workload grows.
FAQ
Does Puppeteer save screenshots as bytes or files?
Both are supported. Supplying path writes a file; omitting it returns image bytes, or a base64 string when you request encoding: 'base64'.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errorsCan I save a screenshot outside the project directory?
Yes. Pass an absolute path and ensure its parent directory exists and is writable by the process running Node.js.
Which method captures a single component?
Use an element handle’s screenshot() method after locating the element. It scrolls the element into view and fails if that handle has been detached from the DOM.
Frequently Asked Questions
What file extension should I use for a Puppeteer screenshot?
Use the extension that matches the desired output, such as .png, .jpg, or .webp; Puppeteer infers the image type from the extension.
How do I capture the entire webpage instead of the visible viewport?
Pass fullPage: true in the screenshot options.
Why does my relative screenshot path point to the wrong folder?
Relative paths are resolved from the Node.js process’s current working directory. Log process.cwd() or use an absolute path.
Quick Recap
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.

