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 DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk5 min

Playwright mein Lazy-Load Images ka Screenshot Kaise Lein

A reliable Playwright workflow for lazy-loaded images: scroll to trigger loading, verify image completion and decoding, then capture the page or target element.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Playwright mein lazy-load images ka sahi screenshot lene ke liye pehle page par scroll karke images ko load trigger karein, phir unke load aur decode hone ka intezar karein, aur uske baad screenshot capture karein. Sirf fullPage: true lagana kaafi nahi: yeh poore document ka screenshot leta hai, lekin offscreen images load karne ki guarantee nahi deta.

Reliable sequence: scroll, verify, capture

Browser ka native loading="lazy" attribute offscreen images ko tab load karne ka hint deta hai jab browser samajhta hai ki ve zaroorat ke kareeb hain. Iska threshold browser control karta hai; yeh fixed page-load event nahi hai. Isliye page.goto() ke baad load event ka intezar karna bhi yeh prove nahi karta ki har lazy image ready hai.

As an Amazon Associate I earn from qualifying purchases.

  1. Page ko navigate karein.
  2. Viewport ke through scroll karein, taaki native lazy loading ya scroll-triggered loader activate ho.
  3. Relevant images ke load hone aur decode hone ki jaanch karein.
  4. Page ya target element ka screenshot lein.

Yeh runnable JavaScript example document ko viewport-height ke 80% steps mein scroll karta hai, phir har <img> ka status check karke screenshot leta hai:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import { chromium } from 'playwright';

const browser = await chromium.launch();
const page = await browser.newPage({ viewport: { width: 1280, height: 800 } });

await page.goto('https://example.com', { waitUntil: 'domcontentloaded' });

// Scroll through the document to trigger near-viewport image loading.
await page.evaluate(async () => {
  const step = Math.max(1, window.innerHeight * 0.8);
  for (let y = 0; y < document.body.scrollHeight; y += step) {
    window.scrollTo(0, y);
    await new Promise(resolve => setTimeout(resolve, 100));
  }
  window.scrollTo(0, 0);
});

// Wait for image completion and decoding; report failures individually.
const imageResults = await page.locator('img').evaluateAll(async images => {
  return await Promise.all(images.map(async img => {
    try {
      if (!img.complete) {
        await new Promise((resolve, reject) => {
          img.addEventListener('load', resolve, { once: true });
          img.addEventListener('error', reject, { once: true });
        });
      }
      if (img.naturalWidth > 0) await img.decode();
      return {
        src: img.currentSrc || img.src,
        loaded: img.complete && img.naturalWidth > 0
      };
    } catch {
      return { src: img.currentSrc || img.src, loaded: false };
    }
  }));
});

console.log(imageResults.filter(result => !result.loaded));
await page.screenshot({ path: 'page.png', fullPage: true });
await browser.close();

The 100 ms pause is only scroll pacing in this example; it is not a universal readiness delay. The readiness check is the image completion and decode logic. In production, put an overall timeout or site-specific completion condition around waits so a stalled image cannot hang the script indefinitely. If images are inserted while scrolling, collect the final image set after the scroll pass or repeat the pass until the page’s finite completion condition is satisfied.

#1 Best Overall
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB | 1920×1080 LED Monitor, 4ms GtG, Adaptive Sync, HDMI 1.4, Tilt Adjust, Low Blue Light, 4yr Advance Replacement Warranty
  • 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

What the image check establishes

HTMLImageElement.complete indicates that loading has completed, but a failed image can also be complete. Checking naturalWidth > 0 helps distinguish a successfully loaded image from a broken one. decode() returns a promise that resolves when the image is decoded and safe to render. The example logs failures rather than letting one rejected decode hide the status of other images.

Choose full-page or element capture

Capture Use it when Important limit
page.screenshot({ fullPage: true }) You need the whole scrollable document in one tall image. It describes screenshot extent, not a promise that offscreen images were fetched or decoded. Scroll and verify first.
locator.screenshot() You need one component or matched element. A scrollable matched element’s screenshot includes only its currently scrolled content, not all hidden internal content at once.

For a long page, one full-page image may be unwieldy; choose an element capture when the useful result is a specific component. If that component sits inside a nested scrolling panel, scroll the panel itself and verify the images inside it before taking its screenshot.

Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB | 1920×1080 LED Monitor, 4ms GtG, Adaptive Sync, HDMI 1.4, Tilt Adjust, Low Blue Light, 4yr Advance Replacement Warranty
  • 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

Handle nested scrollers, infinite feeds, and non-img content

Nested scrolling panels

window.scrollTo() moves the document, not an independently scrollable panel. Use Playwright’s locator scrolling or scroll the specific container, then wait for images within that container. The locator API can bring an element into view; for controlled document movement, Playwright also provides mouse.wheel(). The right target depends on which element actually scrolls.

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

Infinite scroll

Do not try to exhaust an unbounded feed with a generic loop. Decide on a finite stopping rule first—for example, a particular item count or a known end marker—and stop when that condition is met. Then verify the final set of images and capture the intended range.

Rank #3
Dell 24 Monitor - SE2426H - 23.8-inch FHD (1920x1080) 144Hz 1ms Display, in-Plane Switching (IPS) Technology, AMD FreeSync™, TÜV 3-Star 2X HDMI, Tilt
  • 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.

Other kinds of image content

The example checks DOM <img> elements. It does not certify CSS background images, images inside iframes, dynamically swapped <picture> sources, or application loaders that use their own observer and status state. For those, inspect how the page supplies the visual and wait for its actual content-ready signal; a generic selector or delay cannot cover every site.

Wait for the condition you need, not network idle

Playwright documents networkidle as discouraged for testing readiness. Pages may keep network requests open, or become network-quiet before a particular image is usable. Prefer an explicit image condition or an application-specific signal such as the expected content appearing. For images, check completion and successful dimensions, then await decoding where the screenshot must include rendered pixels.

Rank #4
Sale
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor | 100Hz, Game Mode, Advanced Eye Comfort, HDMI and D-sub Ports (LS27D366GANXZA)
  • 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

For Playwright Test visual baselines, toHaveScreenshot() waits until two consecutive screenshots match before comparing them. That helps with visual stability, but a stable blank placeholder can still match. Verify the expected images independently before relying on the snapshot assertion.

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

Troubleshoot missing or inconsistent images

  • Screenshot has blank spaces below the fold: fullPage: true did not itself trigger lazy loading. Scroll through the document first, then check image status.
  • An image reports complete but appears broken: completion alone is not success. Check naturalWidth and inspect the image URL or its load failure.
  • The wait hangs: a load event may never arrive for a stalled request. Add an overall timeout and report the image that did not finish; use the site’s own completion signal if available.
  • Images in a panel remain unloaded: the panel may be the scroll container. Scroll that locator rather than only scrolling the window.
  • Some visuals remain absent despite all <img> checks passing: investigate CSS backgrounds, iframes, or application-managed content that the generic image loop does not cover.
  • Visual snapshots vary between runs: keep browser, operating system, viewport, and rendering environment consistent; these can affect screenshot output.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If you need a screenshot without maintaining a Playwright browser script, ScreenshotNeo provides a website screenshot API and MCP server. Its capture flow accepts cookie/consent banners like a visitor and removes 60+ known consent platforms, newsletter popups, and chat widgets before the shot; each step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers identify the page verdict and billing status. AI agents can use its MCP tools, including take_screenshot, get_page_info, and capture_pdf. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000.

For example, this cURL request returns a WebP screenshot; replace the URL with the page you need. See the ScreenshotNeo API documentation for options and response details:

Best Value
Sale
Sceptre New 22-Inch Gaming Monitor, FHD 1080p, Up to 144Hz, HDMI, DisplayPort, Built-in Speakers, Machine Black (E225W-FW144 Series, 2026)
  • 【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.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Sign up for ScreenshotNeo and start with 1,000 free screenshots a month, no card required.

Frequently Asked Questions

How do I detect when a lazy-loaded image has loaded in Playwright?

Check the image element’s complete state and naturalWidth > 0, then await decode() when you need decoded pixels ready to render.

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

Does Playwright Test’s screenshot assertion confirm that images loaded?

No. It checks for consecutive stable screenshots before comparison; separately assert that the expected images or application content are ready.

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.

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
Outdated Drivers Are Slowing You DownFree scan - exact matches
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.