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

To capture a product page with a consent popup in Playwright, first determine whether the popup is an HTML overlay or a JavaScript browser dialog. Use a locator for an HTML banner; use Playwright’s dialog event for a JavaScript alert, confirm, prompt, or beforeunload dialog. Then capture the page in the state you actually need—with the consent notice visible or after a deliberate choice.

Identify the kind of popup before automating it

A cookie or privacy banner is usually part of the webpage’s DOM. Find its actual controls and use Playwright locators to interact with them. A JavaScript alert, confirm, prompt, or beforeunload prompt is a browser dialog and must be handled through Playwright’s dialog event.

What you see How Playwright handles it What happens if you do nothing
Consent panel rendered on the page Locate the panel’s controls and, if appropriate, click one. It remains page content and may cover or obstruct other content.
JavaScript browser dialog Use a dialog handler and call accept() or dismiss(). Playwright auto-dismisses it if no dialog listener is registered. If a listener is registered, it must resolve the dialog or an action can stall.

There is no universal consent-banner selector or button label. Inspect the target site and use its actual accessible name and structure. Playwright’s Page API documentation covers locators and page behavior; its Dialogs guide explains browser-dialog handling.

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

Choose the state your screenshot should show

Keep the consent notice visible

If the screenshot is meant to document the popup, do not click an accept, reject, or preference button. Wait for the relevant banner to appear, then capture the page.

Capture the page after a choice

Click the intended control, then verify that the page has reached the expected state before taking the screenshot. This is an automated interaction with the site’s UI; do not represent it as legal consent on behalf of a real user.

Reproduce a fresh visit

Use a new, non-persistent browser context when the screenshot should begin without browsing data from a previous run. Browser contexts are isolated and do not write browsing data to disk. If instead the screenshot should reflect an already saved preference, use the state that matches that scenario. The correct storage strategy depends on the site and the test goal; there is no one-size-fits-all setting. See the BrowserContext documentation.

Runnable example: capture after choosing a consent option

