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

Use Playwright to open a webpage in a real browser and save its rendered view as an image. Install the Python package and its browser binaries, then call page.screenshot(). By default, that captures the current viewport; use full_page=True for the full scrollable page or take a screenshot of a locator to capture one element.

Capture a webpage screenshot with Python

Playwright lets Python control a browser that renders the page, then capture the result. Its Python library offers synchronous and asynchronous APIs, and the browser runs headlessly by default. This example uses the synchronous API and Chromium:

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch()
    page = browser.new_page()
    page.goto("https://example.com")
    page.screenshot(path="screenshot.png")
    browser.close()

Save the code in a file such as screenshot.py. When it runs successfully, the image is written to screenshot.png in the process’s current working directory. Change the URL to the page you want to capture and change the output path if you want the image saved somewhere else.

Install Playwright and its browser

The package and the browser binaries are separate installation steps. Install both before launching a browser:

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.
pip install playwright
playwright install

Run these commands in the Python environment you will use to run the script. Playwright supports Chromium, Firefox and WebKit; the example selects Chromium with p.chromium. To use another supported browser, change that selection to p.firefox or p.webkit.

Browser binaries are tied to Playwright releases. If you update the package, you may need to run playwright install again so the installed browsers match the library version. Browser requirements and operating-system support can change, so consult the current Playwright installation and browser-management documentation when setting up a new system or updating an existing project.

Choose what part of the page to capture

The default screenshot is the current viewport: the visible browser area, not necessarily the entire document. Choose a capture scope based on what the image needs to show.

Current viewport

Use the default call when you want the view that fits in the page’s current viewport:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
page.screenshot(path="viewport.png")

This is useful for a quick visual check of the page as it appears at the selected viewport size. A new page created with browser.new_page() uses its default viewport unless you set one. If the visible layout matters, set the viewport explicitly before navigating:

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.
page = browser.new_page(viewport={"width": 1280, "height": 800})

Full scrollable page

Set full_page=True to capture the full scrollable document rather than just the portion currently visible:

page.screenshot(path="full-page.png", full_page=True)

A full-page image can be much taller and larger than a viewport image. Use it for a long article or landing page when the complete document matters; use a viewport image when you need a compact image of one screen. Full-page capture does not guarantee that every site’s lazy-loaded content has already appeared. For a page that loads content as you scroll, use a readiness condition appropriate to that site before taking the screenshot.

One element

When you only need a specific component, take a screenshot of a locator instead of the whole page:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
page.locator(".header").screenshot(path="header.png")

Replace .header with a CSS selector that identifies the element you want. The selector must match an element on the loaded page. A locator capture is a good fit for a card, chart, banner or other region that would be difficult to crop consistently from a full-page image.

Save to a file or keep image bytes in Python

Giving path to screenshot() writes an image file. If you omit path, the call returns the screenshot as bytes instead. That is useful when you want to process the image in memory or pass it to another part of your program without first writing a file:

image_bytes = page.screenshot()

# For example, write the returned bytes later:
with open("screenshot.png", "wb") as image_file:
    image_file.write(image_bytes)

The screenshot API supports PNG, JPEG and WebP. Playwright can infer the image type from the path extension; use an extension that matches the format you want, such as .png, .jpg or .webp. When working with bytes rather than a path, select the image type with the API’s type option.

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 screenshot format, scale and clipping

Beyond capture scope and destination, the screenshot API documents options for image type, clipping, quality and scale. These are useful when the output has constraints such as a fixed crop or a smaller file.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Type: choose PNG, JPEG or WebP. If writing to a path, the extension can determine the format.
  • Quality: set the quality option for formats that support it. Quality is relevant when balancing image size and visual fidelity; it does not replace choosing an appropriate format.
  • Scale: CSS scale produces one image pixel per CSS pixel. Device scale uses device pixels and can produce a larger image on a high-density display.
  • Clip: use the clipping option when you need a defined rectangle rather than a complete viewport, page or matched element.

For example, a path extension selects a common output format directly:

page.screenshot(path="page.webp")

Choose scale deliberately: the device-scale output can have more pixels and take more storage, while CSS scale keeps the output dimensions aligned to CSS pixels. A clip is a coordinate-based crop, so it is most dependable when the viewport and page layout are controlled.

Use the asynchronous Python API

