I am trying to write a browser extension that will detect advertisements. I don't want an AdBlock, I just wish to detect how many ads are encountered. I don't know where to begin searching for ads in the HTML, though. Any help for a good first start?
Ad blocking detection works by placing so-called “bait content” within the pages of a website. Although invisible to the user (it might, for example, be a single pixel in size), this bait content is implemented so as to appear to ad blockers as advertising content.
While ad-blocking software can't be detected by the websites directly, one can assume their presence by testing whether particular elements of the page have been displayed.
Ad blockers are browser extensions or plugins that disable ads on specific web pages. An ad blocker works by blocking communications to ad servers and then hiding the elements of the web page that are designed to display advertising content.
Most adblockers catch the ads via some form of a regex match.
I would recommend you to start with the adblockpluscore repository, since it's open source and you can quickly run through the source code.
Start with the test directory, particularly peeking into the patterns.ini file and see the common patterns, when determining different sources of ads.
Search for these sections in patterns.ini:
You can expect, that your initial solutions won't be too effective, since ads come in different forms of data, but you'll find common patterns between many of them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With