This Node.js example starts in a fresh context, finds an observed button by its accessible name, clicks it, checks that the consent panel is gone, and saves a screenshot. Replace the URL, locator and button name with values observed on the site. The accessible role and name are examples, not standard consent labels.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch();
  const context = await browser.newContext();
  const page = await context.newPage();

  try {
    await page.goto('https://example.com/product');

    // Replace these selectors and names with the site's actual consent UI.
    const consentPanel = page.getByRole('dialog', { name: 'Privacy choices' });
    await consentPanel.waitFor({ state: 'visible' });
    await consentPanel.getByRole('button', { name: 'Reject optional' }).click();
    await consentPanel.waitFor({ state: 'hidden' });

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

If the site does not expose the panel with the dialog role, inspect its markup and use a locator that matches the real element. If the screenshot should show the banner, omit the click and hidden-state wait; instead wait for the panel to be visible before capturing.

Handle JavaScript dialogs only when the page uses them

Playwright automatically dismisses JavaScript dialogs when no dialog listener is installed. If the script installs a listener, the handler must accept or dismiss the dialog. Register it before the action that triggers the prompt if the script needs to choose deliberately.

#1 Best Overall
Sale
Motorola Moto g - 2026 | Unlocked | Made for US 4/128GB | 50MP Camera | Pantone Slipstream, Cellular_Phone
  • Universal unlocked. Compatible with all major U.S. carriers, including Verizon, AT&T, T-Mobile and other prepaid carriers.
  • Super-bright, super-smooth 6.7" display. See your screen clearly even outdoors in sunlight, and enjoy seamless views with a fast-refreshing 120Hz display.*
  • AI-powered camera system. Take stunning photos in any light with the 50MP camera**, look your best with a 32MP selfie cam*****, and capture extreme close-ups.
  • Superfast 5G performance. Unleash your entertainment at 5G speed*** with the MediaTek Dimensity 6300 chipset and up to 12GB of RAM with RAM Boost****.
  • Long-lasting battery + TurboPower charging. Power through day after day with a 5200mAh battery, then get hours of power in just minutes.****
page.on('dialog', async dialog => {
  console.log(`Dialog type: ${dialog.type()}`);
  await dialog.dismiss();
});

await page.getByRole('button', { name: 'Open prompt' }).click();

A logging-only handler is not enough: leaving the dialog unresolved can block the action. Choose accept() or dismiss() according to the behavior the capture is intended to represent.

Wait for the intended page state, then capture

For a stable screenshot, wait for a meaningful condition—such as the consent panel becoming visible or disappearing—rather than relying on a fixed delay or waiting for all network activity to stop. Playwright discourages networkidle as a testing readiness strategy; background analytics and other requests can make it unsuitable. Match the assertion to the site’s actual UI.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Sale
Samsung Galaxy A17 5G Smart Phone 128GB US 1 Yr Manufacturer Warranty Black
  • YOUR CONTENT, SUPER SMOOTH: The ultra-clear 6.7" FHD+ Super AMOLED display of Galaxy A17 5G helps bring your content to life, whether you're scrolling through recipes or video chatting with loved ones.¹
  • LIVE FAST. CHARGE FASTER: Focus more on the moment and less on your battery percentage with Galaxy A17 5G. Super Fast Charging powers up your battery so you can get back to life sooner.²
  • MEMORIES MADE PICTURE PERFECT: Capture every angle in stunning clarity, from wide family photos to close-ups of friends, with the triple-lens camera on Galaxy A17 5G.
  • NEED MORE STORAGE? WE HAVE YOU COVERED: With an improved 2TB of expandable storage, Galaxy A17 5G makes it easy to keep cherished photos, videos and important files readily accessible whenever you need them.³
  • BUILT TO LAST: With an improved IP54 rating, Galaxy A17 5G is even more durable than before.⁴ It’s built to resist splashes and dust and comes with a stronger yet slimmer Gorilla Glass Victus front and Glass Fiber Reinforced Polymer back.

Use page.screenshot() after the page is in the desired state. The Page API supports a full-page capture and masking selected locators. These options change the image; masking a consent banner only covers its pixels in the output. It does not dismiss the banner, interact with the site, or change consent state.

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

// Full scrollable page
await page.screenshot({ path: 'product-full.png', fullPage: true });

// Mask a located element in the output; this does not handle the consent UI
await page.screenshot({
  path: 'product-masked.png',
  mask: [page.getByRole('dialog', { name: 'Privacy choices' })]
});

Use the full-page or mask options only when they match the intended screenshot. The Page API reference documents screenshot options.

Capture a popup opened in a new tab

If the page action opens a new tab or window, wait for the popup before triggering that action, then use the returned page for waits and capture. The popup belongs to the opener’s browser context.

Rank #3
Samsung Galaxy A16 5G 128GB Cell Phone, Unlocked Android Smartphone, Large AMOLED Display, Durable Design, Super Fast Charging, Expandable Storage, US Version, 2025, Blue Black (Renewed)
  • Charger NOT Included, 6.7" Super AMOLED FHD+, 90Hz Refresh Rate, 385 ppi, 800 nits (HBM), 1080x2340px, 5000mAh Battery
  • 128GB, 4GB RAM, microSDXC, Exynos 1330 (5nm), Octa-Core, Mali-G68 MP2 or Mali-G57 MC2 GPU
  • Rear Camera: 50MP, f/1.8 (wide) + 5MP, f/2.2 (ultrawide) + 2MP, f/2.4 (macro), LED flash, panorama, HDR; Front Camera: 13MP, f/2.0, Android 14, up to 6 major Android upgrades, One UI 6.1
  • 3G: HSDPA 850/900/1700(AWS)/1900/2100; 4G LTE: 1/2/3/4/5/7/12/13/14/20/25/26/28/29/30/38/39/40/41/48/66/71, 5G: 2/5/25/41/66/71/77/78 SA/NSA/Sub6/mmWave - Nano-SIM + eSIM
  • US Model – Global Connectivity – Compatible with Most GSM Carriers like T-Mobile, AT&T, MetroPCS, etc. Will Also work with CDMA Carriers Such as Verizon, Straight Talk.
const popupPromise = page.waitForEvent('popup');
await page.getByRole('link', { name: 'Open product details' }).click();
const popup = await popupPromise;

await popup.waitForLoadState();
await popup.screenshot({ path: 'product-details.png' });

Troubleshoot common capture failures

  • The banner is still covering the product. Check whether it is a DOM overlay and whether the intended button was actually clicked. Use the site’s real locator, then verify the resulting state before capture.
  • The script cannot find the consent button. The label or markup may differ by site, locale, or session. Inspect the page and use the observed accessible name or a locator grounded in its DOM; do not assume a universal selector.
  • A click or navigation hangs after a dialog appears. If a dialog listener is registered, make sure it calls accept() or dismiss(). A listener that only logs leaves the dialog unresolved.
  • The notice disappears in a test that should show it. Do not click a consent control. Start with an isolated fresh context if prior browsing state may have persisted.
  • The page is captured before it is ready. Wait for the expected UI state with a locator assertion or wait condition that fits the page. Do not treat networkidle as a universal readiness signal.
  • The banner appears hidden in the image but remains on the page. A screenshot mask changes only the captured pixels. Remove the mask if the notice should be visible, or interact with the actual page control if the desired state is after a choice.

Or skip the browser setup

ScreenshotNeo can capture a URL with one request. It accepts cookie or consent banners as 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 are not billed, and responses identify the page verdict and billing status in headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf for AI agents.

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

cURL:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com/product -o shot.webp

Python:

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://example.com/product"}, timeout=90)
open("shot.webp", "wb").write(r.content)

Node.js:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://example.com/product' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

See the ScreenshotNeo API documentation for request options. ScreenshotNeo offers 1,000 screenshots per month free with no card; paid plans start at $5 for 3,000. Learn about ScreenshotNeo or sign up for the free plan.

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

Frequently Asked Questions

Does masking a consent popup count as dismissing it?

No. Masking covers the selected element in the screenshot output; it does not interact with the page or change its state.

Rank #4
Sale
Samsung Galaxy A17 5G Smart Phone 128GB, US 1 Yr Manufacturer Warranty Blue
  • YOUR CONTENT, SUPER SMOOTH: The ultra-clear 6.7" FHD+ Super AMOLED display of Galaxy A17 5G helps bring your content to life, whether you're scrolling through recipes or video chatting with loved ones.¹
  • LIVE FAST. CHARGE FASTER: Focus more on the moment and less on your battery percentage with Galaxy A17 5G. Super Fast Charging powers up your battery so you can get back to life sooner.²
  • MEMORIES MADE PICTURE PERFECT: Capture every angle in stunning clarity, from wide family photos to close-ups of friends, with the triple-lens camera on Galaxy A17 5G.
  • NEED MORE STORAGE? WE HAVE YOU COVERED: With an improved 2TB of expandable storage, Galaxy A17 5G makes it easy to keep cherished photos, videos and important files readily accessible whenever you need them.³
  • BUILT TO LAST: With an improved IP54 rating, Galaxy A17 5G is even more durable than before.⁴ It’s built to resist splashes and dust and comes with a stronger yet slimmer Gorilla Glass Victus front and Glass Fiber Reinforced Polymer back.

Will a new Playwright context always make a consent banner appear?

It isolates the run from prior browsing data, but the site’s own behavior and consent implementation determine what appears.

What if consent opens in a separate tab?

Wait for the page’s popup event before the action, then capture the returned popup page in the opener’s context.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Tracfone Motorola Moto G 2025, 64GB, Saphire Blue (Locked to
  • Carrier: This phone is locked to Tracfone, which means this device can only be used on the Tracfone wireless network. Tracfone plan required, activating is easy, just 3 steps.
  • DISPLAY: Immersive viewing on a 6.7-inch super-bright 120Hz display with powerful stereo speakers and Bass Boost for cinematic entertainment.
  • CAMERA SYSTEM: Advanced 50MP Quad Pixel camera captures sharp, detailed photos and videos in any lighting condition
  • PERFORMANCE: Lightning-fast 5G connectivity paired with a powerful processor and RAM Boost for smooth multitasking.
  • BATTERY LIFE: Long-lasting 5000mAh battery with TurboPower charging technology delivers hours of power in minutes.

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.