For a normal cookie banner or modal, navigate to the page, click its actual consent control, verify the prompt is gone, and then call page.screenshot(). If you need a repeatable state without exercising the banner, use a fresh browser context and set the site’s verified consent cookie before navigation. A JavaScript alert, confirm, prompt, or beforeunload dialog is different: handle it with Playwright’s dialog event.
Dismiss an ordinary cookie banner before capture
Most cookie-consent prompts are regular page elements, not browser dialogs. Find the site’s real button or other control and interact with it before taking the screenshot. The button name below is only an example; inspect the target page and choose the intended action, such as accepting, rejecting, or opening preferences.
const context = await browser.newContext();
const page = await context.newPage();
await page.goto('https://example.com');
const acceptButton = page.getByRole('button', {
name: /accept all cookies/i,
});
if (await acceptButton.isVisible().catch(() => false)) {
await acceptButton.click();
}
// Verify the site's actual consent prompt is gone before capture.
await page.screenshot({ path: 'page.png' });
Playwright’s screenshot guide documents page.screenshot(). A screenshot records the page’s current state, so make the intended consent choice and verify the resulting UI before capture. If the prompt can appear late, wait for its relevant state rather than relying on a fixed sleep.
As an Amazon Associate I earn from qualifying purchases.
Verify the correct result
Do not assume that any control labeled “Accept” is appropriate for every task. If the test is meant to represent rejection or custom preferences, interact with that control instead. Verification should match the site’s actual banner or dialog; a locator that merely stops being visible may not prove that a consent choice was stored.
Use a known consent state for repeatable screenshots
When the site’s consent state is understood and stored in a cookie, add the correct cookie to a clean context before navigating. Browser contexts isolate cookies and other storage, making them useful for repeatable runs. The cookie name, value, domain or URL, path, expiry, and other attributes depend on the site; Playwright does not define a universal consent cookie.
const context = await browser.newContext();
await context.addCookies([
{
name: 'SITE_SPECIFIC_CONSENT_COOKIE',
value: 'SITE_SPECIFIC_VALUE',
url: 'https://example.com',
},
]);
const page = await context.newPage();
await page.goto('https://example.com');
await page.screenshot({ path: 'page.png' });
Replace the example cookie name and value with the ones the target site actually expects. See Playwright’s BrowserContext API for cookie insertion and context initialization, and its browser-context guide for isolation. For storage beyond cookies, Playwright’s authentication guidance covers storage-state workflows; the site’s specific state format still needs to be established.
#1 Best Overall
- 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
Use an initialization script only when you know the site’s storage format
context.addInitScript() runs after a document is created but before page scripts execute, and applies to pages and newly attached or navigated frames in that context. It can set site-specific local storage early, but it does not identify or dismiss cookie banners automatically. You need the correct storage key and value. If multiple context and page initialization scripts are registered, their execution order is not defined. See the BrowserContext API.
Recommended Free Tools
Choose between clicking and preloading state
- Test the user consent flow: click the real control, then verify the intended outcome before capturing.
- Establish a known state for downstream screenshots: use a fresh context and preload verified site-specific state.
- Only remove the prompt from the image: use screenshot styling to hide or alter elements, but treat that as a visual adjustment—not a recorded consent choice.
Handle JavaScript dialogs separately
Playwright’s dialog API handles JavaScript alert, confirm, prompt, and beforeunload dialogs. These are not HTML cookie banners. Without a registered handler, Playwright automatically dismisses JavaScript dialogs. If you register a handler, it must accept or dismiss the dialog; otherwise the page can remain blocked and actions may stall.
page.on('dialog', async dialog => {
await dialog.dismiss();
});
Use dialog.accept() instead when the test requires acceptance. See Playwright’s dialog guide and Dialog API. This event handler does not remove an ordinary consent banner rendered in page markup.
Or skip the browser setup
ScreenshotNeo is a website screenshot API and MCP server for developers. Its API can return an image or PDF from a URL in one request. 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 request options. ScreenshotNeo accepts cookie or consent banners like a visitor 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 cost nothing, and responses identify the page verdict and billing status in headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsSign up for ScreenshotNeo’s free plan: 1,000 screenshots a month, no card required.
Rank #2
- 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
Troubleshoot consent prompts in screenshots
- The banner returns on every run: each fresh context has isolated cookies and storage. Establish the desired state each run, either by clicking the control or seeding verified site state.
- Adding a cookie changes nothing: check that its domain or URL, path, expiry, and other attributes match the site, and confirm that the site uses that cookie to represent consent.
- The site stores consent outside cookies: inspect its behavior and use the relevant storage-state workflow or a site-specific initialization script. The required key and value are not universal.
- The prompt appears after navigation or just before capture: wait for the relevant UI state and verify it is hidden or removed before taking the screenshot; a fixed delay is less robust than checking the page.
- The prompt disappears only from the screenshot: screenshot styling can hide elements, including elements in shadow DOM and inner frames, but does not establish that consent was accepted or persisted. See the Page API.
- Page actions stall after registering a dialog handler: make sure the handler calls
dialog.accept()ordialog.dismiss()for each dialog.
Frequently Asked Questions
Does Playwright have a built-in command to dismiss every cookie banner?
No universal consent action exists: banner markup, controls, and stored consent state are site-specific. Locate the correct control or set the site’s verified state.
Will hiding a banner with screenshot CSS save the consent choice?
No. It changes what appears in the image, not the site’s consent state.
Quick Recap
Best Value
- 【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
- 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
- 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.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →




