Use Playwright Java’s Page.screenshot() method: navigate to a URL, then save the image by setting a path with Page.ScreenshotOptions.setPath(). Add setFullPage(true) for the full scrollable page, or call screenshot() on a locator to capture one element. The examples below cover setup, capture modes, output options, and common failures.
Set up Playwright Java
Playwright Java requires Java 8 or higher. Its browsers run headless by default, so you can capture screenshots without opening a visible browser window. See the Playwright Java installation guide for project setup and the first script.
Install the browser binaries required by your Playwright version with the Playwright CLI. For Maven, the documented command is:
mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI -D exec.args="install"
You can install one browser by naming it, for example with install webkit in the CLI arguments. Browser binaries are version-specific; after upgrading the Playwright library, run the install command again if the required browsers are missing. See Playwright Java browser installation.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →#1 Best Overall
- CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
- INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
- THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
- WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
- A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents
Capture and save a website screenshot
This complete Java example launches Chromium, opens a page, navigates to a URL, and writes a PNG screenshot to the current working directory:
import com.microsoft.playwright.*;
import java.nio.file.Paths;
public class ScreenshotExample {
public static void main(String[] args) {
try (Playwright playwright = Playwright.create()) {
Browser browser = playwright.chromium().launch();
Page page = browser.newPage();
page.navigate("https://example.com");
page.screenshot(new Page.ScreenshotOptions()
.setPath(Paths.get("screenshot.png")));
browser.close();
}
}
}
The path is relative to the process’s current working directory unless you provide an absolute path. Playwright’s official introductory example uses WebKit; the Java API also lets you select Chromium, as shown here. The essential save operation is page.screenshot(new Page.ScreenshotOptions().setPath(...)). See Playwright Java screenshot examples.
Choose what to capture
Current viewport
The default screenshot captures the visible viewport. Use it when the image should show only what fits in the page’s current browser window; choose the viewport dimensions when creating the page or browser context so the output has the intended layout.
Rank #2
- CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
- 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
- SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
- INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
- THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
Full scrollable page
Set setFullPage(true) to capture the page as if it were displayed on a very tall screen:
page.screenshot(new Page.ScreenshotOptions()
.setPath(Paths.get("full-page.png"))
.setFullPage(true));
This produces one tall image. For pages with very large or dynamic content, consider whether a single image is practical and whether content must be loaded before capture.
One element
Use a locator’s screenshot() method to save just a matched component, such as a header:
Rank #3
- Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
- Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
- Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
- In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
- Ultra-thin bezels: Maximize your viewing experience with thin bezels.
page.locator(".header").screenshot(
new Locator.ScreenshotOptions().setPath(Paths.get("header.png"))
);
A locator screenshot waits for actionability checks, scrolls the element into view, and captures its bounds. Covered content may not be visible in the image. If the element itself is scrollable, the capture shows only the content currently scrolled into view. See the Locator API documentation.
Clipped region
To capture a rectangle within the page, set a clip with x and y coordinates plus width and height. This is useful when a viewport screenshot is too broad but a complete element screenshot is not the right scope. Clip coordinates and the selected viewport should match the layout you intend to capture; see the Page screenshot API for the documented options.
Recommended Free Tools
Return screenshot bytes instead of writing a file
When you omit setPath(), page.screenshot() returns the image as a byte[]. That lets you pass the image to another library or compare pixels without first writing a file:
Rank #4
- CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
- SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
- MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
- KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
- INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient
byte[] image = page.screenshot();
Choose either a path for a directly saved file or returned bytes for post-processing, according to what the rest of your application needs.
Set image format, quality, and pixel scale
- Format: PNG is the default. The API also supports JPEG and WebP. JPEG and WebP quality settings do not affect PNG output. For WebP, quality 100 is lossless; lower values are lossy. WebP screenshot support was added in Playwright 1.62, so confirm your Java library version before relying on it.
- Pixel scale:
DEVICEis the default scale and creates pixels per device pixel.CSScreates one output pixel per CSS pixel, which can make high-DPI screenshots smaller. Choose based on whether your output should reflect device-pixel density or CSS layout dimensions. - Repeatability and privacy: Screenshot options can disable animations, hide the caret, apply a stylesheet, and mask selected locators. The documented mask color default is pink (
#FF00FF); set a different mask color if that is not suitable for the output. - Timeout: The Java page screenshot API documents a default timeout of 30,000 ms. Adjust it for the call or through page/context defaults when your capture requires more time.
For exact option names and defaults, consult the Page API and screenshot guide.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Make captures reliable
A screenshot records the page state Playwright has reached; it does not by itself guarantee that a site’s delayed content has appeared. For dynamic pages, wait for a meaningful page condition before taking the screenshot, and use a stable viewport and capture mode for repeat runs. If an image must exclude animations or sensitive values, use the screenshot options for animation handling and locator masking rather than relying on a later manual edit.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Best Value
- 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
- 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
- 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.
Troubleshoot common screenshot problems
- Browser executable is missing: Install the browser binaries for the project’s Playwright version with the CLI command above. Repeat the install after a library upgrade if that version expects different binaries.
- The screenshot times out: The API’s documented default screenshot timeout is 30,000 ms. Increase the per-call or page/context timeout if the capture genuinely needs longer, and verify that navigation or page conditions are not waiting indefinitely.
- The file is not where expected: Relative paths resolve from the process’s current working directory. Use an absolute path or check the directory from which the Java application is launched.
- An element image is incomplete: Locator screenshots capture the element’s bounds after scrolling it into view. Covered parts may not be visible, and a scrollable element only shows its currently scrolled content.
- The output is unexpectedly large or small: Check full-page mode, viewport dimensions, image format, and pixel scale.
DEVICEcan produce more pixels on a high-DPI device thanCSS. - WebP is unsupported: Verify the Playwright Java version. WebP screenshot support is documented as added in version 1.62.
Or skip the browser setup
If you need a screenshot without installing and managing browser binaries, ScreenshotNeo provides a website screenshot API and MCP server. One GET request can return PNG, JPEG, WebP, or PDF. Here is a cURL example:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp
See the ScreenshotNeo API documentation for request details. Cookie banners are accepted and removed before the shot, along with known newsletter popups and chat widgets. Bot checks, blank pages, and failed loads are never billed. An MCP server lets AI agents use screenshot tools, and the free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. Sign up for ScreenshotNeo and get 1,000 free screenshots a month, no card required.
Version note
Playwright’s release notes are version-specific. For example, the 1.62 release notes list Chromium 153.0.8010.12, Mozilla Firefox 155.0, and WebKit 26.6 as the browser versions tested for that release; those numbers are not evergreen requirements. Check the Java release notes for the version you deploy.
Frequently Asked Questions
How do I capture a screenshot as a Java byte array?
Call page.screenshot() without setting a path; it returns byte[].
Can Playwright Java save screenshots as WebP?
Yes. WebP support was added in Playwright 1.62; verify the version of the Java library in your project before using it.
Quick Recap
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.




