Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon 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 desk4 min

How to Capture a Web Page Screenshot After Dismissing a Modal

Dismiss the page overlay or handle the browser dialog, verify it is gone, then capture the viewport, full page, or a specific element with Playwright.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Dismiss the modal first, confirm it is gone, and then capture the page. The key is to identify what kind of modal you have: an overlay built into the web page needs to be closed through the page, while a JavaScript alert, confirm, or prompt is a separate browser dialog with its own handling.

Identify the kind of modal

A page overlay is part of the website’s interface. It may be a cookie notice, sign-in prompt, newsletter form, or other panel layered over the page. Close it using its own button or the site’s expected interaction.

As an Amazon Associate I earn from qualifying purchases.

A JavaScript alert, confirm, or prompt is a browser dialog, not a page element. In Playwright, these dialogs are dismissed automatically by default. If you add a dialog listener, your code must call accept() or dismiss(); otherwise the page can remain blocked and actions can stall.

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

Dismiss a page overlay with Playwright

When you know a page overlay will appear, explicitly wait for it and close it in the normal sequence before taking the screenshot. Replace the example selector with one that matches the site’s actual close button, and adjust the overlay selector to the page.

#1 Best Overall
Sale
Logitech M185 Compact Ambidextrous 2.4 GHz Wireless Mouse - Swift Grey | Ambidextrous mouse with 2.4 GHz USB-A Nano Receiver, Optical Tracking, 12-Months Battery Life, PC, Mac, Laptop compatible
  • Compact Mouse: With a comfortable and contoured shape, this Logitech ambidextrous wireless mouse feels great in either right or left hand and is far superior to a touchpad
  • Durable and Reliable: This USB wireless mouse features a line-by-line scroll wheel, up to 1 year of battery life (2) thanks to a smart sleep mode function, and comes with the included AA battery
  • Universal Compatibility: Your Logitech mouse works with your Windows PC, Mac, or laptop, so no matter what type of computer you own today or buy tomorrow your mouse will be compatible
  • Plug and Play Simplicity: Just plug in the tiny nano USB receiver and start working in seconds with a strong, reliable connection to your wireless computer mouse up to 33 feet / 10 m (5)
  • Better than touchpad: Get more done by adding M185 to your laptop; according to a recent study, laptop users who chose this mouse over a touchpad were 50% more productive (3) and worked 30% faster (4)
const overlay = page.locator('.modal');
await overlay.waitFor({ state: 'visible' });
await overlay.locator('button[aria-label="Close"]').click();
await overlay.waitFor({ state: 'hidden' });

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

The visibility check ensures the expected overlay appeared; the hidden-state check ensures the screenshot is not taken while it remains on screen. Sites use different markup and close-button labels, so inspect the page and choose selectors that match its controls. If the overlay does not always appear, make the wait conditional or handle its absence rather than allowing a wait for visibility to time out.

When the overlay timing is unpredictable

Playwright’s locator handler can deal with an overlay that appears during an action or an auto-waiting assertion. It does not run simply because an overlay appears while the script is otherwise idle. Use an explicit wait-and-close sequence for a predictable overlay; use a handler when the timing is uncertain and relevant actions or assertions will trigger it.

Rank #2
Sale
Logitech G305 Lightspeed Wireless Gaming Mouse - Black | 12,000 DPI, Lightweight, 6 Programmable Buttons, 250h Battery, On-Board Memory, Compatible with PC and Mac
  • The next-generation optical HERO sensor delivers incredible performance and up to 10x the power efficiency over previous generations, with 400 IPS precision and up to 12,000 DPI sensitivity
  • Ultra-fast LIGHTSPEED wireless technology gives you a lag-free gaming experience, delivering incredible responsiveness and reliability with 1 ms report rate for competition-level performance
  • G305 wireless mouse boasts an incredible 250 hours of continuous gameplay on just 1 AA battery; switch to Endurance mode via Logitech G HUB software and extend battery life up to 9 months
  • Wireless does not have to mean heavy, G305 lightweight mouse provides high maneuverability coming in at only 3.4 oz thanks to efficient lightweight mechanical design and ultra-efficient battery usage
  • The durable, compact design with built-in nano receiver storage makes G305 not just a great portable desktop mouse, but also a great laptop travel companion, use with a gaming laptop and play anywhere
await page.addLocatorHandler(
  page.locator('.modal'),
  async modal => {
    await modal.locator('button[aria-label="Close"]').click();
  }
);

// An action or auto-waiting assertion can trigger the handler.
await page.locator('main').waitFor({ state: 'visible' });
await page.screenshot({ path: 'page.png' });

Use the selector and interaction that fit the target site. If no later action or auto-waiting assertion checks the page, the handler may not run before the screenshot.

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

Handle JavaScript browser dialogs

Playwright dismisses JavaScript dialogs automatically unless you register a listener. If you do register one, resolve each dialog explicitly:

