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

adblock-detector-service

v1.0.3

Published

Tiny frontend adblock detector based on real ad and bait script requests

Downloads

336

Readme

adblock-detector-service

Lightweight frontend adblock detector based on real ad and bait script requests.

It detects ad blockers by attempting to load known ad-related resources and evaluating whether they are blocked by the browser.

The implementation also relies on project-controlled third-party bait domains to improve detection stability across different browsers.

Browser behavior

Designed to work with both classic adblock extensions and built-in browser protections.

Works well with:

  • Chrome-based browsers using adblock extensions
  • Brave with Brave Shields enabled
  • Firefox with built-in tracking and content blocking enabled

To increase reliability, different domain sets are used depending on browser behavior.

How it works

The detector dynamically injects script tags pointing to:

  1. Well-known ad provider domains (Google Ads, Facebook, etc.)
  2. Custom bait endpoints hosted on a dedicated third-party domain controlled by this project

If a request fails (onerror), it is treated as blocked.

Detection result is based on the ratio of blocked requests.

  • Brave and Firefox use bait domains by default
  • Other browsers use real ad domains

Why this library

Many existing adblock detectors rely on outdated techniques or are easily bypassed.

This implementation:

  • uses real network requests instead of heuristics
  • works without fetch/CORS limitations
  • does not depend on DOM bait elements
  • is minimal and framework-agnostic

Installation

npm install adblock-detector-service

Usage

import adBlockDetector from 'adblock-detector-service'

const report = await adBlockDetector()

console.log(report.isAdBlockDetected)

Configuration

type InputSettings = {
    isBaitDomainsOnly?: boolean
    isAdsDomainsOnly?: boolean
    percentage?: number
    requestsLimit?: number
}

Parameters

  • isBaitDomainsOnly (default: false)
    Use only bait (custom) domains for detection. Useful for browsers with aggressive blocking (e.g. Brave, Firefox).
  • isAdsDomainsOnly (default: false)
    Use only real ad provider domains (Google, Facebook, etc.).
  • percentage (default: 0.5)
    Detection threshold. If the ratio of blocked requests exceeds this value → adblock is detected.
  • requestsLimit (default: 5)
    Number of domains to test. Lower values → faster but less reliable detection. Max. value - 5

Notes:

  • All the parameters are optional
  • You can't use isBaitDomainsOnly and isAdsDomainsOnly parameters with true value at the same time

Example

await adBlockDetector({
    percentage: 0.6,
    requestsLimit: 3
})

Response

type IReport = {
    domainsTest: {
        domain: string
        isBlocked: boolean
    }[]
    blockPercent: number
    isAdBlockDetected: boolean
}

Example response

{
  domainsTest: [
    { domain: 'https://.../prebid.js', isBlocked: true },
    { domain: 'https://.../adapter.js', isBlocked: true },
    { domain: 'https://.../banner.js', isBlocked: false }
  ],
  blockPercent: 0.66,
  isAdBlockDetected: true
}