Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon 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 desk5 min

How to Capture a Screenshot Before a Cookie Banner Appears with Playwright

Capture early with Playwright's commit or domcontentloaded milestone, then verify the timing on the target site. Includes runnable code and troubleshooting.

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.

Navigate at an early milestone, then take the screenshot immediately: start with waitUntil: 'commit' for the earliest capture, or try domcontentloaded if you need the initial document parsed. Neither guarantees a banner-free image. Cookie banners can appear in the initial HTML or run quickly in site JavaScript, so check the target site and choose the earliest point that still produces the content you need.

Capture at an early navigation milestone

In Playwright, the key is to avoid waiting longer than the screenshot requires. The Page API defines commit as the point when the response has been received and the document has started loading. domcontentloaded waits for the document’s DOMContentLoaded event, allowing more of the initial page to be built but also giving a fast banner more time to appear.

Try the earliest checkpoint first. If the capture is too empty or incomplete, switch to domcontentloaded and compare the result on the site you care about.

Runnable JavaScript example

Install Playwright and its browser if needed with npm install playwright and npx playwright install chromium. Save this as an ES module file such as capture.mjs, then run node capture.mjs.

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

As an Amazon Associate I earn from qualifying purchases.

import { chromium } from 'playwright';

const browser = await chromium.launch();
try {
  const page = await browser.newPage();
  await page.goto('https://example.com', { waitUntil: 'commit' });
  await page.screenshot({ path: 'before-banner.png' });
} finally {
  await browser.close();
}

To let the initial document progress further, change 'commit' to 'domcontentloaded'. Take the screenshot directly after page.goto(); adding a delay or waiting for a later page condition widens the window in which the banner may appear.

Choose the checkpoint that preserves useful content

Checkpoint What it waits for Trade-off
commit The response is received and the document starts loading. Earliest option, but the screenshot may be mostly blank or only partly rendered.
domcontentloaded The document’s DOMContentLoaded event fires. More initial DOM may be available, but the banner has had longer to appear.
Specific readiness check A particular element or condition that your capture needs. Can make the image more useful, but every additional wait increases the chance that the banner appears first.

There is no universal delay that beats every consent banner. Its timing depends on how the site serves and runs its consent interface. Inspect the screenshots from the actual target rather than assuming one milestone always wins.

Run page-side setup before site scripts when needed

If you have a clear, site-specific reason to prepare the page before its JavaScript runs, register an init script before navigation. Playwright evaluates page.addInitScript() after document creation but before the page’s scripts. The hook is a timing mechanism, not an automatic cookie-banner remover; any code that changes page behavior must be tailored to the site and verified.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import { chromium } from 'playwright';

const browser = await chromium.launch();
try {
  const page = await browser.newPage();
  await page.addInitScript(() => {
    // Add tested, site-specific setup here only when needed.
  });
  await page.goto('https://example.com', { waitUntil: 'commit' });
  await page.screenshot({ path: 'before-banner.png' });
} finally {
  await browser.close();
}

For setup shared across pages, browserContext.addInitScript() applies to pages and relevant child-frame attachments or navigations in that context. The BrowserContext API cautions that the order of multiple context-level and page-level init scripts is undefined. Do not make your logic depend on which of those scripts runs first.

Wait only for content the screenshot needs

If commit captures too early, a targeted readiness check can help ensure a useful element exists before capture. Keep that check as narrow as possible: the longer the page runs before the screenshot, the more opportunity a consent banner has to appear. A selector that appears only after substantial client-side work may be a poor fit for a before-banner capture.

The screenshot API also has a style option that applies CSS during capture. It can hide or alter elements in the resulting image, but it does not prevent consent code from loading and does not establish what a visitor would otherwise see. Use it only when a modified capture is actually what you intend to produce.

#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

Avoid waiting for network idle by default

Playwright’s Page API labels networkidle “DISCOURAGED” for testing and recommends using web assertions to assess readiness instead. It defines network idle as no network connections for at least 500 ms. That pause is often counterproductive when the goal is to capture before delayed UI appears. Prefer an early navigation milestone or a specific, necessary readiness check.

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

Troubleshoot timing and capture problems

  • The image is blank or incomplete: commit may be earlier than the target’s useful render point. Try domcontentloaded or wait for one specific piece of required content, then inspect whether the banner has begun appearing.
  • The banner is already visible: It may be present in the initial HTML or run before your chosen capture point. Try commit, remove unnecessary waits, and test both milestones on the target. Playwright does not promise a banner-free result.
  • An init script does not suppress the banner: Init scripts run before page scripts, but do not disable consent interfaces by themselves. Use only tested site-specific setup, and do not treat the hook as a universal suppression feature.
  • A capture using networkidle takes too long or includes the banner: Replace that wait with commit, domcontentloaded, or a narrowly scoped readiness check. Network idle waits for a quiet network interval, not for a banner-free state.
  • CSS makes the image look right but changes what it represents: The screenshot style option changes the captured presentation. If you need to document what a visitor sees, do not confuse hidden elements in the image with prevented page behavior.
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 with one GET request, without setting up a Playwright browser. The API accepts a URL and can return PNG, JPEG, WebP, or PDF. Its cleanup accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each cleanup step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. ScreenshotNeo also provides an MCP server with screenshot tools for AI agents.

For example, using cURL:

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

See the ScreenshotNeo API documentation for options and response details. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. Sign up for the free plan.

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

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

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.