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

To remove a cookie banner from a Pyppeteer screenshot, handle it before calling page.screenshot(). The most reliable approach is to find and click the target site’s actual reject, decline, or dismiss control, then verify the banner is gone. If you only need a visually clean image, you can hide a known banner with page-side CSS or JavaScript—but that does not record consent and may leave the page blocked or unusable.

Pyppeteer provides the browser-side JavaScript and screenshot methods, but no built-in universal cookie-banner remover. Banner markup and consent controls vary by site, so selectors must be checked against the page you are capturing.

Choose the right way to handle the banner

First decide whether your task needs an actual choice in the site’s consent flow or only a clean-looking image.

  • For a browsing workflow: locate a visible reject, decline, or dismiss control and click it before capture. Choose the available option that matches the user’s intent; do not automatically accept consent just to clear the screen.
  • For a screenshot-only cleanup: hide a known banner with a narrow CSS selector or remove its element. This changes what is visible, not necessarily the site’s consent state.

Clicking the site’s control is usually preferable when you need the page to behave normally afterward. Hiding or removing an element can leave scroll locking, event handlers, or other overlay behavior in place. Neither a successful click nor a successful DOM change proves that the page is ready: inspect the resulting state before taking the screenshot.

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

Prepare Pyppeteer and navigate to the page

Pyppeteer is an unofficial Python port of Puppeteer’s headless-browser automation library. The project documentation and API reference describe Page.evaluate() for running JavaScript in the browser and Page.screenshot() for capturing the page. The API reference is for Pyppeteer 0.0.25, so check the method signatures and behavior for the version installed in your project.

Install Pyppeteer in the Python environment used by your script:

#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
python -m pip install pyppeteer

A basic asynchronous capture establishes the order of operations. Replace the URL with the page you control or are authorized to automate. The banner-specific handling goes after navigation and before the screenshot.

import asyncio
from pyppeteer import launch

async def main():
    browser = await launch(headless=True)
    page = await browser.newPage()
    await page.setViewport({"width": 1440, "height": 1000})
    await page.goto("https://example.com", {"waitUntil": "networkidle2"})

    # Handle and verify the banner here, before the screenshot.
    await page.screenshot({"path": "page.png", "fullPage": True})
    await browser.close()

asyncio.get_event_loop().run_until_complete(main())

The navigation condition is a choice, not a guarantee that every site has finished rendering. Pages that continue loading requests may not reach network idle as expected; for those pages, use an appropriate readiness check for the content you need and handle navigation timeouts explicitly.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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

Click a real consent control before capture

Use the selector for the actual control on the target page. The following example waits for a site-specific reject button, clicks it, and then checks whether the banner container remains visible. Replace both selectors with ones confirmed in that page’s markup.

import asyncio
from pyppeteer import launch

URL = "https://example.com"
REJECT_SELECTOR = "button#cookie-reject"  # Replace for the target site.
BANNER_SELECTOR = "#cookie-banner"        # Replace for the target site.

async def main():
    browser = await launch(headless=True)
    page = await browser.newPage()
    await page.setViewport({"width": 1440, "height": 1000})
    await page.goto(URL, {"waitUntil": "networkidle2", "timeout": 60000})

    reject = await page.waitForSelector(REJECT_SELECTOR, {"timeout": 10000})
    await reject.click()

    # Give the site's UI a moment to update, then verify the banner state.
    await page.waitFor(500)
    banner_visible = await page.evaluate("""(selector) => {
        const el = document.querySelector(selector);
        if (!el) return false;
        const style = getComputedStyle(el);
        const rect = el.getBoundingClientRect();
        return style.display !== 'none' &&
               style.visibility !== 'hidden' &&
               rect.width > 0 && rect.height > 0;
    }""", BANNER_SELECTOR)

    if banner_visible:
        raise RuntimeError("The cookie banner is still visible; inspect the page and selectors.")

    await page.screenshot({"path": "page.png", "fullPage": True})
    await browser.close()

asyncio.get_event_loop().run_until_complete(main())

The visibility check tests the selected element’s computed visibility and dimensions; it does not prove that every overlay is gone or that the underlying page is interactive. Review the screenshot and, if necessary, inspect the page for a backdrop, another banner element, or a blocked scroll state. A site may update its interface asynchronously, so replace the short wait with a wait for a site-specific condition when appropriate.

Find and validate the correct selector

Inspect the page in a browser’s developer tools or examine its DOM to identify the banner, its controls, and any surrounding backdrop. Confirm that the reject or dismiss selector matches the intended button—not an accept button or a similarly named control. Test the selector against the particular site and page state you automate.

There is no dependable universal selector. Consent interfaces can be rendered with different markup, inside iframes, or in shadow DOM. A normal document.querySelector() does not automatically search inside an iframe or a shadow root. Those cases require locating the relevant frame or traversing the page’s shadow DOM using a site-specific approach. Vendor-specific selector examples can become stale as implementations change; verify them against the live target page.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Hide a known banner for a visual-only screenshot

