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

Use Playwright’s synchronous Python API for a simple script: launch a browser, open a page, and call page.screenshot(path="screenshot.png"). Use full_page=True to capture the whole scrollable page, or the asynchronous API if your program already uses asyncio.

Take a website screenshot with synchronous Playwright

For a standalone script, the synchronous API keeps the capture flow straightforward. This example opens a page in Chromium and saves a PNG in the script’s current working directory:

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()

Replace the URL with the page you want to capture. The path argument tells Playwright to write the image to disk; a relative path such as screenshot.png is resolved from the current working directory. The example uses the same launch, navigation, capture, and close sequence as Playwright’s official getting-started pattern.

Prerequisite

This assumes Playwright’s Python package and the browser you intend to launch are installed in the environment where the script runs. If the browser launch fails, check that the selected browser is available to that installation.

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.

Choose what the screenshot contains

Capture the visible viewport

The default is a screenshot of the current viewport. The browser window does not need to show the entire page; content outside the visible area is not included unless you request a full-page capture.

page.screenshot(path="viewport.png")

Capture the full scrollable page

Set full_page=True to capture the whole scrollable page as though it fit on a tall screen:

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

This captures beyond the current viewport. It is different from taking a viewport screenshot after scrolling to a particular position.

Capture one element

Use a locator when you want an image of a specific element, such as a header:

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

Locator screenshots wait for the element to be actionable and scroll it into view. If another element covers it, the covered portion will not actually be visible in the image. For a scrollable container, the screenshot shows only the contents currently scrolled into view; it does not automatically capture all of that container’s contents.

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.

Save to disk or keep the image in memory

Pass path to save the screenshot. If you omit it, page.screenshot() returns image bytes, which you can process or pass to another part of your program:

image_bytes = page.screenshot()

In an asynchronous program, await the call and the returned value is likewise available as bytes.

Use Playwright’s asynchronous Python API

If the surrounding application uses asyncio, use async_playwright and await each browser operation, including the screenshot:

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.
import asyncio
from playwright.async_api import async_playwright

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

asyncio.run(main())

Choose sync or async based on the program you are adding the capture to. A regular one-off script can use the synchronous example; an asyncio application should use the asynchronous API rather than mixing synchronous calls into its async flow.

Control format and repeatability

Choose the output format

Playwright supports PNG, JPEG, and WebP screenshots. The file extension can determine the output type. The quality option applies to JPEG and WebP, not PNG. WebP screenshot support and quality control are version-specific: Playwright’s release notes identify that support in version 1.62, so check your installed version before relying on WebP-specific output.

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.

Stabilize or limit the capture

Screenshot options can help when a page changes during capture or you need only a portion of it:

  • animations="disabled" disables animations for the capture, which can reduce variation from moving content.
  • caret="hide" hides the text caret in the image.
  • clip limits the screenshot to a specified area.
  • style injects styles for the screenshot, useful when you need capture-specific presentation changes.

Use only the options needed for the result you want. They change what appears in the output, so a clipped or styled screenshot is not necessarily a faithful image of the page as a visitor sees it.

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

Capture screenshots with pytest

For tests run with Playwright’s pytest plugin, screenshot capture can be enabled from the command line. The documented default is off:

  • --screenshot=on enables screenshots.
  • --screenshot=only-on-failure captures screenshots only for failures.
  • --full-page-screenshot requests full-page screenshots on failure and requires screenshot capture to be enabled.

For example, enable full-page screenshots on failures with:

pytest --screenshot=only-on-failure --full-page-screenshot

Troubleshoot common capture problems

The browser does not launch

The example depends on a browser being available to the Playwright installation. Confirm that the selected browser is installed in the environment running the script and that your code launches that same browser.

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

The element screenshot is incomplete or obscured

A locator screenshot brings the target into view, but it cannot make an element visible if another element covers it. A scrollable container also shows only its currently scrolled contents. Check overlays and scroll position, or capture the page instead if you need broader context.

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

The file is not where you expected

A relative screenshot path is resolved from the current working directory, which may differ from the folder containing your Python file. Use an absolute path or check the process’s working directory.

The image format or quality option is ignored

Check the filename extension and the selected screenshot type. Quality applies to JPEG and WebP rather than PNG; WebP support depends on the installed Playwright version.

The test run produces no screenshots

Pytest screenshot capture is off by default. Set --screenshot=on or --screenshot=only-on-failure; if requesting full-page screenshots on failure, also enable capture with one of those options.

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

Or skip the browser setup

For a one-request screenshot, ScreenshotNeo accepts a URL and returns an image or PDF. The following Python example saves a WebP response to disk; replace the placeholder API key and target URL with your own values. See the ScreenshotNeo API documentation for the available request options.

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

r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://example.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 step can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and response headers report the page verdict and billing status. Its MCP server provides screenshot tools for AI agents, including Claude, Cursor, and other MCP clients. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo’s free plan: 1,000 screenshots a month with no card.

Frequently Asked Questions

Can I pass a website URL directly to page.screenshot()?

No. Navigate the Playwright page to the URL first with page.goto(), then call the screenshot method.

Does a full-page screenshot include every item inside a scrollable element?

No. A locator screenshot of a scrollable container includes only its currently scrolled contents.

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

Can I capture an image without writing a file?

Yes. Omit the path argument and the screenshot call returns image bytes.

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.