October DealsAmazon USOctober deal check: compare before you payAmazon 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 NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
Chrome

How to Take a Screenshot in Chrome With Code

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

For a quick capture, run Chrome Headless with --screenshot. For repeatable scripts, use Puppeteer’s page.screenshot(); for one element, use ElementHandle.screenshot(). If your application already speaks the Chrome DevTools Protocol (CDP), call Page.captureScreenshot directly. The right choice depends on whether you need a one-off command, browser automation, or protocol-level control.

Choose the capture method

Need Use What to expect
Capture a URL once from a terminal Chrome Headless CLI Minimal setup; Chrome writes screenshot.png to the current working directory.
Navigate and save screenshots in JavaScript Puppeteer A higher-level browser API, with page and element screenshot methods.
Control screenshot capture through an existing Chrome protocol client CDP Page.captureScreenshot Returns base64 image data and supports clipping and PNG, JPEG, or WebP.

Chrome lists screenshots among Puppeteer’s uses, and its Headless guide documents the CLI flag. These are different layers: the CLI is simplest for a single URL, while Puppeteer and CDP give a script more control over navigation and capture. The documentation does not establish one approach as universally fastest. See Chrome’s Puppeteer overview and Chrome Headless mode.

Take a screenshot with Chrome Headless

Run Chrome with the page URL and --screenshot. This documented example sets a 412-by-892 viewport:

chrome --headless=new --screenshot --window-size=412,892 https://developer.chrome.com/

Chrome saves the result as screenshot.png in the command’s current working directory. Change the URL to the page you want to capture. The example’s viewport dimensions are in CSS pixels; choose dimensions that suit the layout you need to inspect.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Samsung 14" Galaxy Chromebook Go Laptop PC Computer, Intel Celeron N4500 Processor, 4GB RAM, 64GB Storage, ChromeOS, XE340XDA-KA2US, Student Laptop, Silver
  • SLIM. LIGHTWEIGHT. READY TO GO: The all-new slim design is perfect for busy lives on the go.
  • SKILLFULLY DESIGNED. MILITARY TOUGH: Built with premium craftsmanship to withstand the occasional drop or ding.
  • ALL-DAY, ALL-IN-ONE CHARGING: Power through your school day – and beyond – with a long-lasting 12-hour battery.¹
  • 3X FASTER THAN THE PREVIOUS GENERATION OF WIFI: Crush your schoolwork in record time with Wi-Fi that’s three times faster than the previous generation of Wi-Fi.
  • YOUR PHONE AND CHROMEBOOK WORK BETTER TOGETHER: Easily transfer files between devices, and control your phone right from your Chromebook.

Wait briefly before capture

If the page needs time to render, Chrome documents --timeout as a delay in milliseconds before screenshot capture. For example:

chrome --headless=new --timeout=3000 --screenshot --window-size=412,892 https://developer.chrome.com/

A timeout is only a fixed wait: it does not prove that every asynchronous request, animation, or lazy-loaded resource has finished. Increase the delay only when a page needs more time, and inspect the output rather than assuming a larger delay guarantees completeness. Chrome documents the same timeout option for headless screenshot, DOM-dump, and PDF capture. Details are in the Chrome Headless guide.

When the CLI is a good fit

  • You need one screenshot and already have Chrome available in your environment.
  • A fixed viewport is enough and you do not need to find or interact with a specific page element.
  • You can accept a fixed wait instead of coordinating capture with a page-specific condition.

The executable name may differ by operating system or installation. If chrome is not recognized, use the Chrome executable available on your system; the command’s flags and URL remain the same. Run it from a directory where you can find the generated file, or check the current working directory after the command completes.

Automate screenshots with Puppeteer

Puppeteer is a JavaScript library for automating Chrome and Firefox. Its documented page workflow launches a browser, creates a page, navigates to a URL, writes a screenshot, and closes the browser. This example uses try/finally so the browser is closed even if navigation or capture fails:

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

Save it as an ES module file and run it in a Node.js environment with Puppeteer available. The output path is relative to the process’s working directory unless you provide an absolute path. The code follows Puppeteer’s documented launch, navigation, screenshot, and close sequence; the cleanup wrapper ensures the close call runs on success or failure. See the Puppeteer Page API.

