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

The most dependable way to automate website screenshots is to run a real browser with Playwright, navigate to the page, wait for the state you need, and call its screenshot API. Use a normal viewport capture for what a visitor sees, full_page/fullPage for the complete scrollable document, or a locator screenshot for one component. Python supports synchronous and asynchronous code; JavaScript uses an asynchronous Page API.

This guide gives runnable Python and JavaScript examples, explains output formats and scale, covers dynamic pages and reproducibility, and shows a managed alternative when you do not want to operate browsers yourself.

Choose the capture you actually need

Before writing code, decide what the image represents. A default screenshot is the current browser viewport. It does not include content below the fold. A full-page screenshot stitches the entire scrollable document into one image. An element screenshot crops the bounding box of a selected element, such as a header or product card.

Goal Playwright setting Result
Visible viewport Omit the full-page option What fits in the current viewport
Entire document Python full_page=True; JavaScript fullPage: true The page’s full scrollable height
One component locator.screenshot() A crop of the located element

Automate a screenshot with JavaScript

Basic viewport capture

Playwright’s JavaScript API launches a browser, creates an isolated context and page, navigates, then writes the image. This example uses Chromium; the same browser-type interface can select WebKit or Firefox.

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.
const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch();
  const context = await browser.newContext();
  const page = await context.newPage();

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

  await browser.close();
})();

The path is relative to the process’s working directory. Use an absolute path when a job runner or container has an unexpected working directory. Always close the browser in a finally block in production so failed jobs do not leave browser processes running.

Full-page JavaScript capture

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');
    await page.screenshot({
      path: 'example-full.png',
      fullPage: true
    });
  } finally {
    await browser.close();
  }
})();

fullPage: true captures the entire scrollable page, not merely the visible viewport. Very tall pages can create large images; consider a viewport capture, a selected element, or a downstream image-resizing step when consumers do not need every pixel.

Capture one element or return bytes

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

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

    const header = page.locator('.header');
    const pngBytes = await header.screenshot();
    require('fs').writeFileSync('header.png', pngBytes);
  } finally {
    await browser.close();
  }
})();

A locator screenshot is an element crop, not a full-document image. Omitting path returns bytes, which is useful for image comparison, object storage uploads, or sending the result to another service without a temporary file.

Automate a screenshot with Python

Synchronous Python

from playwright.sync_api import sync_playwright

with sync_playwright() as playwright:
    browser = playwright.chromium.launch()
    try:
        context = browser.new_context(viewport={"width": 1440, "height": 900})
        page = context.new_page()
        page.goto("https://example.com")
        page.screenshot(path="screenshot.png")
    finally:
        browser.close()

The synchronous API is straightforward for scripts, cron jobs and command-line utilities. Keep the browser lifetime around a batch when capturing several URLs, but create a fresh context when you need isolated cookies, headers or viewport settings.

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

Asynchronous Python

import asyncio
from playwright.async_api import async_playwright

async def main():
    async with async_playwright() as playwright:
        browser = await playwright.chromium.launch()
        try:
            context = await browser.new_context(viewport={"width": 1440, "height": 900})
            page = await context.new_page()
            await page.goto("https://example.com")
            await page.screenshot(path="screenshot.png")
        finally:
            await browser.close()

asyncio.run(main())

Use the async form when your application already runs an event loop or captures multiple pages concurrently. Do not mix synchronous Playwright calls into an active async event loop.

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.

Full-page and element captures in Python

from playwright.sync_api import sync_playwright

with sync_playwright() as playwright:
    browser = playwright.chromium.launch()
    try:
        page = browser.new_page()
        page.goto("https://example.com")
        page.screenshot(path="full.png", full_page=True)
        page.locator(".header").screenshot(path="header.png")
    finally:
        browser.close()

For async code, use the same options with await page.screenshot(path="full.png", full_page=True) and await page.locator(".header").screenshot(path="header.png").

Control format, quality and pixel scale

PNG, JPEG and WebP

Playwright supports PNG, JPEG and WebP output. PNG is lossless and has no quality setting. JPEG and WebP support quality controls, so they are often smaller when a little compression is acceptable. The file extension normally follows the chosen path; set the format explicitly when your workflow needs a particular encoding.

# Python
page.screenshot(path="page.webp", type="webp", quality=82)

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

CSS scale versus device scale

The CSS scale produces one image pixel per CSS pixel, making dimensions predictable across high-density displays. Device scale follows device pixels and can produce a larger, sharper image on a retina-style context. Choose CSS scale for stable visual regression dimensions; choose device scale when the consumer expects high-density pixels.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
# Python
context = browser.new_context(device_scale_factor=1)  # CSS-sized output

// JavaScript
const context = await browser.newContext({ deviceScaleFactor: 2 });

Make dynamic pages reproducible

Navigation finishing does not mean an application has finished rendering. Wait for the specific state your page requires: a locator becoming visible, a navigation condition, or network activity settling according to the application’s behavior. A fixed sleep is not a universal solution because it can be too short for a slow run and wasteful for a fast one.

Wait for content you will capture

// JavaScript
await page.goto('https://example.com/dashboard');
await page.locator('[data-testid="chart"]').waitFor({ state: 'visible' });
await page.screenshot({ path: 'dashboard.png' });
# Python
page.goto("https://example.com/dashboard")
page.locator('[data-testid="chart"]').wait_for(state="visible")
page.screenshot(path="dashboard.png")

