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

@scthakuri/adblock-detector

v1.0.10

Published

Lightweight, dependency-free adblock detector for React. Detects most adblock extensions and ships a ready-made modal, a React hook, and a zero-config auto-detecting component.

Readme

@scthakuri/adblock-detector

Lightweight, dependency-free adblock detector for React. Detects most adblock extensions (uBlock Origin, AdBlock Plus, AdGuard, Brave's built-in blocker, and more) and gives you a ready-made, customizable modal to prompt visitors to disable them.

NPM NPM Downloads TypeScript Known Vulnerabilities License: MIT

Demo

Live demo: try it yourself

Open the demo, enable an adblock extension in your browser, then reload the page. The detector modal appears live.

Features

  • Zero runtime dependencies. No crypto-js, no polyfills, nothing else installed alongside React.
  • ✅ Detects most popular adblock extensions (see Tested With)
  • ✅ Ships a ready-made, themeable modal component, or use the raw detection function and build your own UI
  • ✅ Fully typed (.d.ts included, no @types package needed)
  • ✅ Small footprint. No bundled crypto library; class-name obfuscation uses a tiny inline hash instead.

Installation

# npm
npm i @scthakuri/adblock-detector

# yarn
yarn add @scthakuri/adblock-detector

# pnpm
pnpm add @scthakuri/adblock-detector

Requires React ≥16.8 (uses hooks internally).

Quick Start

Simplest usage, detects and shows the modal automatically:

import { AutoDetectorModal } from '@scthakuri/adblock-detector';

function App() {
  return (
    <div className="App">
      <AutoDetectorModal closeBtn />
    </div>
  );
}

export default App;

If you need to control visibility yourself (custom trigger logic, analytics on detection, etc.), use the hook and DetectorModal directly:

import { useState } from 'react';
import DetectorModal, { useAdblockDetector } from '@scthakuri/adblock-detector';

function App() {
  const { detected } = useAdblockDetector();
  const [dismissed, setDismissed] = useState(false);

  return (
    <div className="App">
      {detected && !dismissed && (
        <DetectorModal
          closeBtn
          onModalClose={() => setDismissed(true)}
        />
      )}
    </div>
  );
}

export default App;

API Reference

<AutoDetectorModal />

Combines useAdblockDetector and DetectorModal into one drop-in component: detects on mount, renders nothing while loading or when no adblocker is found, and shows the modal automatically otherwise. Dismissing it (via closeBtn) hides it for the rest of the session. Accepts the same props as DetectorModal below, minus needing onModalClose (it's handled internally, though you can still pass one for a side effect on close).

<AutoDetectorModal closeBtn theme="#4f46e5" />

useAdblockDetector()

React hook: the recommended way to consume detection state. Runs the check once on mount and is unmount-safe (won't call setState after the component using it is gone).

| Returns | Type | Description | |---|---|---| | detected | boolean | Whether an adblocker was detected. | | loading | boolean | true until the check resolves. |

const { detected, loading } = useAdblockDetector();

detectAdblock(callback)

Imperative version of the same check, for use outside React (vanilla JS, class components, one-off checks). useAdblockDetector is built on top of this.

| Param | Type | Description | |---|---|---| | callback | (detected: boolean) => void | Called once with the detection result. |

import { detectAdblock } from '@scthakuri/adblock-detector';

detectAdblock((detected) => {
  if (detected) {
    // an adblocker is active
  }
});

detectByGoogleAd(callback)

Lower-level probe used internally by detectAdblock. Checks connectivity, requests a real Google Ads script, and inspects both the network response and whether the global it sets survives. Exported in case you want to compose your own detection flow (e.g. skip the fair-adblock check, or add your own probes alongside it).

| Param | Type | Description | |---|---|---| | callback | (detected: boolean) => void | Called once with the detection result. |

DetectAdblock / DetectByGoogleAd (PascalCase) remain exported as deprecated aliases for existing code. New code should use the camelCase names above.

<DetectorModal />

Pre-built modal shown when an adblocker is detected. The component always renders its markup, so mount/unmount it based on your own detection state (see Quick Start above).

| Prop | Type | Default | Description | |---|---|---|---| | theme | string | "#ff0000" | Any valid CSS color. Accents the icon, border, and footer. | | title | string | "Adblock Detected!!!" | Modal heading. | | message | string | (default message) | Modal body text. | | reloadBtnText | string | "I've Disable Adblock" | Text for the reload button. | | closeBtn | boolean | false | Show a close (×) button. | | onModalClose | () => void | () => {} | Called when the close button is clicked. The modal does not unmount itself; call this to update your own state. |

<DetectorModal
  theme="#4f46e5"
  title="Please disable your ad blocker"
  message="This site is supported by ads. Please whitelist us to continue."
  reloadBtnText="Refresh page"
  closeBtn
  onModalClose={() => setDismissed(true)}
/>

Tested With

  • ☞ Adblock Plus
  • ☞ Adblock
  • ☞ Adguard
  • ☞ Adremover
  • ☞ Adblock for Chrome™
  • ☞ Brave
  • ☞ Ghostery
  • ☞ uBlocker
  • ☞ uBlock
  • ☞ Ultrablock
  • ☞ Privacy Badger
  • ☞ DuckDuckGo
  • ☞ Disconnect
  • ☞ Microsoft Edge AdBlock extension
  • ☞ Firefox Tracking Protection
  • ☞ uBlock Origin
  • ☞ Fair AdBlocker
  • ☞ Hola ad remover
  • ☞ Comodo AdBlocker
  • ☞ Opera Built-in AdBlock extension

Local Development

git clone https://github.com/scthakuri/react-adblock-detector.git
cd react-adblock-detector
npm install       # also runs the build via the `prepare` script
npm run build      # compile src/ -> lib/

Type-check without emitting:

npx tsc --noEmit

Contributing

Issues and PRs welcome at github.com/scthakuri/react-adblock-detector.

License

MIT © Suresh Chand