Awesome Open Source
Awesome Open Source

Detect AdBlock Dependency Status

yarn add detect-adblock

DetectAdbblock is a library which recognizes using of ad blocker in a browser. You can use it in case you want to show advertisment towards users or just run important script which are beign blocked.


This library is inspired by BlockAdBlock project. Main changes are that this library is simplified, completely written in ES6 and contains tests written in Jest.

How to use

To use Detect AdBlock you need just to import DetectAdblock class to your project and then use it as a standard javascript class.


  • timeout specifies number of ms to run check for, default is 1000.
  • enabledHandler is a callback which is called when no ad block is recognized.
  • disabledHandler is a callback which is called when no ad block is not recognized.


  • startChecking(count) is a method which starts checking for ad blockers. Count is the number of checks in one run. Default is 5.


import DetectAdblock from '@blueberry/detect-adblock'

const onEnabled = () => console.log('ENABLED');
const onDisabled = () => console.log('DISABLED');

const check = () => {
  // It is important to check wheter the script is rendered in the browser.
  if (!process.env.IS_BROWSER) return;

  const detector = new DetectAdblock(500, onEnabled, onDisabled);

Browser compatibility

The package should work in all modern browsers including IE8+.

Made with love by

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
javascript (69,968
adblock (89
detector (34