Use capture-scoped CSS when you want a rule to affect only one screenshot, and inject a stylesheet when the modified page state must persist. In Playwright Test, pass a stylesheet with stylePath. For a direct Playwright capture, use the screenshot option style or call page.addStyleTag(). In Puppeteer, call page.addStyleTag() before page.screenshot(). This lets you hide chat widgets, freeze volatile regions, remove irrelevant banners, or adjust layout without changing your application’s production CSS.
Choose the CSS method that matches the capture
| Method | Best fit | How it behaves | Important consideration |
|---|---|---|---|
Playwright Test stylePath |
Visual regression assertions | Applies a stylesheet while Playwright creates the screenshot used by toHaveScreenshot(). |
Designed for screenshot assertions; the documentation describes support for dynamic elements, Shadow DOM and inner frames. |
Playwright Page screenshot style |
One-off or scripted captures | Applies stylesheet text for the screenshot operation. | Useful when the rule should not remain in the page afterward. |
page.addStyleTag() in Playwright or Puppeteer |
Several actions should see the modified page | Inserts a <style> element or external stylesheet into the document. |
The mutation remains available to subsequent page operations. |
Keep the selector narrow. A rule that hides .live-chat-widget is safer than a broad rule such as div { display:none }, which can remove meaningful content from the image.
Playwright Test: apply a stylesheet with stylePath
For a visual assertion, create a CSS file next to your test and pass its path to expect(page).toHaveScreenshot(). The option is intended for screenshot assertions and is identified in current Playwright documentation as available since version 1.41.
1. Create the temporary stylesheet
/* screenshot.css */
/* Hide a transient control that is irrelevant to this baseline. */
.live-chat-widget {
visibility: hidden !important;
}
/* Freeze an animated region without removing its layout box. */
.rotating-promo {
animation: none !important;
transition: none !important;
}
visibility:hidden keeps the element’s space while making it invisible. That can preserve layout better than display:none. Use the latter only when removing the element’s space is part of the intended image.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →2. Pass the file to the assertion
import { test, expect } from '@playwright/test';
import path from 'node:path';
test('capture page with a temporary stylesheet', async ({ page }) => {
await page.goto('https://example.com');
await expect(page).toHaveScreenshot({
stylePath: path.join(__dirname, 'screenshot.css'),
});
});
stylePath accepts a file name or an array of file names. Use multiple files when you want to keep general stabilization rules separate from page-specific overrides.
#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.
Playwright Page screenshots: use the capture-only style option
For a direct page capture rather than a test assertion, put stylesheet text in the screenshot options. This is the cleanest choice when the override exists only to produce this image.
import { chromium } from 'playwright';
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
await page.screenshot({
path: 'capture.png',
style: '.live-chat-widget { visibility: hidden !important; }',
});
await browser.close();
The CSS is applied while the screenshot is made. It is not a replacement for your site’s stylesheet and should not be treated as a production customization.
When the page itself must stay modified: addStyleTag()
Use page.addStyleTag() when later actions should see the inserted rules—for example, when you need to click or measure the page after hiding a panel.
import { chromium } from 'playwright';
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
await page.addStyleTag({
content: `
.live-chat-widget { visibility: hidden !important; }
.rotating-promo { animation: none !important; }
`,
});
// Subsequent locators and measurements see the injected stylesheet.
await page.screenshot({ path: 'capture.png' });
await browser.close();
The Page API also accepts a file path or URL instead of inline content. Because this changes document state, avoid it when you need a strictly capture-scoped override.
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.
Puppeteer: inject CSS, then capture
Puppeteer’s equivalent is to navigate, insert a style tag, and call page.screenshot(). Its guide demonstrates waitUntil: 'networkidle2' as one navigation example; dynamic applications may need a more specific readiness check.
import puppeteer from 'puppeteer';
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://example.com', { waitUntil: 'networkidle2' });
await page.addStyleTag({
content: `
.live-chat-widget { visibility: hidden !important; }
.rotating-promo { animation: none !important; transition: none !important; }
`,
});
await page.screenshot({ path: 'capture.png', fullPage: true });
await browser.close();
You can also target one element rather than the entire page. In Puppeteer, the screenshot API supports an element handle’s screenshot method; use that when the image should contain only a component.
Write CSS that improves, rather than falsifies, the image
Hide irrelevant overlays
Consent prompts, chat launchers, timestamps and rotating notices can make a baseline noisy. Hide only elements that do not belong in the capture’s purpose. If a banner is part of the user experience you are documenting, leaving it visible is more accurate than suppressing it.
Windows 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 reinstallOutdated 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 matchStop motion and transitions
* {
animation: none !important;
transition: none !important;
caret-color: transparent !important;
}
This broad rule can stabilize an image, but it also affects every element. Prefer a page-specific selector when only one component is unstable.
Handle fixed and sticky controls carefully
Fixed headers and floating buttons can cover content in a full-page image. Before hiding them, check whether the overlap reflects what a real visitor sees. If you do suppress one, use its stable class or an attribute selector and preserve the rest of the layout where possible.
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.
Reach content inside frames and Shadow DOM
Playwright’s screenshot assertion stylesheet is documented as able to pierce Shadow DOM and apply to inner frames. This is useful for volatile widgets that ordinary page-level selectors cannot reach. Verify the selector against the rendered component rather than assuming a host element’s class also matches its internal nodes.
Wait for the state you actually want to capture
CSS injection does not make fonts, images or asynchronous content ready. Navigate first, then wait for the page-specific condition that defines a complete image: a heading becoming visible, a loading indicator disappearing, a known API result rendering, or a network-idle state when that is genuinely appropriate.
Free tools Windows power users keep installed
One-click scans. No signup required.
await page.goto('https://example.com');
await page.locator('[data-test="report-ready"]').waitFor();
await page.screenshot({
path: 'report.png',
style: '.live-chat-widget { visibility: hidden !important; }',
});
Puppeteer’s networkidle2 is a useful example, not a universal guarantee. Pages that poll, stream data or lazy-load images can continue changing after network activity appears quiet. For full-page captures, scroll or otherwise trigger lazy content according to the application’s behavior before taking the image.
Make visual comparisons reproducible
Even identical CSS can produce different pixels across host operating systems, browser versions, browser settings, hardware, power sources and headless modes. Keep those conditions stable between a baseline and a later run. Pin the browser version used by your automation, use the same viewport and device scale factor, and avoid comparing captures made on materially different environments.
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
- Use a fixed viewport and device scale factor.
- Use the same browser and headless mode for baseline and comparison.
- Wait for fonts and the content that matters to your test.
- Disable only known sources of nondeterminism.
- Keep selectors resilient; prefer data attributes or stable component names over generated class names.
Common failures and fixes
The rule has no effect
Cause: the selector does not match the rendered element, the element is inside a frame or Shadow DOM, or a more specific rule wins. Fix: inspect the live DOM, use the correct frame or component boundary, and add !important only for a narrowly scoped stabilization rule.
The screenshot is taken before the CSS appears
Cause: capture starts before an external stylesheet or page mutation is applied. Fix: await page.addStyleTag(); with stylePath or screenshot style, pass the option directly to the screenshot call.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minuteContent is missing after hiding an overlay
Cause: a broad selector matched real content or display:none collapsed a container needed for layout. Fix: narrow the selector, try visibility:hidden, and inspect the resulting geometry before capture.
Images or fonts are incomplete
Cause: the page was considered ready before its visual assets finished loading. Fix: wait for a meaningful page-specific locator or application state, and ensure lazy-loaded regions have been activated.
Best 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.
Baselines differ on another machine
Cause: rendering varies with browser, operating system, hardware or headless settings. Fix: run comparisons in a consistent environment and treat cross-environment pixel differences as expected unless you have normalized those variables.
The page looks right, but later test steps fail
Cause: a capture-only rule was expected to persist. Fix: use addStyleTag() when subsequent interactions must see the modified state; use screenshot style or stylePath when the change belongs only to the image.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Or skip the browser setup
ScreenshotNeo provides a website screenshot API and MCP server for developers. You can send one GET request and receive a PNG, JPEG, WebP or PDF, without maintaining Playwright or Puppeteer launch code. Its custom CSS option is useful when you need capture-specific rules alongside other capture settings.
With the API, cookie and consent banners, newsletter popups and chat widgets are removed before the shot. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads and cache hits are not billed, and response headers identify the page verdict and billing result. An MCP server exposes take_screenshot, get_page_info and capture_pdf for Claude, Cursor and other MCP clients.
curl -G "https://api.screenshotneo.com/v1/shot"
-d access_key=YOUR_API_KEY
--data-urlencode url=https://stripe.com
-o shot.webp
See the ScreenshotNeo documentation for request options and authentication. The service offers 1,000 screenshots per month free with no card; paid plans start at $5 for 3,000 shots, and every feature is included on every plan. Create a free ScreenshotNeo account.
Python and Node.js alternatives
Python
import requests
r = requests.get(
"https://api.screenshotneo.com/v1/shot",
params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"},
timeout=90,
)
r.raise_for_status()
open("shot.webp", "wb").write(r.content)
Node.js
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const buffer = Buffer.from(await res.arrayBuffer());
await import('node:fs/promises').then(fs => fs.writeFile('shot.webp', buffer));
Frequently Asked Questions
Should I use stylePath for a normal Playwright screenshot?
No. stylePath belongs to Playwright Test screenshot assertions. For a direct capture, use the screenshot style option or page.addStyleTag().
Can injected CSS change the application permanently?
No. These techniques change the loaded document in the browser session. They do not edit your production stylesheets or deploy a site change.
Why does networkidle2 sometimes still produce an incomplete image?
A page can continue rendering after network activity quiets, especially with polling, streaming or lazy-loaded content. Wait for the specific visual state your capture requires.
Quick Recap
Is hiding a cookie banner always appropriate for a screenshot?
Only when the banner is irrelevant to the image’s purpose. Suppressing meaningful user-interface content can make the capture misleading.
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.

