DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk6 min

How to Build Website Screenshot Functionality with Code

A practical guide to building website screenshot capture with Playwright or Puppeteer, including viewport, full-page and element screenshots, readiness, output handling and fixes.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To add website screenshot functionality, launch a browser with Playwright or Puppeteer, set the viewport, navigate to the page, wait for the content you need, and save a viewport, full-page, or element screenshot. You can write the image to disk or handle its bytes in your application.

Choose the capture scope and framework

Use a browser automation library when your application needs to render a real web page before capturing it. Playwright documents screenshot support across its language bindings; Puppeteer provides a JavaScript API. The right starting point is usually the framework and runtime that already fit your application.

What you need Approach What to expect
Visible viewport page.screenshot() in Playwright or Puppeteer Captures the current viewport. Content below the fold is excluded unless full-page capture is enabled.
Long page Playwright fullPage: true Produces a tall page image; confirm the output suits your display or processing limits.
One component Playwright locator screenshot or Puppeteer element screenshot Captures a narrower area. Puppeteer attempts to scroll a hidden element into view.
Programmatic processing Return screenshot bytes or a buffer Use the image data directly in another step; base64 is an optional encoding, not a different capture method.
Responsive layout Set viewport before navigating Choose CSS viewport dimensions and device scale behavior deliberately; do not assume those dimensions equal the final image’s pixel dimensions.
Protocol-level control Chrome DevTools Protocol Page.captureScreenshot A lower-level option for protocol integrations; most application code can start with a framework API.

Build the capture flow

  1. Launch or connect to a browser. Create a page or tab using your selected framework.
  2. Set the viewport before navigation. This helps the page render at the intended responsive breakpoint. Changing screen size after load can alter site behavior.
  3. Navigate to the target URL. Use a readiness condition appropriate to the page rather than assuming one wait strategy fits every site.
  4. Wait for the content you need. A page may continue rendering after navigation resolves. If your application controls the target page, an app-specific ready signal is often clearer than a generic network condition.
  5. Choose the capture area. Capture the viewport, the full page, or a specific locator or element.
  6. Save or consume the result. Write to a file for a simple workflow, or use returned bytes for processing or delivery.
  7. Manage browser lifecycle. Close a one-off browser after the capture; a long-running service may reuse browser resources according to its own lifecycle design.

Playwright examples

Visible viewport to a file

const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch();
  try {
    const page = await browser.newPage({ viewport: { width: 1440, height: 900 } });
    await page.goto('https://example.com', { waitUntil: 'domcontentloaded' });
    await page.screenshot({ path: 'screenshot.png' });
  } finally {
    await browser.close();
  }
})();

The viewport is configured before navigation. domcontentloaded is a starting point, not a promise that every client-rendered element is ready.

Full-page image

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

Use this when content below the fold belongs in the output. A full-page image can be much taller than the viewport, so consider the limits of the system that will store, transmit, or display it.

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.

One element

await page.locator('.header').screenshot({ path: 'header.png' });

Replace .header with a selector unique to the component you want. If the element is not present, wait for it or check that the selector matches the rendered page before attempting capture.

Use the screenshot bytes

const imageBytes = await page.screenshot();
// Pass imageBytes to your image-processing or response code.

Playwright can save a screenshot to a path or return a buffer. The exact handling after capture depends on your application.

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.

Puppeteer example

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch();
  try {
    const page = await browser.newPage();
    await page.setViewport({ width: 1440, height: 900 });
    await page.goto('https://example.com', { waitUntil: 'networkidle2' });
    await page.screenshot({ path: 'screenshot.png' });
  } finally {
    await browser.close();
  }
})();

Puppeteer’s screenshot guide uses networkidle2 as an example navigation condition. It is not a universal readiness test: pages with persistent network activity or delayed application rendering may need a different condition or an explicit wait for the content being captured.

Capture an element in Puppeteer

const element = await page.$('.header');
if (!element) throw new Error('Header element not found');
await element.screenshot({ path: 'header.png' });

The element screenshot method attempts to scroll a hidden element into view. Check that the element exists and represents the intended capture area.

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.

Control readiness and output quality

Wait for the page you actually need

  • Use a navigation wait condition as an initial boundary, then wait for a meaningful selector if the application renders key content asynchronously.
  • For a site you control, expose a readiness signal that becomes available after the content is ready for capture.
  • Do not treat a network-idle condition as proof that all visual content, such as delayed client rendering, is complete.

Match dimensions to the use case

  • Set width and height before navigation when you need a responsive layout at a known viewport.
  • Consider device scale settings when the consuming system expects a particular image density.
  • Use full-page capture for a long document, and an element capture when only one component matters.

Choose an output form

A file path is convenient for a local artifact. A returned buffer or byte array is more convenient when the next step is image processing, an HTTP response, or storage managed by your application. Base64 can be useful where a text representation is required, but it increases encoded payload size and does not change how the page was captured.

Common problems and fixes

  • The screenshot is blank or missing page content: Navigation may have completed before the page’s client-side content was ready. Wait for a selector or application-specific readiness condition.
  • The page is captured at the wrong breakpoint: Set viewport dimensions before navigation and verify the width and height expected by the target layout.
  • Content below the fold is absent: The default screenshot captures the visible viewport. Enable full-page capture when that is the intended result.
  • An element capture fails: Confirm the selector matches an element on the rendered page and wait for it to appear. Puppeteer attempts to scroll an element into view, but it cannot capture an element that was not found.
  • A wait condition never completes: A page with ongoing network activity may not reach the chosen network-idle condition. Use a condition suited to the page or wait for the specific content needed.
  • The image is too large for its destination: Full-page output may be very tall. Consider capturing a component or viewport, or adapt downstream image handling to the size you generate.
  • The browser remains open after errors: Put browser cleanup in a finally block so it runs after a successful capture or an exception.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Performance, reliability, and cost considerations

The cited framework documentation explains capture APIs, not comparative speed, fidelity, hosting expense, or throughput. Those outcomes depend on your target pages, browser environment, concurrency, and output handling; measure them in the environment where you plan to run the code.

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

For repeat captures, decide whether each job should launch a new browser or use a browser managed by a longer-lived service. Reuse can avoid repeated setup, but requires deliberate lifecycle and failure handling. Set practical limits for navigation and capture in the surrounding application, and treat timeouts and failed navigation as capture failures rather than valid screenshots.

For a lower-level integration, the Chrome DevTools Protocol exposes Page.captureScreenshot. Most applications can begin with Playwright or Puppeteer and move to protocol commands only when they need that level of control.

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.

Or skip the browser setup

ScreenshotNeo provides a website screenshot API and MCP server. One GET request can return an image or PDF; the request below saves a WebP screenshot. See the ScreenshotNeo documentation for API options.

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

ScreenshotNeo accepts cookie and consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and responses indicate the page verdict and billing status. Its MCP server includes take_screenshot, get_page_info, and capture_pdf tools for AI agents. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots.

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

Sources

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.

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

Leave a Reply

Your email address will not be published. Required fields are marked *

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.

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
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.