Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
FREEDOM251

Freedom251 › Blog › browser automation

How to Capture Product Screenshots on Pages With Consent Popups in Playwright

By Freedom251 Team · · 6 min read

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

First determine whether the “popup” is an HTML panel inside the page or a JavaScript browser dialog. Use Playwright locators for a consent banner, and capture it untouched if it should remain visible; click its actual control and verify the result if the screenshot should show the page after a choice. Handle JavaScript dialogs separately through Playwright’s dialog event. Then capture the intended state with page.screenshot().

Identify the popup and decide what the screenshot should show

A cookie or privacy banner is usually ordinary page content: an element in the page’s DOM that can cover or obscure other content. Inspect it and its controls, then decide the desired image before interacting:

  • Show the consent notice: wait until the panel is visible and take the screenshot without activating a choice button.
  • Show the page after a choice: locate the intended accept, reject, or preferences control, click it, verify the resulting page state, and capture afterward.

There is no universal consent-banner selector or button label. Markup and wording vary by site and may be localized. Prefer an accessible locator based on the observed role and name, such as getByRole('button', { name: 'Accept all' }), and adapt it to the page you are automating. Playwright’s Page documentation describes locators and page APIs.

In an automated test, clicking a control simulates interaction with the site; do not treat that action as a real person’s legal consent.

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

Capture the page with the consent panel visible

This Node.js example leaves the banner alone and captures it once it appears. Replace the URL and accessible name with those observed on the target page.

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');
    const consentButton = page.getByRole('button', { name: 'Accept all' });
    await consentButton.waitFor({ state: 'visible' });
    await page.screenshot({ path: 'product-with-consent.png' });
  } finally {
    await browser.close();
  }
})();

The button locator is used here only to establish that the panel is present; the script does not click it. If the panel has no suitable button, wait for an observed locator that identifies the panel itself instead.

As an Amazon Associate I earn from qualifying purchases.

Capture the page after a consent choice

When the intended image should show the page after a choice, click the site’s actual control and assert the expected result before capture. For example, if the banner disappears after acceptance:

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');
    const acceptButton = page.getByRole('button', { name: 'Accept all' });
    await acceptButton.waitFor({ state: 'visible' });
    await acceptButton.click();
    await acceptButton.waitFor({ state: 'hidden' });
    await page.screenshot({ path: 'product-after-consent.png' });
  } finally {
    await browser.close();
  }
})();

Change the final assertion if the site signals success in another way, such as displaying a confirmation or revealing a page element. An assertion tied to the expected UI state is more reliable than an arbitrary delay.

Handle JavaScript dialogs separately

A browser dialog created by JavaScript—alert, confirm, prompt, or a beforeunload prompt—is not an HTML consent panel. Playwright’s Dialogs documentation says dialogs are auto-dismissed by default when no dialog listener is installed.

#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.****

If the script needs to choose deliberately, register a handler before the action that triggers the dialog, and accept or dismiss it. A handler that only logs the message can leave the page action blocked.

page.on('dialog', async dialog => {
  if (dialog.type() === 'confirm') {
    await dialog.accept();
  } else {
    await dialog.dismiss();
  }
});

// Perform the action that triggers the dialog only after registering the handler.
await page.getByRole('button', { name: 'Continue' }).click();

Choose the response that fits the test. Do not install this handler as a substitute for locating and interacting with an HTML banner.

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

Choose a browser context that matches the session you need

A fresh, non-persistent browser context is useful when the screenshot should reproduce a first visit without preferences from an earlier run. Playwright documents these contexts as isolated from other contexts and as not writing browsing data to disk. A new page created inside the context starts with that context’s session state.

Rank #2
Sale
Samsung Galaxy A17 5G Smart Phone 128GB US 1 Yr Manufacturer Warranty Black | Large AMOLED, High-Res Camera, Durable Design, Super Fast Charging, Expandable Storage, Circle to Search, 2025
  • 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.

If the screenshot must reflect a previously saved preference, use the appropriate saved state instead of assuming every run should be fresh. The right strategy depends on the behavior being demonstrated; consent storage and persistence are site-specific. See the BrowserContext documentation.

If clicking a link or control opens a new tab or window, wait for the popup event before the action and capture the returned page. The new page belongs to the opener’s browser context.

Rank #3
Sale
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-popup.png' });

Match screenshot options to the intended image

After the page reaches the state you want to document, use page.screenshot(). For example, await page.screenshot({ path: 'product.png' }) captures the viewport by default. The Page API also documents options that change what appears in the output:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • fullPage: true captures the full scrollable page rather than only the viewport.
  • mask covers selected locators in the screenshot. Masking changes the image; it does not dismiss the banner, make a choice, or change the page state.

Use full-page capture or masking only when the intended deliverable calls for it. See the screenshot options and examples in the Playwright Page API.

Rank #4
Samsung Galaxy A17 5G Smart Phone 128GB, US 1 Yr Manufacturer Warranty Blue | Large AMOLED, High-Res Camera, Durable Design, Super Fast Charging, Expandable Storage, Circle to Search, 2025
  • 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.

Make the capture repeatable and diagnose failures

Wait for the expected UI, not all network activity

Use a locator assertion or wait that reflects the state you need—for example, the consent panel becoming visible or disappearing after a click. Playwright discourages networkidle as a testing readiness strategy; analytics and other background requests can make network activity a poor proxy for visual readiness.

Common problems and fixes

  • The banner is not found: the selector or accessible name may not match the site, or the panel may not have appeared. Inspect the rendered page and use its actual structure and text; account for localization and session state.
  • The screenshot still shows the banner after clicking: verify that the intended control was clicked and wait for the page’s actual post-choice state before capturing. A click completing does not by itself prove the UI changed as expected.
  • A click or navigation stalls after a dialog appears: if a dialog listener is installed, ensure it calls accept() or dismiss(). If no listener is installed, Playwright’s default is to dismiss dialogs automatically.
  • The screenshot hides the consent panel but the page still behaves as though it is present: a screenshot mask affects pixels only. Interact with the page control if the page state must change.
  • The banner appears in one run but not another: check whether the run reuses a context or stored state. Use a fresh isolated context when the target is a first-visit view, or set up the saved state needed for a returning-session view.
  • The screenshot is taken from the wrong tab: if the action opened a popup page, wait for the popup event and call screenshot() on that returned page.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

For a one-request screenshot without managing a Playwright browser, ScreenshotNeo is a website screenshot API and MCP server. Its API accepts a URL and can return an image or PDF. For a WebP screenshot of a product page, the cURL request is:

Best Value
Tracfone Motorola Moto G 2025, 64GB, Saphire Blue (Locked to | Prepaid Smartphone- 6.6" 120Hz Display, 5G , 50MP Quad Pixel Camera, Long-Lasting Battery
  • 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.
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 request parameters and response details. ScreenshotNeo accepts cookie or consent banners as a visitor and removes 60+ known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify the page verdict and billing status in headers. An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents and MCP clients. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots.

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

Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month with no card.

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.

browser automationconsent popupsPlaywrightscreenshotsWeb development

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.

Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

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.