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

Click the modal’s close control, wait until the modal is hidden or detached, and only then take the screenshot. Use selectors that match the actual page; the examples below use placeholders because no target page or markup was supplied.

Dismiss the modal and confirm it is gone

With Puppeteer’s Locator API, click the close control and wait for the modal root to disappear before capturing the page:

const closeButton = page.locator('[role="dialog"] button[aria-label="Close"]');
await closeButton.click();
await page.waitForSelector('[role="dialog"]', { hidden: true });
await page.screenshot({ path: 'after-dismiss.png' });

Replace both selectors with ones verified against the target page. The example assumes a dialog with an accessible close button. A site may use different markup, labels, or a different modal root. Puppeteer’s screenshot guide documents page screenshots; its Page.waitForSelector() API can wait for a selector to become hidden or detached.

Choose a reliable waiting approach

Locator for the close control

A Locator automatically waits for the target element and its state when performing an action, making it a practical choice when a clear selector identifies the close control. See Puppeteer’s page interactions guide.

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.
#1 Best Overall
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB
  • 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

Explicit selector waits

Alternatively, wait for the close control to become visible, click it, then wait for the modal root to become hidden:

await page.waitForSelector('[role="dialog"] button[aria-label="Close"]', {
  visible: true,
});
await page.click('[role="dialog"] button[aria-label="Close"]');
await page.waitForSelector('[role="dialog"]', { hidden: true });
await page.screenshot({ path: 'after-dismiss.png' });

The documented default timeout for waitForSelector is 30 seconds; you can change it through the method’s options. This lower-level approach does not automatically retry a later action if that action fails. Consult the Page.waitForSelector reference for the current options and behavior.

Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB
  • 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 navigation, frames, and selectors

If closing the modal navigates

If clicking the control triggers navigation rather than merely closing an overlay, coordinate the click with the navigation wait so Puppeteer does not miss the event:

await Promise.all([
  page.waitForNavigation(),
  page.locator('[role="dialog"] button[aria-label="Close"]').click(),
]);
await page.screenshot({ path: 'after-dismiss.png' });

Use this pattern only when the close action actually navigates. The Page class reference documents the click/navigation coordination pattern.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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.

If the modal is inside an iframe

Identify the frame that contains the modal, then locate and click its close control and wait for the modal state in that frame. Puppeteer provides selector waiting on Frame as well as on Page.

If the modal does not disappear

Confirm that the modal selector matches the modal root, not a nested element that remains after closing. Check that the close selector identifies the intended control and that clicking it is permitted by the page. There is no universal modal selector; inspect the target page’s DOM or accessible labels and adapt the example.

Rank #4
Sale
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor
  • 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

Troubleshoot timing and capture problems

  • The wait times out: The selector may be wrong, the modal may not have appeared, or the close action may not have removed or hidden the element you are waiting on. Verify the actual modal root and control selectors.
  • The screenshot still includes the modal: Ensure the screenshot is awaited after the hidden-state wait, and that the wait targets the visible overlay rather than an unrelated element.
  • The click fails: Check whether the close control is present and visible, and whether an overlay or another page state prevents interaction. A Locator can automatically wait for the element and its state; with explicit waits, make sure the control is visible before clicking.
  • The page changes after clicking: Use the coordinated navigation pattern instead of waiting only for the modal to disappear.
  • The modal is in a frame: Perform the interaction and state wait in the corresponding frame, not the top-level page.

A fixed sleep is less dependable than waiting for the UI state: animation and page-loading durations vary. Capture only after the relevant state has been confirmed.

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 rather than a Puppeteer workflow, ScreenshotNeo provides a website screenshot API and MCP server. Its API accepts one GET request with a URL and can return an image or PDF. For example, save a screenshot of a page after configuring your key:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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

See the ScreenshotNeo documentation for API details. ScreenshotNeo accepts cookie and consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each of those steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers report the page verdict and billing status. Its MCP server lets AI agents using Claude, Cursor, or another MCP client use 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 shots.

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

Frequently Asked Questions

What does Puppeteer capture with page.screenshot()?

It captures the page; Puppeteer also documents element-only screenshots through ElementHandle.screenshot(). See the screenshot guide.

Which Puppeteer version do these examples target?

The official documentation surfaced for this guide is Puppeteer 25.12.0. Check the current official API reference if you are using a later version.

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

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.