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 DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk3 min

How to Hide a Cookie Banner in a Website Screenshot with CSS

Hide a cookie banner in a Playwright screenshot by passing a targeted CSS rule to the screenshot style option. The rule changes the image, not consent state.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

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

Find a selector that matches the actual banner

  1. Open the target page in the Playwright browser context.
  2. 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.
  3. Use that selector in the screenshot’s style string, followed by display: none !important;.
  4. 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.

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

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.

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

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

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.

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • 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 #2
Sale
HTML and CSS: Design and Build Websites
  • 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.

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