Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk4 min

How to Disable CSS Animations for Playwright Screenshots

Set animations: 'disabled' on Playwright's direct screenshot call. Learn how it handles finite and infinite animations, when to use reduced-motion emulation, and how screenshot assertions differ.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a one-off Playwright screenshot, pass animations: 'disabled' to page.screenshot():

await page.screenshot({ animations: 'disabled' });

This handles CSS animations, CSS transitions, and Web Animations during capture. Direct screenshots otherwise allow animations to run. For visual regression assertions, toHaveScreenshot() already disables animations by default.

Disable animations in a direct screenshot

Set the screenshot option explicitly wherever you capture a page image:

await page.screenshot({ path: 'page.png', animations: 'disabled' });

The option is available on Playwright’s page.screenshot() API. It covers CSS animations, CSS transitions, and Web Animations. Consult the Playwright Page API for the installed release’s current options.

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

What “disabled” does to animation state

It does not freeze every animation at the exact frame visible when the call begins. Playwright fast-forwards finite animations to completion, which fires transitionend. Infinite animations are canceled at their initial state for the screenshot, then played over after capture. If application code responds to transitionend, that event may affect the state captured; inspect the result when the page relies on such handlers.

Use screenshot assertions for visual regression tests

With Playwright Test, capture and compare an expectation using:

import { test, expect } from '@playwright/test';

test('page matches its screenshot', async ({ page }) => {
  await page.goto('https://example.com');
  await expect(page).toHaveScreenshot();
});

toHaveScreenshot() waits until two consecutive page screenshots produce the same result before comparing against the expectation. Its animations option defaults to disabled, unlike direct page.screenshot(), whose default is allow. See the official PageAssertions API.

Choose the right way to reduce motion

Approach Use it for What it does Important limitation
page.screenshot({ animations: 'disabled' }) A direct screenshot Screenshot-time handling of CSS animations, CSS transitions, and Web Animations. Finite animations are fast-forwarded and emit transitionend; infinite ones return to their initial state for capture.
page.emulateMedia({ reducedMotion: 'reduce' }) Testing the site’s response to a user’s reduced-motion preference Emulates the prefers-reduced-motion media feature. It does not guarantee that a page suppresses every animation; that depends on the site’s CSS and application behavior.
page.screenshot({ style: '...' }) A targeted capture-only visual override Applies a stylesheet for the screenshot, including through Shadow DOM and inner frames. Your CSS may change layout or visibility. The Page API lists this option as added in v1.41; check compatibility with your installed Playwright version.

Emulate reduced motion when that preference is what you are testing

await page.emulateMedia({ reducedMotion: 'reduce' });
await page.screenshot({ path: 'reduced-motion.png' });

Playwright documents reduce and no-preference; passing null clears the emulation. This changes the emulated media preference, not the screenshot option. Use it to test how the page responds to prefers-reduced-motion, rather than as a universal replacement for screenshot-time animation handling. See Playwright’s emulateMedia API.

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

Use a screenshot stylesheet for specific dynamic elements

For a page element that needs a custom treatment, apply a capture-time CSS override:

await page.screenshot({
  path: 'page.png',
  style: '.ticker, .animated-banner { visibility: hidden !important; }'
});

The screenshot style option is useful for targeted changes such as hiding a ticker. It is not the same as disabling all animations: write rules that fit the page, and check that they do not hide content or alter the layout you intend to test.

Runnable example with Playwright Test

For a standalone direct screenshot in a Node.js project using Playwright:

import { chromium } from 'playwright';

const browser = await chromium.launch();
const page = await browser.newPage();

try {
  await page.goto('https://example.com');
  await page.screenshot({ path: 'page.png', animations: 'disabled' });
} finally {
  await browser.close();
}

Use the playwright package for the standalone browser example. If your project uses Playwright Test, use its @playwright/test runner and toHaveScreenshot() for screenshot assertions.

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.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot inconsistent screenshots

  • Animations still appear in a direct capture: Confirm the option is on the actual page.screenshot() call. The direct API defaults to allowing animations.
  • A screenshot assertion behaves differently from a manual capture: toHaveScreenshot() has its own stabilization behavior and defaults to disabled animations. Use the direct screenshot option if you are calling page.screenshot().
  • The page changes after an animation ends: Finite animations are fast-forwarded and fire transitionend. Check whether event listeners update content or application state before capture.
  • Reduced-motion emulation has no visible effect: The page must implement a response to prefers-reduced-motion. Emulation changes the preference; it does not impose a universal animation rule.
  • A CSS override produces a different layout: Inspect the injected rules and remove or narrow selectors that affect geometry or visibility. Screenshot styles can affect Shadow DOM and inner frames as well.
  • An option is rejected by the installed version: Check the official API documentation against your project’s Playwright release. In particular, the screenshot style option is documented as added in v1.41.

Or skip the browser setup

If you need a screenshot without running and maintaining a browser in your own script, ScreenshotNeo is a website screenshot API and MCP server. A single GET request can return an image or PDF. This is an alternative capture service, not a way to configure Playwright itself or test a site’s reduced-motion behavior.

Example using cURL:

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 parameters. It accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify the page verdict and billing status in headers. Its MCP server includes tools for AI agents to take screenshots. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots.

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

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.

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

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.