October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

How to Hide Cookie Banners and Popups in Playwright Screenshots

Use capture-time CSS to omit a cookie banner from a Playwright screenshot without changing consent state. Learn when to dismiss popups, use masks, or handle frames.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a one-off clean image, pass a narrow CSS rule in Playwright’s page.screenshot({ style }) option. That hides the selected element only while the screenshot is captured; it does not accept cookies or save a consent choice. If you are testing consent, use the site’s real controls and assert the result instead.

Hide an overlay in one screenshot

Use the screenshot-time style option to inject CSS without changing the page’s lasting state. Replace the example selectors with ones that match the site you are capturing:

As an Amazon Associate I earn from qualifying purchases.

await page.goto(url);
await page.screenshot({
  path: 'page.png',
  style: `
    #cookie-banner,
    [data-testid="cookie-banner"] {
      display: none !important;
    }
  `,
});

The selectors above are examples, not universal cookie-banner selectors. Inspect the page DOM and choose a specific selector for the element you want to omit. A broad rule can hide legitimate page content. Check the resulting image, too: removing a fixed or sticky overlay may reveal content underneath or leave a site-specific gap.

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

Choose the method that matches your test

Goal Use What it does
Omit a known overlay from a visual capture page.screenshot({ style }) Applies CSS during screenshot capture. It is suited to a visual-only change that should not persist on the page.
Conceal sensitive content or cover an element Screenshot mask with a locator Covers the matched element’s bounding box with a colored rectangle. The result is a visible block, not a naturally clean background.
Test consent behavior Click the site’s accept, reject, or settings control, then assert the resulting UI or state Exercises the site’s consent flow; hiding the banner with CSS does not operate its controls.
Dismiss an expected popup before an action Wait for it and dismiss it in the normal test flow Handles a known overlay explicitly before continuing.
Recover from an unexpected overlay that blocks an action page.addLocatorHandler() Runs when Playwright detects the overlay during a relevant actionability or auto-waiting assertion check; it is not a general background monitor.

Use the screenshot options carefully

Capture-time CSS versus a persistent style tag

page.screenshot({ style }) accepts stylesheet text for the capture. Playwright documents it as useful for dynamic elements and repeatable screenshots; the style pierces Shadow DOM and applies to inner frames. For a single image, this avoids leaving a style change on the page. page.addStyleTag({ content }) adds a style tag to the page and is an alternative when the styling needs to remain present beyond that screenshot. See the Playwright Page API.

Masking is not removal

Use the screenshot mask option when covering an element is the goal—for example, to obscure a value. Playwright paints the matched element’s bounding box with a mask color, so the masked area can stand out. If the image should look as though a banner were absent, targeted screenshot-time CSS is a better fit. Screenshot assertions also support masks and style text or paths; those assertions work only with the Playwright test runner. See the PageAssertions API.

Keep motion separate from overlay removal

The screenshot animations option can disable animations and help stabilize moving content, but it does not remove cookie banners or popups. Its behavior differs for finite and infinite animations, so consult the Page API for the installed version.

Dismiss predictable popups in the test flow

If a known popup blocks a click or other interaction, wait for it and dismiss it explicitly where it appears in the test. Playwright’s documentation says: “When an overlay is shown predictably, we recommend explicitly waiting for it in your test and dismissing it as a part of your normal test flow, instead of using page.addLocatorHandler().” Reserve a locator handler for overlays that are genuinely unexpected. A handler is invoked around actions or assertions that run actionability or auto-wait checks; it will not run just because an overlay appears while the test is idle. See the Page API overlay-handler guidance.

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 | 1920×1080 LED Monitor, 4ms GtG, Adaptive Sync, HDMI 1.4, Tilt Adjust, Low Blue Light, 4yr Advance Replacement Warranty
  • 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

Target the correct element, including inside frames

Prefer a stable site-owned attribute or a meaningful accessible locator when interacting with a control. Locators resolve to elements when used, and the correct target depends on the site’s DOM; there is no Playwright-wide selector that identifies every consent banner. See the Playwright locators documentation.

If the overlay belongs to an iframe, a selector in the top-level document cannot target that separate frame’s document. Use a frame locator for frame-scoped interaction. Playwright documents screenshot styles as applying to inner frames as well, but the correct frame and element still depend on the page. Verify the captured image rather than assuming the rule matched the intended content.

Troubleshoot a banner that remains or leaves a gap

  • The CSS rule has no effect: Inspect the DOM and confirm the selector matches the banner itself. The example IDs and attributes are placeholders; the Playwright API supplies the styling mechanism, not selectors for each consent platform.
  • The banner is inside an iframe: Identify the frame and target its content with frame-scoped locators for interactions. Check the screenshot to confirm the capture-time style has the intended effect in that frame.
  • Hiding it exposes a blank or awkward area: The site may reserve space or shift its layout around the overlay. Inspect the image and adjust only the site-specific layout rule needed; do not broaden the selector until it hides unrelated content.
  • The banner returns after reload: Screenshot-time CSS is temporary and does not save consent. Use the site’s actual controls and test the resulting state if persistence is what matters.
  • A locator handler does not fire: It is not an always-on observer. It runs in connection with a relevant actionability or auto-waiting assertion check.
  • The masked area is conspicuous: That is expected: a mask covers the element with a colored rectangle. Use capture-time CSS if the element should be absent from the visual output.
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 can return a screenshot or PDF from one request, without setting up a Playwright browser for the capture. Its clean-shot steps accept cookie and consent banners and remove more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and responses identify the page verdict and billing status in headers. ScreenshotNeo also offers an MCP server for AI agents, with tools including take_screenshot, get_page_info, and capture_pdf.

Install Python’s requests package, set your API key, and run this example (change the target URL as needed):

Free tools Windows power users keep installed

One-click scans. No signup required.

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
import requests

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

See the ScreenshotNeo API documentation for setup and request options. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Sign up for free ScreenshotNeo access.

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.
Rank #4
Sale
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor | 100Hz, Game Mode, Advanced Eye Comfort, HDMI and D-sub Ports (LS27D366GANXZA)
  • 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
Rank #3
Sale
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.

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 *

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
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair 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.