Capture a specific element

Use an element screenshot when the target is a chart, card, or other DOM element rather than the whole page. Puppeteer documents ElementHandle.screenshot(). Locate the element, check that the lookup succeeded, then capture it:

Rank #2
ASUS 2026 15" FHD IPS Chromebook, Intel Processor Up to 2.80GHz, 4GB DDR4, 128GB Storage, HDMI, Super-Fast WiFi, Chrome OS, Pastel Blue, Renewed
  • Intel Processor Up to 2.80GHz, 4GB DDR4, 128GB Storage
  • 15" FHD IPS Display, Intel UHD Graphics
  • 1x USB Type C, 1 x USB Type A, 1x Headphone/Microphone Combo Jack, HDMI
  • Super Fast WiFi and Bluetooth, Integrated Webcam
  • Chrome OS, AC Charger Included, Pastel Blue
import puppeteer from 'puppeteer';

const browser = await puppeteer.launch();
try {
  const page = await browser.newPage();
  await page.goto('https://example.com');

  const element = await page.$('.chart');
  if (!element) {
    throw new Error('Could not find an element matching .chart');
  }

  await element.screenshot({ path: 'chart.png' });
} finally {
  await browser.close();
}

Replace .chart with a selector that identifies the element you want. If the selector matches nothing, the explicit check stops the script with a readable error instead of attempting to capture an absent element. For current options and behavior, consult the reference for the Puppeteer version installed in your project and the Puppeteer screenshots guide.

Choose page or element capture

  • Use page.screenshot() for the page view you want to save.
  • Use ElementHandle.screenshot() when the capture should be limited to one selected DOM element.
  • For either method, check the options supported by your installed Puppeteer version rather than assuming an option name or behavior from another version.

Use the Chrome DevTools Protocol directly

CDP is the lower-level route when your application already communicates with Chrome through the DevTools Protocol. The Page.captureScreenshot command returns a data field containing base64-encoded image bytes for JSON transport. Its documented formats are png, jpeg, and webp. Optional parameters include a clip rectangle, JPEG quality from 0 to 100, and an option to capture beyond the viewport.

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

Here is a minimal request shape to send over an established CDP connection:

{
  "id": 1,
  "method": "Page.captureScreenshot",
  "params": {
    "format": "webp",
    "captureBeyondViewport": true
  }
}

A CDP client sends the request to its connected target and receives a response with the matching request ID. Decode the response’s result.data from base64 before writing it to a file. The JSON above describes the protocol request; it is not a standalone command-line program, because connecting to Chrome and handling the protocol transport are responsibilities of the client application.

Clip a region or choose an output format

Use the optional clip parameter when the capture should cover a defined rectangle. For example, the parameter shape is:

"clip": {
  "x": 0,
  "y": 0,
  "width": 800,
  "height": 600,
  "scale": 1
}

These values describe the capture rectangle; adjust them to the region you intend to save. For JPEG, the protocol accepts a quality value from 0 to 100. PNG and WebP are also supported. Confirm details against the CDP reference matching the Chrome version you use: the published Page protocol reference is a rolling “tot” reference, so protocol details can vary over time.

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.

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server. A single GET request can return a PNG, JPEG, WebP, or PDF. Its capture flow accepts cookie and consent banners like a visitor, then removes more than 60 known consent platforms, newsletter popups, and chat widgets; each of those steps can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and responses include X-Page-Verdict and X-Billed headers describing the result. Its MCP server exposes take_screenshot, get_page_info, and capture_pdf to Claude, Cursor, and other MCP clients.

For example, save this as shot.webp using cURL (replace the URL with the page you want and supply your API key):

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 API documentation for request options. Python and Node.js examples are also available as direct GET requests:

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)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

Beyond a basic capture, options include full-page capture with lazy images loaded, a CSS-selector element, dark mode, device presets and custom viewports, retina scale, PDF page and margin settings, HTML/CSS-to-image, custom CSS or JavaScript, click-before-capture, selector or network-idle waits, request and resource blocking, custom headers, cookies, user agent, authorization, timezone, geolocation, transparent backgrounds, resizing, configurable cache TTLs, signed image links, asynchronous jobs with signed webhooks, bulk capture of 100 URLs per call, a usage API, and an OpenAPI specification. Other screenshot API parameter names also work to ease migration.

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

