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

Install Playwright and its browser binaries, then launch a browser, navigate to a page, save the screenshot, and close the browser. Use page.screenshot(path="screenshot.png") for the visible viewport; pass full_page=True to capture the full scrollable document. This guide covers runnable synchronous and asynchronous scripts, element captures, practical screenshot options, reliability, and common errors.

Install Playwright and a browser

Playwright’s Python package and the browser binaries it drives are installed separately. In a terminal, create and activate a virtual environment if you use one, then run:

python -m pip install playwright
playwright install

The first command installs the Python API. The second downloads Playwright’s supported browsers. The official installation guide describes Python and operating-system prerequisites, which may change; check it before setting up a new environment: Playwright for Python installation. For a targeted Linux installation, the browser guide documents playwright install --with-deps chromium, which installs Chromium and its system dependencies: Playwright browsers.

Use the Python interpreter that will run your script to install the package. If playwright is not recognized as a command, invoke it through that interpreter with python -m playwright install.

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

Write a basic synchronous screenshot script

Save this as screenshot.py and run python screenshot.py. It opens Chromium in headless mode, visits the URL, writes a PNG in the current working directory, and closes the browser even if navigation or capture raises an error.

from pathlib import Path
from playwright.sync_api import sync_playwright

URL = "https://example.com"
OUTPUT = Path("screenshot.png")

with sync_playwright() as p:
    browser = p.chromium.launch()
    try:
        page = browser.new_page()
        page.goto(URL, wait_until="load", timeout=30_000)
        page.screenshot(path=str(OUTPUT))
        print(f"Saved {OUTPUT.resolve()}")
    finally:
        browser.close()

The essential sequence is start Playwright, launch an engine, create a page, navigate, capture, and close. browser.new_page() is a convenient way to create a page with a fresh context; use an explicit context when you need settings or state shared by multiple pages. Playwright’s introductory script uses the same basic flow: Playwright for Python: First script.

A plain page.screenshot() captures the current viewport. The file path determines where the output is saved; relative paths are resolved from the process’s current working directory, not necessarily the directory containing the script.

Capture the full page or one element

Full scrollable page

Set full_page=True to capture the full scrollable document as a tall image:

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

This captures the page’s full height rather than taking repeated viewport shots. Very long pages can produce large images; if you need bounded dimensions, use a clip or capture selected sections instead. The official screenshots guide defines full-page capture as a screenshot of the full scrollable page: Playwright screenshots.

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.

One element

Use a locator’s screenshot method to save just the matched element. Locators wait for a matching element according to Playwright’s normal locator behavior, but a selector that matches nothing will eventually time out.

page.locator(".header").screenshot(path="header.png")

Choose a selector that identifies the intended element uniquely. For repeated cards or buttons, narrow the locator before capturing, for example with a parent locator or an index when the page structure is stable. Locator screenshots are documented alongside page screenshots: Playwright screenshots.

Use the asynchronous API in an asyncio application

If your application already runs an asyncio event loop, use Playwright’s asynchronous API and await each browser operation. Do not call asyncio.run() from inside an already-running event loop; call await main() from the async application instead.

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()
        try:
            page = await browser.new_page()
            await page.goto("https://example.com", wait_until="load", timeout=30_000)
            await page.screenshot(path="screenshot.png")
        finally:
            await browser.close()

if __name__ == "__main__":
    asyncio.run(main())

The async with block manages the Playwright driver lifecycle; the try/finally ensures the browser is closed after the capture attempt. The synchronous and asynchronous interfaces are both documented by Playwright: Playwright for Python.

Choose a browser engine and debugging mode

Playwright supports Chromium, Firefox, and WebKit. Select the engine that matches the compatibility question: a screenshot in one engine is not evidence that the page renders identically in the others. For cross-browser visual checks, run the same capture flow against each engine you need to support.

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.
Engine Launch call Use when
Chromium p.chromium.launch() You need Chromium rendering or are following the examples in this guide.
Firefox p.firefox.launch() You need to inspect Firefox rendering.
WebKit p.webkit.launch() You need to inspect WebKit rendering.

Install the browser binaries with playwright install, or target the browser you intend to use. The browser guide also covers branded Chrome and Edge and device emulation: Playwright browsers.

Browsers run headless by default. For visual debugging, launch with headless=False so you can watch navigation and inspect what the browser displays:

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.
browser = p.chromium.launch(headless=False)

Headed mode requires a graphical environment. In a server or container without one, keep headless mode enabled or configure a suitable display environment.

Control when the screenshot is taken

A successful navigation does not necessarily mean the page has finished the work relevant to your capture. Choose a navigation condition that suits the site, then explicitly wait for application content when needed. For example, wait for a product panel rather than adding an arbitrary long sleep:

page.goto("https://example.com", wait_until="load", timeout=30_000)
page.locator("[data-testid='product-panel']").wait_for(state="visible", timeout=10_000)
page.screenshot(path="product.png")

Change the selector to one that exists on your target page. If content is rendered after initial load, this makes the intended capture condition clear. A fixed delay can be useful for a known animation or delayed widget, but it is less reliable than waiting for a meaningful selector.

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