Rank #3
Sale
Logitech M185 Compact Ambidextrous Wireless Mouse with Rubber Grips - Blue | Ambidextrous mouse with 2.4 GHz USB-A Nano Receiver, Optical Tracking, 12-Months Battery Life, PC, Mac, Laptop compatible
  • Compact Mouse: With a comfortable and contoured shape, this Logitech ambidextrous wireless mouse feels great in either right or left hand and is far superior to a touchpad
  • Durable and Reliable: This USB wireless mouse features a line-by-line scroll wheel, up to 1 year of battery life (2) thanks to a smart sleep mode function, and comes with the included AA battery
  • Universal Compatibility: Your Logitech mouse works with your Windows PC, Mac, or laptop, so no matter what type of computer you own today or buy tomorrow your mouse will be compatible
  • Plug and Play Simplicity: Just plug in the tiny nano USB receiver and start working in seconds with a strong, reliable connection to your wireless computer mouse up to 33 feet / 10 m (5)
  • Better than touchpad: Get more done by adding M185 to your laptop; according to a recent study, laptop users who chose this mouse over a touchpad were 50% more productive (3) and worked 30% faster (4)
page.on('dialog', async dialog => {
  await dialog.dismiss();
});

Use accept() instead when the workflow must confirm an alert or accept a confirmation. For a prompt, accepting can also require supplying the expected text. Leaving a registered dialog unhandled can prevent the page from progressing to the capture.

Choose what to capture

Capture scope What it includes Use it when
Viewport The currently visible browser page area You need the page as framed on screen.
Full page The whole scrollable page You need below-the-fold content in one image.
Element locator A selected page element You need a component rather than the whole page.

For a full-page screenshot, dismiss the modal first and then capture:

Rank #4
Amazon Basics 3-Button USB Wired Mouse with Responsive Tracking, Plug & Play, Compatible with Windows and Mac, Black
  • Computer mouse for easily navigating a computer interface; click, scroll, and more
  • USB-A wired connection; if existing device only supports USB-C, an additional adapter will be required
  • High-definition (1000 dpi) optical tracking ensures responsive cursor control for precise tracking and easy text selection
  • 3 buttons offer effortless fingertip control
  • Plug-and-go ready for instant use
await page.screenshot({ path: 'page.png', fullPage: true });

For one element, take a locator screenshot:

await page.locator('.header').screenshot({ path: 'header.png' });

A locator screenshot scrolls the element into view. Check that another element is not covering the target, since a covering element can affect what appears in the image. Playwright also offers CSS-pixel and device-pixel scale options; device-pixel scale can produce larger images on high-DPI displays.

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

Troubleshoot captures that still show a modal

  • The close action does nothing: Check that the selector targets the actual close control and that it is inside the intended overlay. Some sites require a specific button or interaction.
  • The screenshot happens too soon: Wait for the overlay to reach the hidden state before capture rather than relying only on the click completing.
  • A locator handler did not run: A handler runs when an action or auto-waiting assertion checks the page, not merely when the overlay appears. Add a relevant action or use an explicit wait-and-close sequence.
  • The page stalls on a browser dialog: If a dialog listener is registered, make sure it calls accept() or dismiss().
  • The element image is obscured: Inspect the target and remove or dismiss any overlay covering it before using the locator screenshot.
  • The expected overlay never appears: Avoid an unconditional wait for visibility when the modal is optional; handle its absence so the rest of the capture can proceed.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server. For a one-request capture after its cleanup steps:

Best Value
Sale
Acer Wireless Mouse for Laptop, 2.4GHz Computer Mouse 3 Adjustable 1600 DPI | Office Cordless USB Mice with USBA Receiver, 6 Buttons, Medium to Large Sized Hands Compatible with PC, Laptop, Desktop
  • 【Plug and Play for Home/Office/School】The wireless computer mouse features 2.4GHz connectivity, delivering a stable, interference-free connection up to 32ft. Designed for 𝐦𝐞𝐝𝐢𝐮𝐦 𝐭𝐨 𝐥𝐚𝐫𝐠𝐞 𝐬𝐢𝐳𝐞𝐝 𝐡𝐚𝐧𝐝𝐬, it ensures comfortable use all day. Simply plug in the USB-A receiver for instant pairing—no drivers needed. 📌📌 If the mouse isn’t suitable, place the USB receiver in the battery compartment and return both.
  • 【3 Levels Adjustable DPI】This travel USB mouse offers 3 adjustable DPI settings (800, 1200, 1600), allowing you to customize sensitivity for precise design work. Effortlessly switch to match your task and elevate your productivity. 📌 Please remove the film at the bottom of the mouse before use.
  • 【Effortless Browsing】Equipped with forward and backward buttons, this computer mice streamlines your workflow, making it easy to navigate through web pages and files with a simple click. 📌Side button does not work on Mac.
  • 【Visible Indicator Light】 The pc mouse features a visual indicator for DPI levels and low battery alerts. The red light flashes once for 800 DPI, twice for 1200 DPI, and three times for 1600 DPI. When the battery level is below 10%, the light flashes red until the mouse is completely out of power.
  • 【Click to Wake】With smart sleep mode, it saves power by standby after 10 inactive minutes, just 2-3 clicks to wake. This efficient design delivers 3x longer battery life than motion-wake mice. Engineered for durability, its buttons and scroll wheel are tested for 10 million clicks, ensuring long-term reliability and consistent performance.
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 API documentation for options and response details. Before capture, it accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers identify the page verdict and billing status. Its MCP server lets AI agents use take_screenshot, get_page_info, and capture_pdf. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots. Sign up for free: 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.

Leave a Reply

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

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.

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
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver 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.