Plans include 1,000 screenshots per month free with no card; paid options start at $5 for 3,000 screenshots. Every feature is available on every plan, and yearly billing gives two months free. Sign up for ScreenshotNeo and start with 1,000 free screenshots a month, no card required.

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

Troubleshoot common capture problems

The output file is missing

For the CLI example, Chrome writes screenshot.png in the current working directory. Check the directory from which you launched the command and confirm that Chrome completed. In Puppeteer, inspect the path passed to screenshot(); a relative path is resolved from the running process’s working directory.

The screenshot is blank or incomplete

First verify that the URL is the intended page and that navigation has completed in the workflow you chose. If content needs additional rendering time, try Chrome’s documented --timeout option or use Puppeteer to coordinate the script with the page. A longer fixed delay may help, but cannot guarantee completion of asynchronous content. For content that appears only after scrolling, inspect the Puppeteer screenshot guide and use the capture options documented for your installed version.

Rank #4
HP Chromebook 14 Laptop, Intel Celeron N4120, 4 GB RAM, 64 GB eMMC, 14" HD Display, Chrome OS, Thin Design, 4K Graphics, Long Battery Life, Ash Gray Keyboard (14a-na0226nr, 2022, Mineral Silver)
  • FOR HOME, WORK, & SCHOOL – With an Intel processor, 14-inch display, custom-tuned stereo speakers, and long battery life, this Chromebook laptop lets you knock out any assignment or binge-watch your favorite shows..Voltage:5.0 volts
  • HD DISPLAY, PORTABLE DESIGN – See every bit of detail on this micro-edge, anti-glare, 14-inch HD (1366 x 768) display (1); easily take this thin and lightweight laptop PC from room to room, on trips, or in a backpack.
  • ALL-DAY PERFORMANCE – Reliably tackle all your assignments at once with the quad-core, Intel Celeron N4120—the perfect processor for performance, power consumption, and value (2).
  • 4K READY – Smoothly stream 4K content and play your favorite next-gen games with Intel UHD Graphics 600 (3) (4).
  • MEMORY AND STORAGE – Enjoy a boost to your system’s performance with 4 GB of RAM while saving more of your favorite memories with 64 GB of reliable flash-based eMMC storage (5).

The element capture fails

Confirm that the selector matches an element on the page after navigation. The sample checks for a missing handle and throws an explicit error; replace the selector with one that actually identifies the target. If the content is added later, make sure your script waits for it before querying the element.

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.

The CDP image is not a readable file

The protocol response transports image bytes as base64 text inside JSON. Decode result.data before writing it as a binary image; saving the base64 characters themselves produces text, not the image file. Also check that the requested format matches the file extension you use.

The screenshot dimensions do not match expectations

For the CLI, set --window-size=WIDTH,HEIGHT to define the viewport in the documented workflow. With CDP, review the clip rectangle and the beyond-viewport option. For Puppeteer, use the options supported by your installed version and consult its current reference rather than assuming settings from another release.

Performance, reliability, and cost considerations

For a single URL and a known viewport, the CLI minimizes application code. Puppeteer adds a browser automation layer that is useful when you need scriptable navigation or element targeting. Direct CDP avoids a higher-level screenshot method but requires the application to manage protocol communication and decode the response. Choose based on the control your workflow needs, not an assumed speed ranking: the cited documentation gives capabilities and examples, not comparative benchmark results.

Timing is a reliability decision as well as a performance one. A fixed delay adds that amount of waiting to each capture but may still miss work that finishes later; do not equate “waited N milliseconds” with “page fully rendered.” For repeatable jobs, define what ready means for the particular page and verify the resulting image. No official benchmark or universal cost comparison is established by the documentation cited here.

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

Frequently Asked Questions

Can I use Chrome’s headless screenshot command without Puppeteer?

Yes. Chrome documents a standalone Headless command using --screenshot; Puppeteer is a separate JavaScript automation option.

Can CDP return a WebP screenshot?

Yes. Page.captureScreenshot lists WebP alongside PNG and JPEG.

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 *

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

Read next

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.