Useful screenshot options

The options below are documented by Playwright’s screenshot API. Verify availability and exact behavior against the version installed in your project, especially when upgrading: Page screenshot API and Locator screenshot API.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Need Option or method What it does
Full document full_page=True Captures the full scrollable page instead of only the viewport.
Region of the page clip={"x": 0, "y": 0, "width": 800, "height": 600} Captures a specified page region. Coordinates and dimensions must describe the region you intend to include.
Hide changing or sensitive content mask=[page.locator(".timestamp")] Masks matched elements in the screenshot; useful when a changing region would make visual comparison noisy or expose information.
Control animation effects animations="disabled" Controls animations during capture. Use it when movement would make the output inconsistent with the state you want to compare.
Transparent output omit_background=True Omits the page background where supported by the output type, useful for transparent images.
JPEG or WebP type="jpeg" or type="webp" Selects an image format. JPEG supports a quality setting; confirm format support in your installed version.
Adjust image scale scale="css" or scale="device" Chooses whether output dimensions follow CSS pixels or device scale factor.
Process the image in memory Omit path Returns screenshot bytes rather than writing directly to a file.

Example: mask a dynamic region and save WebP

WebP capture was added for page.screenshot() and locator.screenshot() in Playwright 1.62, according to Microsoft’s release notes. If your installed version predates that release, upgrade before using this format.

page.screenshot(
    path="stable-view.webp",
    type="webp",
    full_page=True,
    animations="disabled",
    mask=[page.locator(".live-counter")],
)

Use a mask only for content you deliberately want obscured or excluded from visual comparison. Check the resulting image, particularly when a masked element changes size or when layout is important to the test.

Example: receive bytes instead of writing a file

image_bytes = page.screenshot(full_page=True)
# Pass image_bytes to your image-processing or visual-diff code.

Returning bytes avoids an intermediate file when a downstream step consumes the image in memory. If the image should be retained for inspection or build artifacts, save it to a known path instead.

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

Make captures more repeatable

Screenshot scripts often fail not because the screenshot call is wrong, but because the page is in a different state from run to run. Establish the capture conditions deliberately:

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.
  • Wait for the content you need. Prefer a locator for the relevant application state over a blind sleep.
  • Control motion. Disable animations when the capture is for visual comparison, unless animation itself is what you are testing.
  • Mask volatile regions. Hide timestamps, counters, or other dynamic areas when their changing pixels are not relevant.
  • Keep the rendering target consistent. Use the same browser engine and page configuration for captures that you compare.
  • Close resources. Close the browser in a finally block so errors do not leave browser processes behind.
  • Save outputs predictably. Use explicit output paths in automation, and ensure the destination directory exists and is writable.

These are implementation practices based on the screenshot controls Playwright documents, not a claim that any particular setup guarantees pixel-identical output. Network content, fonts, browser versions, and application state can still affect what is rendered.

Troubleshoot common failures

Symptom Likely cause Fix
playwright: command not found or browser executable missing The package or browser binaries were installed using a different Python environment, or the browser install step was skipped. Run python -m pip install playwright, then python -m playwright install with the interpreter used to run the script.
Navigation times out The site is slow, unreachable, or waiting for the chosen navigation condition takes too long. Check the URL and network access. Use a timeout suited to the environment and wait for the specific content needed instead of assuming all page activity will finish quickly.
Screenshot is blank or missing page content The capture happened before the application rendered the content you care about, or the target content is hidden or unavailable. Wait for a meaningful locator to become visible, then capture. Run with headless=False to inspect what the browser actually shows.
Element screenshot times out The locator does not match an element, or the element never becomes available. Check the selector against the rendered page and wait for the correct state. Make the locator specific enough to identify the intended element.
Output file is not where expected A relative path is resolved from the process’s current working directory. Print or inspect Path.cwd(), use an absolute path, or create the desired output directory before capture.
WebP option is rejected The installed Playwright version may not support WebP screenshots. Check the installed version and upgrade to a version that supports the format; Microsoft’s release notes identify Playwright 1.62 as adding WebP screenshot capture.
Headed launch fails on a server The environment has no graphical display. Use the default headless mode, or provide a graphical display environment for debugging.
Browser process remains after an exception The script exited before reaching a normal close call. Put browser.close() in a finally block, as in the examples.

Or skip the browser setup

If you need a screenshot from a URL without installing Playwright and browser binaries, ScreenshotNeo offers a one-request screenshot API. The call below saves a WebP capture of the example URL. See the ScreenshotNeo API documentation for request options and response details.

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 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 or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers identify the page verdict and billing status. Its MCP server offers take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. The Free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 screenshots. Learn more at ScreenshotNeo, or sign up for 1,000 free screenshots a month with no card.

Frequently Asked Questions

Can Playwright save a screenshot as bytes instead of a file?

Yes. Omit the path argument from page.screenshot() and it returns image bytes.

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

Can I run a Playwright script inside an existing asyncio application?

Yes. Use playwright.async_api and await the operations; call your coroutine from the application’s running event loop rather than invoking asyncio.run() again.

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.