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

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

For a newsletter popup that is part of the webpage, use Playwright to click the site’s real dismiss control, wait until the popup is hidden, and then capture the page. If the “popup” is a browser-native JavaScript dialog such as alert(), handle it with Playwright’s dialog event instead. The examples below use JavaScript and show how to capture either the visible viewport or the full page.

Identify what kind of popup you need to dismiss

A newsletter signup is usually an HTML element rendered inside the webpage—often a dialog or overlay. It can be located and operated with Playwright’s normal locator APIs. A JavaScript alert(), confirm(), prompt(), or beforeunload prompt is different: it is a browser dialog, not an element in the page’s DOM.

  • In-page overlay: find its close, dismiss, or “No thanks” control and click it.
  • Browser-native dialog: listen for Playwright’s dialog event and accept or dismiss it.

Use the first workflow for the usual newsletter prompt. Do not try to find a native dialog with a CSS selector or a role locator.

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

Set up Playwright

These commands assume Node.js and npm are installed. In a new project directory, install Playwright and its Chromium browser:

#1 Best Overall
Sale
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
npm init -y
npm install playwright
npx playwright install chromium

The examples use Chromium. To automate a different supported browser, install that browser with Playwright and adjust the browser launch call. Keep Playwright and the installed browser version aligned by using the installation command for the Playwright version in your project.

Dismiss an expected newsletter overlay, then capture

When the popup is expected at a known point in the flow, handle it explicitly as part of that flow. Replace the example dialog and button names with the accessible names actually exposed by the page. The following is a runnable script shape; its example URL and labels must be changed to match your target site.

const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch({ headless: true });
  const page = await browser.newPage({ viewport: { width: 1440, height: 900 } });

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

    const popup = page.getByRole('dialog', { name: 'Newsletter signup' });
    const dismissButton = popup.getByRole('button', { name: 'No thanks' });

    await dismissButton.waitFor({ state: 'visible' });
    await dismissButton.click();
    await popup.waitFor({ state: 'hidden' });

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

Save this as capture.js and run node capture.js. A successful run writes page.png in the current directory. The explicit visibility wait makes the script wait for the control to appear; the hidden-state wait verifies that the overlay is gone before capture. A click by itself does not establish that the dismissal animation or removal has finished.

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

Adapt the locator to the actual site

There is no universal newsletter-popup selector. Inspect the rendered accessibility tree or page DOM, then select the dialog and its actual dismissal control. If the widget is not exposed as a dialog, use a locator appropriate to its rendered structure, for example:

const popup = page.locator('.newsletter-modal');
const dismissButton = popup.locator('button.close-newsletter');

Those CSS selectors are illustrative only. Prefer a role and accessible name when they accurately identify the intended control. Some widgets live in an iframe; in that case, locate the relevant frame and use its locators rather than searching the main page.

When the overlay appears unpredictably

For an overlay that may appear during unrelated actions, Playwright provides page.addLocatorHandler(). It is intended for unexpected overlays, not as a general background watcher: Playwright checks handlers around actions or auto-waiting assertions. If the popup is predictable, explicit waits and dismissal in the normal flow are easier to reason about. When a locator handler could affect a sequence of low-level mouse actions, prefer a self-contained locator action such as locator.click().

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.

Handle a browser-native JavaScript dialog

Register a listener before the action that might trigger the dialog. If you install a listener, it must call accept() or dismiss(); merely logging the event can leave the page blocked and subsequent actions stalled. If no page or context dialog listener is installed, Playwright automatically dismisses these dialogs.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
page.on('dialog', async dialog => {
  console.log(`Dialog type: ${dialog.type()}`);
  await dialog.dismiss();
});

// Run the action that triggers the dialog after registering the listener.
await page.getByRole('button', { name: 'Open prompt' }).click();
await page.screenshot({ path: 'page.png' });

Use dialog.accept() instead when the page must proceed with an accepted alert or confirmation. For a prompt that needs a text value, pass the intended value to accept(). Choose the response that matches the task; a native dialog does not have an HTML close button to click.

Choose the screenshot scope

By default, page.screenshot() captures the current viewport. To capture the entire scrollable document, set fullPage: true:

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
await page.screenshot({ path: 'whole-page.png', fullPage: true });

Full-page capture produces an image as if the page were displayed on a very tall screen; use it when the deliverable needs the whole document, not just what a visitor sees at the current scroll position. Playwright’s screenshot API also has options for output format, clipping, masking, and animation behavior. Check the API documentation corresponding to the Playwright version installed in your project when those details matter.

Common problems and fixes

Symptom Likely cause What to change
The popup locator never appears or matches nothing. The role, accessible name, or CSS selector does not match the rendered widget; it may also be inside an iframe. Inspect the page’s accessibility tree and DOM, use the actual labels and structure, or target the correct frame.
The screenshot still shows the popup. The script captured after the click but before the overlay became hidden, or the click missed the actual dismiss control. Target the real dismissal control and wait for the overlay’s hidden or detached state before calling screenshot().
A click or navigation stalls after a JavaScript prompt appears. A dialog listener was registered but did not accept or dismiss the dialog. Call dialog.accept() or dialog.dismiss() in the listener, or remove the listener if automatic dismissal is desired.
A locator handler does not dismiss an intermittent overlay when expected. Locator handlers are checked around actions and auto-waiting assertions, not continuously in the background. Use an action or assertion that causes Playwright to check handlers, or explicitly handle a predictable popup in the main flow.
The output contains only the visible portion of the page. The default screenshot scope is the viewport. Pass fullPage: true if the full scrollable document is required.

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server. Its clean-shot flow accepts cookie or consent banners like a visitor and removes 60+ known consent platforms, newsletter popups, and chat widgets before capture; each of those steps can be turned off. A one-request capture looks like this:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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 parameters. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing; the response includes X-Page-Verdict and X-Billed headers. Its MCP server offers take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients. The free plan includes 1,000 shots a month without a card; paid plans start at $5 for 3,000 shots. Sign up for 1,000 free screenshots a month, with no card required.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Cost and reliability considerations

With Playwright, you run the browser automation yourself, so the code can follow the site’s real dismissal interaction and wait on the page state you choose. That also means your script depends on selectors, labels, timing, and any browser setup required by your environment. Avoid fixed sleeps when a specific visible or hidden state can be awaited; state-based waits make the intended condition explicit.

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.

For a hosted capture service, check how it reports a failed or skipped capture before building downstream processing around image output. ScreenshotNeo’s verdict and billing headers distinguish billed captures from outcomes such as bot checks, blank pages, failed loads, and cache hits. Its listed monthly plans are Free (1,000 shots, no card), Starter ($5 for 3,000), Growth ($15 for 15,000), Pro ($39 for 60,000), Scale ($99 for 250,000), and Business ($249 for 1,000,000); yearly billing gives two months free. All features are on every plan.

Frequently Asked Questions

Can I remove a newsletter popup by hiding its element instead of clicking it?

You can hide or mask an element for a presentation-specific image, but that is not the same as reproducing a visitor dismissing the prompt. If visitor-like dismissal is the goal, use the site’s actual dismiss interaction.

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

Should I use a fixed timeout after clicking the close button?

Prefer waiting for a meaningful page condition, such as the popup becoming hidden or detached. A fixed delay can be too short on a slow page and unnecessarily long on a fast one.

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.