In Playwright, hide a cookie banner in the screenshot by injecting a CSS rule with the screenshot API’s style option. Use a selector that matches the banner on the page you are capturing:
await page.screenshot({
path: 'page.png',
style: '.cookie-banner { display: none !important; }'
});
Replace .cookie-banner with the real selector for that site. This changes what appears in the image; it does not accept, reject, or record the visitor’s consent.
Hide the banner with Playwright’s screenshot-time CSS
Playwright’s page.screenshot() accepts a style string containing CSS to apply while the screenshot is taken. The API documents this option as available from Playwright v1.41. See the Page API screenshot options.
await page.screenshot({
path: 'page.png',
style: '#actual-consent-banner { display: none !important; }'
});
The selector is illustrative: there is no universal cookie-banner selector. Inspect the target page and use a selector that identifies its banner without hiding unrelated content.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallOutdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchFind a selector that matches the actual banner
- Open the target page in the Playwright browser context.
- Inspect the banner in the page’s DOM and identify a suitably specific CSS selector, such as an ID or class used by that banner.
- Use that selector in the screenshot’s
stylestring, followed bydisplay: none !important;. - Capture the image and inspect it to confirm the banner is gone and the intended page content remains visible.
Playwright locators support CSS selectors; its locator documentation shows selectors such as button in use. The selector still needs to fit the specific site. See Playwright locators.
As an Amazon Associate I earn from qualifying purchases.
Capture a viewport or the full page
Hiding the banner and choosing how much of the page to capture are separate settings. For the viewport, omit fullPage. To capture the full scrollable page, set fullPage: true:
await page.screenshot({
path: 'page-without-banner.png',
fullPage: true,
style: '#actual-consent-banner { display: none !important; }'
});
Playwright documents fullPage as capturing the full scrollable page. See Playwright screenshots.
Choose CSS hiding or a mask based on the result you need
- Use screenshot-time CSS when the goal is to make the banner invisible in the image so the content underneath can show.
- Use a mask when the goal is to cover an element with a solid-color overlay, for example in a screenshot comparison. A mask covers the element’s bounding box rather than revealing what is behind it. See the Page API screenshot options.
- Use a separate consent-flow test when you need to verify that a user’s preference is accepted, rejected, or saved. Screenshot styling alone does not demonstrate that any consent state changed.
Troubleshoot a banner that still appears
The selector does not match
Check the target page’s DOM and confirm the selector identifies the visible banner. A made-up or generic selector will not reliably match every site.
The rule hides the wrong element
Make the selector more specific to the banner, then inspect the resulting screenshot to ensure page content was not also hidden.
You expected the consent choice to persist
The style option is for screenshot rendering. It is not a consent interaction and does not establish that a preference was stored. Test the intended consent control and resulting state separately.
#1 Best Overall
Or skip the browser setup
ScreenshotNeo can return a website screenshot from one GET request. Its clean-shot steps accept the cookie or consent banner like a visitor and remove more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks, blank pages, and failed loads are not billed, and response headers report the page verdict and billing status. It also provides an MCP server for AI agents, with tools including take_screenshot, get_page_info, and capture_pdf.
Recommended Free Tools
For a WebP screenshot, save the response body from this request:
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 options. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. Sign up for ScreenshotNeo and get 1,000 free screenshots a month, with no card.
Quick Recap
Best Value
Rank #4
- Brand: Wiley
- Set of 2 Volumes
- A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
Rank #3
Rank #2
- HTML CSS Design and Build Web Sites
- Comes with secure packaging
- It can be a gift option
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.




