14

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.

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
  • AFAIK, adBlock is also triggered by specific words. Changing the name/url might help :) – Martijn May 16 '17 at 09:53
  • I recently had a problem like this, Adblock was stopping the `onerror` attribute of an `img` element working. I just told the tester to disable it, if anyone has an answer I'd like to know too. It was "AdBlock Ultimate" that was causing this issue, "AdBlock plus" worked fine – George May 16 '17 at 09:54
  • does the url contain any ad keywords like *ad* *buy* *sell* – treyBake May 16 '17 at 09:55
  • @ThisGuyHasTwoThumbs The link in question was to the site's forums. Oddly, one of two such links (which appear at different window sizes), but only one of the two was blocked. – Niet the Dark Absol May 16 '17 at 09:57
  • click here to start the adventure against multiple adversaries adding hours of fun to your day – mplungjan May 16 '17 at 09:57
  • It seems that it was removing a container element: ` – Niet the Dark Absol May 16 '17 at 09:57
  • @NiettheDarkAbsol huh who'da thought sociallinks would be considered an ad :S I wonder if adblock has a list of keywords to avoid somewhere – treyBake May 16 '17 at 10:00
  • @ThisGuyHasTwoThumbs some adblockers have an option to also [disable social media buttons](https://adblockplus.org/tutorials#disablesocial) – Kruga May 16 '17 at 11:16
  • @Kruga ah I see, thanks :) – treyBake May 16 '17 at 11:18

1 Answers1

10

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.

Jimmy Breck-McKye
  • 2,923
  • 1
  • 22
  • 32
  • +1 for checking the list. One of my generated class names was being blocked because it started with `sc-`, added a prefix for all classes and now all my elements can live in peace. – MustSeeMelons Oct 05 '20 at 06:58