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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@pvitor/adblock-detector

v1.0.0

Published

adblock detectector

Readme

Multi Adblock Detector

This project is a fork of multi-adblock-detect, modified for compatibility with older React versions (^16) with changes to Promise returns and improvements to adblock detection techniques.

🚀 Features

  • React 16+ compatibility - Works with legacy React projects
  • Promise-based API - Modern async/await support with consistent Promise returns
  • Multiple detection methods - 6 different adblock detection techniques
  • Improved reliability - Enhanced timeout handling and better error management
  • TypeScript support - Full TypeScript definitions included

📦 Installation

npm install @pvitor/adblock-detector

🔧 Usage

import {
    detectAdBlockFetchOrXhrAdsByGoogle,
    detectAdBlockFetchDoubleClick,
    detectAdBlockScriptAdsByGoogle,
    detectAdBlockBaitElementOrXhrGoogle,
    detectAdBlockScriptAdsJs,
    detectAdBlockScriptSailthruJs
} from "@pvitor/adblock-detector";

 async function detectMultiAdBlockMethods() {

  try {

    const [
      HasDetectAdBlockFetchOrXhrAdsByGoogle,
      HasDetectAdBlockFetchDoubleClick,
      HasDetectAdBlockScriptAdsByGoogle,
      HasDetectAdBlockBaitElementOrXhrGoogle,
      HasDetectAdBlockScriptAdsJs,
      HasDetectAdBlockScriptSailthruJs
    ] = await Promise.all([
      detectAdBlockFetchOrXhrAdsByGoogle('/pagead/js/adsbygoogle.js'),
      detectAdBlockFetchDoubleClick(),
      detectAdBlockScriptAdsByGoogle(),
      detectAdBlockBaitElementOrXhrGoogle('/ads/pagead2.googlesyndication.com'),
      detectAdBlockScriptAdsJs('/util/ads/ads.js'),
      detectAdBlockScriptSailthruJs('/ads/sailthru.js')
    ])

    return {
      HasDetectAdBlockFetchOrXhrAdsByGoogle,
      HasDetectAdBlockFetchDoubleClick,
      HasDetectAdBlockScriptAdsByGoogle,
      HasDetectAdBlockBaitElementOrXhrGoogle,
      HasDetectAdBlockScriptAdsJs,
      HasDetectAdBlockScriptSailthruJs
    };
      
    } catch(err) {}
 }

🛠️ Required Support Files

Some detection methods require support files on your server to function properly.

detectAdBlockFetchOrXhrAdsByGoogle

Create the file /pagead/js/adsbygoogle.js on your server.

detectAdBlockBaitElementOrXhrGoogle

Create the file /ads/pagead2.googlesyndication.com and pass the path as a parameter to detectAdBlockBaitElementOrXhrGoogle().

File content (no leading or trailing spaces, just the text):

thistextshouldbethere

⚠️ Important: Files like pagead2.googlesyndication.com need to be properly configured to be accessible on your server. Test by opening the file in your browser to validate.

detectAdBlockScriptAdsJs

Create the file /util/ads/ads.js and pass the path as a parameter to detectAdBlockScriptAdsJs().

File content:

// used by useDetectAdBlockScriptAdsJs.tsx to determine if ad blocker is present
var e = document.createElement('div');
e.id = 'detectAdBlocker';
e.style.display = 'none';
document.body.appendChild(e);

detectAdBlockScriptSailthruJs

Create the file /ads/sailthru.js and pass the path as a parameter to detectAdBlockScriptSailthruJs().

File content:

var e = document.createElement('div');
e.id = 'ybVg4vsBhs';
e.style.display = 'none';
document.body.appendChild(e);

📊 Comparison with Original Library

Key Improvements

| Feature | @pvitor/adblock-detector | multi-adblock-detect | Notes | |---------|---------------------------|------------------------|-------| | React Compatibility | React ^16.6.0 | React ^18.2.0 | Better compatibility with legacy projects | | API Design | Promise-based, no callbacks | Callback-based | More modern and consistent API | | Timeout Handling | Smart timeouts with guaranteed responses | No timeout in some methods | Prevents hanging promises | | Error Handling | Comprehensive error management | Limited error handling | Better reliability | | Bundle Format | CommonJS (Node.js compatible) | ES Modules | Better compatibility with older build tools |

Detection Method Improvements

| Method | Improvements | |--------|-------------| | detectAdBlockFetchDoubleClick | ✅ 1-second timeout, ✅ Promise-based, ✅ Prevents multiple resolutions | | detectAdBlockFetchOrXhrAdsByGoogle | ✅ Flexible URL parameter, ✅ Guaranteed response, ✅ Definitive true/false state | | detectAdBlockScriptAdsByGoogle | ✅ Script cleanup after loading, ✅ Explicit success/failure states | | detectAdBlockScriptAdsJs | ✅ Proper useEffect implementation, ✅ Modern API with timeout | | detectAdBlockScriptSailthruJs | ✅ URL parameter support, ✅ Modern Promise-based API |

⚠️ Known Limitations

  • uBlock Origin and Brave Shield are not currently detected
  • Support for these blockers will be added in future versions

📄 License

This code is derived from several sources. All original code is licensed under the Apache License, Version 2.0. See full text at: https://github.com/arjun-menon/multi-adblock-detect/blob/master/LICENSE.md

Attribution

The detection algorithms are derived from multiple sources:

  • detectAdBlockBaitElementOrXhrGoogle: just-detect-adblock (no license information)
  • detectAdBlockFetchDoubleClick: adblock-detect-react (no license information)
  • Three algorithms from: Detecting uBlock Origin and Adblock Plus (no license information)
    • detectAdBlockFetchOrXhrAdsByGoogle (the "ultimate" solution)
    • detectAdBlockScriptAdsByGoogle (first solution in the article)
    • detectAdBlockScriptSailthruJs (updated solution from May 25th 2022)
  • detectAdBlockScriptAdsJs: In-house solution (may be removed due to low effectiveness)

The wrapper code is released under Apache 2.0.