npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

playwright-autoconsent

v1.0.4

Published

Easy integration of @duckduckgo/autoconsent with Playwright for automated cookie consent handling

Readme

playwright-autoconsent

Easy integration of @duckduckgo/autoconsent with Playwright for automated cookie consent handling in your tests.

Automatically detects and handles cookie consent popups from 100+ providers including Google, Cookiebot, OneTrust, Quantcast, and many more.

Features

  • 🚀 Simple API - One line of code to handle cookie consent
  • 🌍 Multi-language support - Works across all languages
  • 🎯 100+ CMPs supported - Covers most major consent management platforms
  • 🔧 Flexible - Opt-in, opt-out, or just detect
  • 📦 Lightweight - Thin wrapper around battle-tested @duckduckgo/autoconsent
  • 💪 TypeScript support - Full type definitions included

Installation

npm install playwright-autoconsent @duckduckgo/autoconsent playwright

Or with playwright-core (lighter):

npm install playwright-autoconsent @duckduckgo/autoconsent playwright-core

Note: Both @duckduckgo/autoconsent and playwright (or playwright-core) are peer dependencies and must be installed.

Quick Start

import { chromium } from 'playwright';
import { handleCookieConsent } from 'playwright-autoconsent';

const browser = await chromium.launch();
const page = await browser.newPage();

await page.goto('https://example.com');

// Automatically detect and reject all cookies
const result = await handleCookieConsent(page);

console.log('Consent handled:', result.handled);
console.log('CMP detected:', result.cmp);
console.log('Success:', result.success);

await browser.close();

API

handleCookieConsent(page, options)

Handle cookie consent on an already-loaded page.

Parameters:

  • page - Playwright Page object
  • options - Configuration object
    • action - 'optIn' | 'optOut' | null (default: 'optOut')
    • timeout - Timeout in ms (default: 5000)
    • enableCosmeticRules - Hide popups with CSS (default: true)
    • debug - Enable logging (default: false)

Returns: Promise<ConsentResult>

const result = await handleCookieConsent(page, {
  action: 'optOut',  // Reject all cookies
  timeout: 5000,
  debug: true
});

navigateAndHandleConsent(page, url, options)

Navigate to a URL and handle consent in one call.

import { navigateAndHandleConsent } from 'playwright-autoconsent';

const result = await navigateAndHandleConsent(
  page,
  'https://example.com',
  { action: 'optOut' }
);

initAutoconsent(page, options)

Initialize autoconsent on a page (useful for SPAs).

import { initAutoconsent } from 'playwright-autoconsent';

// After page interaction
await page.click('#load-more');
const result = await initAutoconsent(page);

Examples

Accept All Cookies

await handleCookieConsent(page, { action: 'optIn' });

Just Detect (Don't Click Anything)

const result = await handleCookieConsent(page, { action: null });
if (result.handled) {
  console.log(`Found ${result.cmp} consent popup`);
}

With Remote Playwright

Works perfectly with remote Playwright instances:

import { chromium } from 'playwright';
import { navigateAndHandleConsent } from 'playwright-autoconsent';

const browser = await chromium.connect('ws://remote-playwright:9080');
const page = await browser.newPage();

await navigateAndHandleConsent(page, 'https://example.com');

Debug Mode

const result = await handleCookieConsent(page, {
  debug: true  // Logs all autoconsent messages
});

Supported CMPs

This library supports 100+ Consent Management Platforms including:

  • Google
  • Cookiebot
  • OneTrust
  • Quantcast
  • TrustArc
  • Evidon
  • Osano
  • CookieYes
  • Termly
  • And many more...

Full list: https://github.com/duckduckgo/autoconsent/tree/main/rules

How It Works

  1. Injects @duckduckgo/autoconsent into the page
  2. Detects which CMP (if any) is present
  3. Automatically clicks the appropriate buttons based on your action
  4. Returns the result

TypeScript

Full TypeScript support included:

import { Page } from 'playwright';
import { handleCookieConsent, ConsentResult } from 'playwright-autoconsent';

const result: ConsentResult = await handleCookieConsent(page, {
  action: 'optOut',
  timeout: 5000
});

Limitations

  • Cannot bypass CAPTCHAs - If a site shows a CAPTCHA, autoconsent won't help
  • Requires JavaScript - Won't work if JavaScript is disabled
  • Best effort - Some custom CMPs might not be detected

Related Projects

License

MIT

Contributing

Issues and PRs welcome! This is a thin wrapper around @duckduckgo/autoconsent.

For CMP detection issues or new CMP support, please contribute to the upstream project: https://github.com/duckduckgo/autoconsent

Credits

Built on top of the excellent @duckduckgo/autoconsent library by DuckDuckGo.