For pages with animations, use screenshot options that disable animations where supported, and mask volatile locators such as timestamps or rotating advertisements. These measures improve consistency but cannot guarantee identical pixels across browsers, operating systems, fonts, network responses or changing content.

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.

Set a deliberate viewport and context

Viewport size, timezone, locale, color scheme, cookies and authentication all affect rendering. Put these values in the browser context rather than relying on the machine running the job. A dark-mode capture, for example, should request a dark color scheme explicitly.

const context = await browser.newContext({
  viewport: { width: 1280, height: 800 },
  colorScheme: 'dark',
  locale: 'en-US'
});

Save files or process screenshots in memory

Use a path for a simple artifact pipeline. Use returned bytes when you need to compare images, upload directly to object storage, attach them to a test report, or transform them without creating an intermediate file.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
# Python bytes
image = page.screenshot(type="png")
with open("screenshot.png", "wb") as output:
    output.write(image)

For repeatable naming, derive a safe filename from a URL and include a timestamp or content hash. Never use an unsanitized URL as a filesystem path.

Common failures and fixes

Browser executable is missing

Playwright’s Python or Node package and the browser binaries are separate installation concerns. Install the package and its supported browser binaries using the setup instructions for the Playwright version in your project, then rerun the script. Pin dependencies in CI so a browser update does not silently change pixels.

Navigation or screenshot timeout

A slow origin, blocked request, selector that never appears, or an oversized page can trigger a timeout. Confirm the URL from the same environment, inspect the failing selector, and increase the operation timeout only when the slower condition is expected. Keep a finite timeout so a broken site cannot occupy a worker forever.

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

Blank or incomplete image

The page may require a post-navigation API call, lazy loading, consent interaction or authentication. Wait for the content that proves readiness, provide the required cookies or headers in the context, and capture after the relevant UI state exists. A screenshot cannot show content the browser was never allowed to load.

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.

Element locator fails

Prefer stable attributes such as data-testid over generated class names. Check that the element is attached and visible, and remember that an element inside an iframe requires selecting the appropriate frame before locating it.

Images differ between runs

Fix viewport, browser engine, device scale, locale, timezone and color scheme. Disable or mask animations and volatile regions, and control test data. Differences can still be legitimate when the site serves changing content or when fonts and operating-system rendering differ.

Performance, reliability and cost decisions

  • Reuse responsibly: keep one browser process for a batch, but isolate users and jobs with separate contexts.
  • Limit concurrency: each page consumes CPU, memory and network bandwidth; tune workers to the machine rather than launching unlimited pages.
  • Keep full pages exceptional: full-document images are larger and slower than viewport or element crops.
  • Record failures: save the URL, browser engine, viewport, timing and error so a transient network problem is distinguishable from a rendering regression.
  • Protect credentials: pass authentication through controlled context settings and secret storage, never hard-code tokens in source or output filenames.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

ScreenshotNeo is a hosted website screenshot API and MCP server. One GET request returns PNG, JPEG, WebP or PDF, while the service handles browser capture for you. It is useful when you need clean shots: before capture it accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups and chat widgets. Bot checks, blank pages, timeouts, failed loads and cache hits are not billed, and each response reports the page verdict and billing status in X-Page-Verdict and X-Billed headers.

Its API supports full-page and CSS-selector element captures, dark mode, device presets or custom viewports, retina scale, PDF paper settings, custom CSS and JavaScript, click-before-capture actions, selector hiding, selector/delay/network-idle waits, request and resource blocking, headers, cookies, user agents, Authorization, timezone and geolocation, transparent backgrounds, resizing, configurable-TTL caching, signed image links, asynchronous jobs with signed webhooks, bulk capture of up to 100 URLs per call, usage reporting and an OpenAPI specification. Parameter names used by other screenshot APIs also work, which can simplify migration.

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

For AI workflows, its MCP server exposes take_screenshot, get_page_info and capture_pdf to Claude, Cursor and other MCP clients.

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.
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 documentation for request options and response handling.

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

The Free plan includes 1,000 screenshots each month with no card. Paid plans start at $5 for 3,000 screenshots; every feature is available on every plan. Sign up free to try it.

Which approach should you use?

  • Choose Playwright when you need browser-level control, custom application logic, local test integration or complete ownership of execution.
  • Choose ScreenshotNeo when you want an HTTP call, cleaned pages, usage-aware billing, asynchronous jobs, bulk requests or an MCP workflow without maintaining browser workers.
  • Use viewport captures for visual checks, full-page captures for archival documents, and element captures for component-level tests.

FAQ

Can I capture a screenshot without writing it to disk?

Yes. Omit the path and use the returned bytes in Python or JavaScript, then upload or compare them in memory.

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

Does a full-page screenshot include content hidden behind a click?

No. It captures the rendered scrollable document. If content appears only after an interaction, perform that interaction and wait for the resulting state first.

Why is my image larger on a retina machine?

Device-pixel scale follows the device’s pixel ratio. Use CSS scale or a context with a controlled device scale factor when fixed dimensions matter.

Frequently Asked Questions

Can I capture a screenshot without writing it to disk?

Yes. Omit the path and use the returned bytes in Python or JavaScript, then upload or compare them in memory.

Does a full-page screenshot include content hidden behind a click?

No. It captures the rendered scrollable document. If content appears only after an interaction, perform that interaction and wait for the resulting state first.

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.

Why is my image larger on a retina machine?

Device-pixel scale follows the device’s pixel ratio. Use CSS scale or a context with a controlled device scale factor when fixed dimensions matter.

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.