Anti-Adblock Introdution

If you use an Adblock technology like uBlock, you sometimes see an Anti-Adblock technology on a website that blocks you from accessing the website content. A famous example recently is I will use a website as an example to show how you can defeat that by creating a custom whitelist rule that will fight the Anti-Adblock but still disable the Advertisements and Tracking. You can call it an Anti-Anti-Adblock or Anti-Adblock-Killer.

Create an Anti-Adblock-Killer for an example website

The example website for this tutorial is that shows a nag screen. When you open the website with Adblock enabled, you receive a message like this:

Open the developer tools (by pressing F12 on Windows for Chrome), click the magnifier to inspect the element and click on the dialog that shows the Anti-Adblock message.

The sourcecode shows the div that displays this message. The name indicates that the div id is random, refreshing the page and inspecting the div again proofs that. Therefore a black or white-listing based on the div id would not work. Now search for the id of the div in the code by pressing Ctrl+F. One of the matches is:

As you can see by the code and name of the canRunAds variable, it is used to determine if the user can show Ads or uses an Adblocker. Searching for canRunAds reveals no code location that sets it, therefore it must be set by an external script (If the code to set it is not obfuscated of course). Open the Network tab of the developer tools and refresh the page. You will now see all network requests that got blocked by the Adblocker marked red.

Right click on each of the blocked scripts and select Open in new tab. The url reveals an interesting script:

var canRunAds = true;

Now all we need to do is whitelist this specific url in uBlock. Open the uBlock settings, select My rules, click Edit below Temporary rules and insert a new line: script allow

Save the whitelist rules, refresh the website and voila the nag screen is gone and shows no Ads.

Update the Anti-Adblock-Killer

Update 2015-08-2: The website Anti-Adblock code changed and the solution above does not work anymore. A look into the code of the website reveals the new added JavaScript code:

var script = document.createElement('script');
    script.onerror = function(){
        script.onerror = null;
		_gaq.push(['_trackEvent', 'adblock popup', "show popup", document.location+""]);
    script.src = "";

This code uses the window.onerror function to catch failed http request which in our case is the blocked the Ad script. In the source code of the nag screen you can see that is uses the css class headline. If you search for it in the html you will see that it is only used in the nag screen. That allows us to use that class to find the nag screen with a jquery selector and from there to traverse up the DOM tree to find the main div of the nag screen that has a random id. Install Tampermonkey for Chrome or Greasemonkey for Firefox and add a new user script with the following content:

// ==UserScript==
// @name Anti-Adblock Killer
// @require
// @namespace
// @version      1.0
// @description  Removes the nag screen on when using an ad-blocker
// @author       CornelK
// @match*
// @grant        none
// ==/UserScript==

var script = document.createElement('script');
script.src = "";


Refresh the site and voila, the nag screen is gone again (for now).