If the surrounding program already uses asyncio, Playwright provides an asynchronous API. The browser and page operations are awaited, and the browser is closed in a finally block so cleanup still runs if navigation or capture raises an error:

import asyncio
from playwright.async_api import async_playwright

async def main():
    async with async_playwright() as p:
        browser = await p.chromium.launch()
        try:
            page = await browser.new_page()
            await page.goto("https://example.com")
            await page.screenshot(path="screenshot.png", full_page=True)
        finally:
            await browser.close()

asyncio.run(main())

Use the synchronous example for a standalone script that does not need an event loop. Use the asynchronous form when it fits an existing async application; do not mix synchronous Playwright calls into an event-loop workflow simply to make one screenshot.

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

Handle pages that load content dynamically

A successful navigation does not establish that every site-specific element, animation or lazy-loaded image is ready for capture. The right wait depends on how the page works. If the content you need appears only after a particular element loads, wait for that element using a locator readiness condition before calling screenshot(). If images load on scroll, scroll in the way the site expects before taking a full-page image.

A fixed delay can be useful for a known, brief transition, but it is a blunt tool: a short delay may capture too early, while a long delay wastes time on pages that were already ready. Prefer a condition tied to the content you need when the page provides one. There is no single wait strategy that guarantees readiness for every website.

Or skip the browser setup

If you need screenshots from code without managing Playwright and browser binaries, ScreenshotNeo is a website screenshot API and MCP server. A GET request with a URL returns a PNG, JPEG, WebP or PDF. Here is the Python one-call form; see the ScreenshotNeo API documentation for request options:

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)

ScreenshotNeo accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups and chat widgets before capture; each of those steps can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads and cache hits cost nothing, and responses identify the page verdict and whether the request was billed. Its MCP server provides take_screenshot, get_page_info and capture_pdf for Claude, Cursor and other MCP clients.

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

The Free plan includes 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 screenshots; yearly billing gives two months free. Sign up for ScreenshotNeo’s free plan.

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

Troubleshoot common screenshot problems

The browser will not launch

If Playwright is installed but the selected browser is missing, install the browser binaries with playwright install. If you have updated Playwright, rerun the command: the browser binaries required by a release may differ from those installed for an earlier version. For operating-system-specific setup issues, check the current official installation and browser requirements rather than assuming every system uses the same prerequisites.

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.

The screenshot is blank or shows an incomplete page

Check that the navigation reached the intended URL and that the content you need had loaded before capture. Pages that render content after navigation, load images on scroll or show content only after interaction may need a site-specific wait or action. Capture a locator for a visible target element when that is a better readiness signal than taking the whole page immediately.

The output only contains the visible screen

That is the default behavior. Use full_page=True for the full scrollable document, or capture a specific element with page.locator("selector").screenshot(...). Confirm that you changed the actual screenshot call being executed, especially if a helper function wraps it.

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 image is unexpectedly large or the wrong format

Check the filename extension and the scale option. A device-scale image may contain more pixels than a CSS-scale image, particularly on high-density displays. Use the extension for the desired format when saving to a path, and select CSS scale if one image pixel per CSS pixel is sufficient.

The script stops responding during navigation or capture

The screenshot API’s documented default timeout is 30,000 milliseconds. A slow page or a page that never reaches the condition your script expects can run into a timeout. Identify whether navigation or the screenshot operation is waiting, then choose an appropriate site-specific readiness condition and review the relevant API timeout option. Do not solve every slow page by adding an arbitrary, very long delay.

Practical choices for repeatable captures

  • Make the viewport explicit when comparing screenshots over time; layout can change with viewport dimensions.
  • Choose a scope intentionally. Viewport captures are compact, full-page captures include the scrollable document, and locator captures isolate one component.
  • Use a file path for a saved artifact and bytes when the next step is in-memory processing or transfer.
  • Keep package and browser versions aligned. After updating Playwright, install the matching browser binaries if required.
  • Wait for the content that matters. A site-specific condition is more reliable than assuming a navigation call means all visual content is ready.
  • Control output size. Format and scale affect the resulting image; device-pixel captures may be larger.

Frequently Asked Questions

Can I capture a screenshot without saving it to disk?

Yes. Omit the path argument; Playwright returns the image as bytes that your program can pass to another function or store later.

Which browser does the example use?

The examples select Chromium. Playwright’s Python API also supports Firefox and WebKit, subject to installing the corresponding browser binaries.

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.