Best Playwright Settings for Dynamic Page Screenshots
In this article
For reliably crisp screenshots of dynamic web pages, the top pick is Playwright's built-in fullPage: true combined with waitUntil: 'networkidle' and a generous timeout — it handles most single-page apps and infinite-scroll layouts without extra code. This combination waits for network traffic to settle, captures the entire scrollable area, and avoids the common cut-off and blank-section problems that plague default settings.
What to Look For
When configuring Playwright for screenshots, four criteria actually matter:
- Wait strategy – Dynamic content (AJAX, lazy loading, animations) needs a wait condition that ensures the page is fully rendered. Options include
load,domcontentloaded,networkidle, or explicit element waits. - Full-page capture – Whether you need the entire scrollable page or just the viewport. Playwright's
fullPageoption handles the former, but it can be slow on very long pages. - Viewport and device settings – Screenshot dimensions depend on the viewport size. For responsive sites, you may need to emulate specific devices or set a custom viewport.
- Handling dynamic elements – Timers, carousels, or infinite scroll can change content mid-capture. You need to control or wait for these to stabilize.
Playwright Default (with fullPage)
Strengths: The simplest approach: page.screenshot({ fullPage: true }) after page.goto(url, { waitUntil: 'networkidle' }). It works out-of-the-box for most static and moderately dynamic pages, captures the whole page, and requires no extra libraries.
Trade-offs: Network idle can hang on pages with continuous requests (e.g., live feeds). Full-page capture on extremely long pages may produce massive images or time out. No built-in handling for animations or delayed content.
Best for: Quick, one-off screenshots of standard websites and blogs where content loads quickly and stays put.
Playwright with Explicit Element Waits
Strengths: Instead of relying on network idle, you wait for a specific selector that indicates content is ready (e.g., await page.waitForSelector('.article-body')). This is more reliable for SPAs that fetch data after initial load, and it avoids the networkidle hang.
Trade-offs: Requires knowing the page structure and choosing the right selector. If the selector changes, the script breaks. It doesn't solve issues with lazy-loaded images below the fold unless you also scroll.
Best for: Dashboards, admin panels, and single-page apps where you know the key content container.
Playwright with Scroll and Wait (for Lazy Loading)
Strengths: Manually scroll through the page in steps, waiting for new content to load each time, then take a full-page screenshot. This ensures lazy-loaded images and infinite-scroll sections are captured. Example: loop window.scrollBy(0, 500) and wait a bit, then screenshot.
Trade-offs: Slow, especially on long pages. Can trigger extra network requests that never settle. Requires tuning scroll step and delay per site.
Best for: Social feeds, product listings, and any page with infinite scroll or lazy-loaded media.
Playwright with Animations Disabled
Strengths: Force CSS animations and transitions off via page.addStyleTag({ content: '* { animation: none !important; transition: none !important; }' }). This prevents elements from being captured mid-animation (e.g., a half-open dropdown or a fading carousel). It stabilizes the visual state for a consistent screenshot.
Trade-offs: The screenshot won't reflect the page's actual interactive behavior. Some sites rely on animations for layout (e.g., accordions), so disabling them might change the layout.
Best for: Marketing sites with hero sliders, hover effects, or animated charts where you need a static, clean capture.
Playwright with Device Emulation
Strengths: Use devices['iPhone 13'] or a custom viewport to capture mobile-specific layouts. Combined with fullPage, you get a mobile-optimized screenshot. This is essential for responsive design testing.
Trade-offs: Mobile full-page screenshots can be extremely tall and heavy. Touch events may differ from desktop, and some sites serve different content to mobile user agents.
Best for: Responsive design QA, mobile app previews, and verifying mobile-specific UI elements.
Playwright with Custom Timeout and Retry
Strengths: Set a generous timeout (e.g., 30s) and wrap the screenshot in a retry loop that checks for a stable condition (e.g., two consecutive identical DOM snapshots). This handles pages with unpredictable load times or periodic updates.
Trade-offs: Adds complexity and runtime. A retry loop can mask real issues. Not ideal for time-sensitive batch jobs.
Best for: Complex enterprise apps, real-time dashboards, and pages with third-party widgets that load erratically.
How to Choose
Start with the simplest: default + fullPage + networkidle. If that fails, move to explicit waits. For lazy-loaded content, add scrolling. For animations, disable them. For mobile, use device emulation. Your budget (time, compute) matters: full-page captures on long pages are expensive; consider viewport-only shots if you only need the fold. The main trade-off is reliability vs. speed – more waits and retries mean longer execution but fewer blank screenshots.
Frequently Asked Questions
Why does my full-page screenshot cut off at the viewport?
You likely forgot fullPage: true. Also ensure the page doesn't have a fixed-height body; use page.setViewportSize to a larger height if needed.
Why does networkidle never resolve?
Some sites have continuous requests (e.g., analytics, live chat). Use waitUntil: 'load' plus an explicit element wait instead.
How do I capture a page that loads content on scroll?
Scroll incrementally and wait for new elements to appear before taking the final screenshot. You can also use page.evaluate to scroll to the bottom and then back to top to trigger all lazy loads.
Can I take a screenshot of a specific element?
Yes, use locator.screenshot() on a selector. This is useful for capturing a chart or a modal without the rest of the page.
How do I handle cookie banners or pop-ups that block content?
Before screenshotting, click the accept button or remove the element via page.evaluate. You can also use page.addStyleTag to hide it.
What is the best file format for screenshots?
PNG for quality, JPEG for smaller size. Playwright supports both via type option. For dynamic pages with text, PNG avoids compression artifacts.
Bottom Line
For most dynamic pages, start with waitUntil: 'networkidle' and fullPage: true. If that fails, add an explicit wait for a key element. For lazy-loaded or animated pages, combine scrolling and animation disabling. The best setting is the one that matches your page's behavior – test on a sample to find the minimal reliable configuration.