Use page.screenshot({ fullPage: true, style: '...' }) to capture the full scrollable page with temporary CSS applied. For Playwright Test visual comparisons, use toHaveScreenshot({ fullPage: true, stylePath: './screenshot.css' }) instead: the first accepts CSS text, while the second points to a stylesheet file. Both options were added in Playwright v1.41, so check your installed version if either is rejected.
Capture a full page with inline CSS
In a direct screenshot, set fullPage: true to capture the scrollable document rather than only the visible viewport. Pass CSS text in the style option to apply it temporarily during capture. The screenshot call returns an image buffer; set path to save it to a file.
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto('https://example.com', { waitUntil: 'networkidle' });
await page.screenshot({
path: 'full.png',
fullPage: true,
style: `
.newsletter-popup,
.chat-widget {
display: none !important;
}
`,
});
await browser.close();
})();
Replace the example URL and selectors with the page and elements you need. Here, style takes the stylesheet contents, not a filename. Playwright applies screenshot styles for the capture; they do not permanently change the page. See the Playwright screenshots guide and the page.screenshot API reference.
Hide only what should not appear
Use narrowly scoped selectors to hide genuinely volatile material, such as a changing embed or an unwanted popup. For example, iframe { visibility: hidden; } hides every iframe, which may also remove useful content. A targeted selector is safer when only one frame should be excluded. Screenshot CSS changes the image, so avoid hiding content your test or record is supposed to verify.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstall#1 Best Overall
- 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.
Use a stylesheet file for Playwright Test assertions
If the goal is to compare a screenshot with a stored baseline, use Playwright Test’s toHaveScreenshot() assertion. Its stylePath option accepts a path to a stylesheet file, unlike style on the direct screenshot API, which accepts CSS text.
import { test, expect } from '@playwright/test';
test('page matches the full-page screenshot', async ({ page }) => {
await page.goto('https://example.com');
await expect(page).toHaveScreenshot({
fullPage: true,
stylePath: './screenshot.css',
});
});
Create screenshot.css beside the test or adjust the path to match your project:
/* screenshot.css */
.newsletter-popup,
.chat-widget {
display: none !important;
}
toHaveScreenshot() is a Playwright Test assertion, not a method on the regular page object. The assertion captures repeatedly until two consecutive screenshots stabilize, then compares the result with its expected screenshot. That helps with transient rendering but cannot make screenshots from different environments identical. Consult the Playwright visual comparisons guide and toHaveScreenshot API reference.
Rank #2
- 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.
Choose full-page capture or an element screenshot
fullPage: true is for the entire scrollable document. If you need just one component or region, use a locator or element screenshot instead; it captures the targeted element area rather than expanding the capture to the page’s full scroll height. These approaches solve different capture problems, so choose based on what the output should represent.
Make visual comparisons repeatable
A baseline comparison is meaningful only when the capture conditions are sufficiently consistent. Playwright notes that screenshots can vary with the operating system, browser version, settings, hardware, power source, and headless mode. Keep those conditions aligned between baseline creation and comparison; CSS alone cannot eliminate environment-dependent rendering differences.
Screenshot assertions also provide controls for animations, caret visibility, masks, scale, and pixel-difference tolerances. Set them to match the change your test should detect. For example, masking a changing timestamp may be appropriate if the timestamp itself is irrelevant; broadly relaxing pixel tolerances can also conceal changes that matter. See the assertion options for the available controls.
Rank #3
- 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.
Check Playwright version support
The screenshot style option and assertion stylePath option are documented as added in Playwright v1.41. If an older project reports an unknown option or type error, check the installed Playwright release and upgrade if necessary. The documentation includes rolling and Next-version pages, so verify API details against the version used by your project.
Troubleshoot common problems
The CSS file is ignored
For page.screenshot(), pass stylesheet contents in style; it does not read a file path. For a Playwright Test screenshot assertion, pass the file path in stylePath. Also confirm that the path resolves from the test’s working context.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →The page is cut off at the viewport
Set fullPage: true on the screenshot or assertion options. Without it, the capture is limited to the visible page area. If you intended to capture only a component, use that element’s screenshot method instead.
Rank #4
- 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 screenshot assertion fails intermittently
First check whether the page contains changing content, animations, or late-loading elements. Use a narrowly scoped screenshot stylesheet or the assertion’s relevant stability controls where appropriate, then keep the browser and machine environment aligned with the baseline. The built-in wait for two consecutive matching captures does not neutralize differences across operating systems or browser versions.
The custom CSS changes too much
Inspect the selectors in the temporary stylesheet. Broad selectors such as iframe can hide all matching content; replace them with selectors targeting only the unstable or unwanted element. Remember that hiding something removes it from the image and can mask a real visual change.
The API rejects style or stylePath
Check the installed Playwright version: both options are marked as available from v1.41. Also confirm that you are using style with page.screenshot() or stylePath with the Playwright Test toHaveScreenshot() assertion.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsBest Value
- 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.
Or skip the browser setup
If you need a screenshot without running Playwright yourself, ScreenshotNeo accepts one GET request and returns an image or PDF. Its cookie-banner handling accepts the consent banner like a visitor and removes 60+ known consent platforms, newsletter popups, and chat widgets before the capture; each step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, with response headers identifying the page verdict and billing status. Its MCP server offers take_screenshot, get_page_info, and capture_pdf for AI agents and other MCP clients.
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 options. The Free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. Sign up for the free plan.
Frequently Asked Questions
Does Playwright’s screenshot CSS permanently alter the page?
No. The CSS supplied through screenshot options is applied temporarily for capture.
Can I use stylePath with page.screenshot()?
No. Use CSS text with the direct screenshot API’s style option; stylePath is for Playwright Test’s toHaveScreenshot() assertion.
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.