If consent state is irrelevant to your task and you only need the banner not to appear in the image, apply a narrowly scoped style to the known banner element before capture:

await page.evaluate("""() => {
    const banner = document.querySelector('#cookie-banner');
    if (banner) banner.style.setProperty('display', 'none', 'important');
}""");

await page.screenshot({"path": "page.png", "fullPage": True});

Replace #cookie-banner with a selector verified on the target page. Do not use a broad rule that hides every fixed or sticky element: it could also remove navigation, notices, or other content you intend to capture.

Removing a node is another visual-only option when you know the exact element:

await page.evaluate("""() => {
    const banner = document.querySelector('#cookie-banner');
    if (banner) banner.remove();
}""");

Hiding or removing the banner does not itself make a consent choice. The site may still have a backdrop, locked scrolling, event listeners, or a consent state that has not changed. If the page looks blank, remains covered, or cannot be interacted with, inspect the rest of the overlay behavior rather than assuming that removing one element completed the task.

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

Capture the intended page region

Once the page is in the desired state, capture it. Pyppeteer’s screenshot options include full-page capture and clipping a region. Use full-page capture when you need the whole document; use a clip when the output should show only a specific viewport region.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
# Full document
await page.screenshot({"path": "full-page.png", "fullPage": True})

# A fixed viewport region
await page.screenshot({
    "path": "region.png",
    "clip": {"x": 0, "y": 0, "width": 1200, "height": 800}
})

For a clip, make sure its coordinates and dimensions correspond to the page state and viewport you intend to capture. A banner outside the clipped area may not appear in the image, but that is not the same as dismissing it or changing consent state.

Troubleshoot failed banner removal

The selector times out or matches nothing

  • Cause: the selector is incorrect, the banner has not appeared yet, or the control is rendered in an iframe or shadow root.
  • Fix: inspect the target page after navigation, wait for the correct element, and determine whether it belongs to the main document, a frame, or a shadow root. Update the selector and verify that it identifies the intended control.

The click runs but the banner remains

  • Cause: the selector may target the wrong control, the site may update asynchronously, or another overlay element may remain.
  • Fix: check the button text and surrounding markup, wait for a site-specific post-click state, and inspect the visible page before capture. Do not treat a completed click call as proof that the UI changed.

The banner disappears but the page is still blocked

  • Cause: hiding or removing the banner element may leave a backdrop, scroll lock, or other behavior active.
  • Fix: inspect the page for the remaining overlay and determine whether the target site’s real consent control is a better fit. Avoid broad cleanup rules that conceal unrelated content.

Navigation never reaches the expected readiness state

  • Cause: some pages continue making requests, so a network-idle condition may not occur in the time allowed.
  • Fix: choose a readiness condition tied to the page content you need, set a suitable timeout, and handle navigation timeout errors. Verify that the banner and target content have actually loaded before capture.

The screenshot is clean but consent was not recorded

  • Cause: CSS hiding and DOM removal affect presentation, not necessarily the site’s consent flow.
  • Fix: if the workflow needs a consent decision, interact with the appropriate visible site control and verify the resulting page state. Do not describe a visual-only screenshot cleanup as consent.

Performance, reliability, and cost considerations

Banner handling adds a page-specific step to the navigation-and-capture workflow. Waiting for a selector can prevent capturing before the control is available; waiting too long on an incorrect selector adds delay or causes a timeout. Keep selectors narrow, use timeouts suited to the target page, and verify the result so failed dismissal does not silently produce a misleading image.

Reliability depends on the target site’s current implementation and page state. A selector that works for one site—or even one version of a site—is not evidence of a general solution. Consent tooling may use ordinary DOM, frames, or shadow DOM, and the relevant control can change. The cited guidance does not establish a universal solution, a Pyppeteer-specific banner-removal success rate, or a general runtime or cost figure.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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 is a website screenshot API and MCP server for developers. It can accept cookie and consent banners like a visitor and remove more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each cleanup step can be turned off. Only clean shots are billed: bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, with the response identifying the page verdict and billing status in headers. Its MCP server offers take_screenshot, get_page_info, and capture_pdf for AI agents and MCP clients.

For a one-request capture, use this cURL example with your API key and target URL. See the ScreenshotNeo documentation for API details.

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

The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots. Sign up for free to try it.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

Frequently Asked Questions

Does Pyppeteer have a built-in method to remove cookie banners?

No. It provides browser evaluation and screenshot methods, but banner handling must be implemented for the target page.

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

Does hiding a cookie banner record consent?

No. Hiding or removing an element is a visual change and does not itself establish the site’s consent state.

Can one cookie-banner selector work across all websites?

No universal selector is established; markup and rendering methods vary by site.

Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

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.