Content-Blocking in Manifest v3
2024-10-14 00:59:18 Author: textslashplain.com(查看原文) 阅读量:7 收藏

I’ve written about selectively blocking content in browsers several times over the last two decades. In this post, I don’t aim to convince you that ad-blocking is good or bad, instead focusing on one narrow topic.

Circa 2006, I was responsible for changing IE so that you could simply add an advertising site to the Restricted Sites zone and none of its script would load. Later, in 2010, I wrote a bit about the landscape of ad-blocking on the IEBlog.

More recently, Apple introduced Content-Blocking framework for their browser in 2015, and in 2019 the Edge team released Tracking Prevention, which blocks many ads in its Strict Mode.

Manifest v3

Recently, there’s been a bit of an outcry about Google’s move to require Chrome extensions be built atop a new platform named Manifest v3. This long overdue change attempts to mitigate the overprivileged Chrome extensions framework. V2 poses security, privacy, and performance risks to users, and has been abused (intentionally and unintentionally) by extension authors over the years.

No good deed goes unpunished, however, and conspiracy theorists have argued that Google is doing this to prevent ad-blockers from working. These theories aren’t entirely crazy — Google is, after all, first-and-foremost an advertising company. Where the theory falls apart, however, is that Google’s ads are among the easiest to block. While MV3 may make it more challenging to block some ad providers, you can still trivially choke off more than half of Google’s ad revenue in under a dozen lines of code. If MV3 were a conspiracy on Google’s part, it’s a jaw-droppingly ineffective one.

Step-by-Step: Blocking Google Ads

To save myself some typing, let’s start with a trivial MV3 extension I built for web developers (which should soon be obsolete 🤞).

Clone the code to your local disk. Create a new file named adsense.json:

[{
    "id" : 1,
    "priority": 1,
    "action" : { 
        "type" : "block"
    },
    "condition" : {
        "urlFilter" : "||pagead2.googlesyndication.com",
        "resourceTypes" : ["script"]
  }
}]

As you can see, Manifest v3 makes it utterly trivial to block requests to Google’s ad network.

Modify the existing manifest.json file with new values:

Remove the old localhost.json and add the new adsense.json file:

Testing the Extension

First, visit a page that has a Google ad on it to ensure that it loads as expected:

Now, inside Chrome, visit chrome://extensions, toggle the Developer Mode toggle, and click the Load Unpacked button. Select your extension’s folder:

Revisit the page with the Google ad and observe that it no longer loads. The Developer Tools console notes that the request for the JavaScript was blocked:

The MV3 ad-blocking approach is very easy to work with. Simply declare which sites you want to block, and they’re blocked. No slow and complicated network parsing or anything like that.

But…but… but…

Skeptical readers will note that this trivial approach blocks one type of Google’s ads, but not every type of Google ads. And that’s certainly true.

Fifteen years ago, I described the cat and mouse game between ad-hating users and advertising platforms as “a grenade fight, where both sides get infinite grenades.” Nothing has changed.

Economics rules everything around us.

Because sites need ad revenue to survive, they rely on ads not being blocked. Thus, ad networks have incentives to disrupt ad blockers. When a new blocking technique is adopted, the ad network responds. There are entire businesses built around trying to coax/annoy users to allow ads; one of the biggest is a platform called Admiral. Because I browse with Edge’s Tracking Prevention: Strict enabled, almost every ad-supported site I visit pops a banner like this one:

Some sites allow a “Continue without supporting us” link, and some do not. It’s the site’s choice. Major publishers might not rely on third-party frameworks and instead perform their own ad-blocking detection.

In response, some ad-blockers introduce ad-blocker-blockers, and the publishers then have ad-blocker-blocker-blockers. And the battle rages on, with dueling JavaScript files burning your battery while a quiet war rages under the surface.

-Eric


文章来源: https://textslashplain.com/2024/10/13/content-blocking-in-manifest-v3/
如有侵权请联系:admin#unsafe.sh