Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@horat1us/detect-ad-block

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@horat1us/detect-ad-block

Browser Ad Block add-ons detector

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
increased by20%
Maintainers
1
Weekly downloads
 
Created
Source

Detect Ad Block

Simple module to detect advertising block add-on in browser using Promise.

  • Promise-based
  • TypeScript
  • ESM/CommonJS support

Require Promise to be supported or polifylled.

Inspired by FuckAdBlock@4.0.0-beta3.

Installation

Using npm:

npm i @horat1us/detect-ad-block@^1.0

Usage

import { DetectAdBlock } from "@horat1us/detect-ad-block";

function detect() {
    const detectAdBlock = DetectAdBlock();
    detectAdBlock.perform({ timeout: 1000 })
        .then((result) => {
            console.log(result ? `AdBlock Detected` : `AdBlock Not Found`);
        })
        .catch((error) => {
            console.error(`Error while AdBlock checking: `, error);
        });
}
const timeout = 5000;

// You may use window.onload, document.onreadystatechange etc.
if (window.requestIdleCallback) {
    window.requestIdleCallback(detect, timeout);
} else {
    setTimeout(detect, timeout)
}

Note: You should not run adblock checking directly on or after page load.

DetectPlugin

You may use built-in plugins:

  • http:ajax (default) - http request block detection using XMLHttpRequest (AJAX)
  • html (default) - html element block detection
  • http:script - http request block detection using script tag (<script src="/ad/.... />)

Also, you may implement custom plugin using DetectPlugin interface.

import { DetectAdBlock, plugins } from "@horat1us/detect-ad-block";

const detectAdBlock = DetectAdBlock([
    // your plugins list
    plugins.ajax,
    plugins.script,
    plugins.html,
    // using built-in plugin with custom options
    plugins.Html({
        name: "custom-html",
        baitStyle: "...",
        baitClass: "...",
        interval: 100,
        timeout: 950,
    }),
    // or custom plugin
    {
        name: "custom-plugin",
        version: 1,
        detect(resolve) {
            const result = performSomeCheck();
            resolve(result);
        },
    },
])

Contributors

License

MIT

Keywords

FAQs

Package last updated on 18 Sep 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc