Facebook feed without ads? Possible?

The cat and mouse game between advertisers and ad-blockers are never over. As soon the blocker guys come up with some solution, the advertisers take counter measure to make the ad-blocking ineffective. No wonder, since selling ads is their business-model.

The gold standard for blocking content -including ads- is to use CSS selector based rules. This is what we can set up in our browser extensions, like Adblock, Adblock Plus, uBlock Origin, etc. All of them come with an extensive set of rules, sometimes referred to as filters.

The weakness in the CSS selector based approach has been identified by advertisers and they have made their counter measure. Since the CSS selector uses fixed IDs and classes, the obvious counter measure is to use dynamically generated IDs and class names on the server side, which changes all the time, making the fixed CSS selector based approach useless.

What else can be done to block unwanted content and ads when dynamic IDs and class names are in place? Well, instead of using CSS selectors, one can inspect the JavaScript objects themselves, using injected JavaScript code. Injecting JavaScript code into pages are supported by the major browsers, through some API. However this often comes with a limitations like the “isolated world” approach like in Chrome, meaning the injected JavaScript code runs in a different -isolated- engine, but shares the same DOM. Of course there are techniques to circumvent this limitation.

Facebook uses React. Even though the IDs and classes are dynamically generated, the properties in the JavaScript objects can be inspected and based on their values one can decide whether a particular feed-unit is genuine from one of your friends, or an ad.

I’ve written a piece of JavaScript code, called as a “scriptlet” -using uBlock Origin’s terminology-, which can be used together with the uBlock Origin browser extension. This small JavaScript code, identifies the ads and other unwanted feed-units -configurable what- and blocks them.

To use it, you first need to install the uBlock Origin browser extension, then configure the extension to use the external scriptlet from my repository, then you need to add a filter line to have it injected.

If you are interested, check out my GitHub repository!

Facebook feed without ads? Possible?