Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deal with AdBlock blocking non-ad elements

I recently had an issue whereby a user was complaining that they couldn't access a certain page because the link wasn't where it was supposed to be.

After some head-scratching, I had them disable all browser extensions and sure enough the problem went away. Re-enable extensions one by one...

AdBlock.

For some reason, it was blocking the links to the pages the user wanted to access.

Now, I don't run ads and never plan to, so usually I just tell people with this problem to whitelist the site and all is well. But if someone never knew there was a problem to begin with, I would actually lose traffic because of this. So how can I avoid this?

The only thing I can really think of is to detect AdBlock and pop up a small notice explaining that AdBlock is known to corrupt the website and that, since we don't run ads, they may want to disable it for the site. I mean, the site is a game, and this isn't the first time a browser extension has broken it, but I don't think first-time visitors would be too happy to see a popup asking to disable their blocker, you know?

So any solution that would actually prevent AdBlock from corrupting the site in the first place would be great.

like image 730
Niet the Dark Absol Avatar asked May 16 '17 09:05

Niet the Dark Absol


People also ask

Why is AdBlock blocking my content?

If your visitors are seeing a warning like this: AdBlock has blocked a download from a site known to host malware, it's because they have the Malware Protection filter list enabled. Your domain is appearing on a list of known malware hosts maintained by Malwaredomains.com.

How do you use AdBlock on sites that don't allow it?

The easiest way you can bypass ad block detection on a website is by disabling JavaScript using the Site Info option on the browser. Just click on the Site Info icon as shown in the screenshot and disable the JavaScript option.

Why isn't my AdBlock blocking pop up ads?

Why doesn't AdBlock block all pop-ups automatically? Often it's because of the difference between first-party and third-party advertising we mentioned earlier. EasyList, the set of filter rules used by all ad blockers, ignores first-party pop-ups.


1 Answers

You cannot prevent Chrome extensions from running. They operate in their own separate thread, with a privileged API, and hidden from page scripts.

Detecting adblockers is awkward. The easiest way is to create a 'sacrificial element' - a div with a class like 'ad_unit', for example - add it to the DOM and then wait a frame to see if it has been hidden (with display: none, for example, or a getBoundingClientRect check).

Element checking is tricky, though, because strictly speaking there's no guarantee an adblocker will run synchronously or before your checking code.

Because adblockers run in a privileged mode, their operation does not trigger events in the nonprivileged script space. To put it more simply: you can't use DOMMutationEvents to spy when a foreign extension messes with your page.

The other option is to try and load a 'sacrificial file' - an image with a URI that looks like an advert, say - and then attach an onError handler to the element. If it throws an error that looks suspicious (I think it's ERR_BLOCKED_BY_CLIENT on Chrome), then you show your warning message.

Your final choice is to try and avoid incurring Adblock's wrath in the first place. Adblockers generally use open blacklists of URIs and CSS selectors, like EasyList (https://easylist.to/easylist/easylist.txt) - this is what AdblockPlus uses and a fair few others. You could just try and make sure your DOM elements never have IDs or classes that collide with any of those selectors. It's a big list, though, and it can change at any time.

like image 127
Jimmy Breck-McKye Avatar answered Oct 07 '22 21:10

Jimmy Breck-McKye