AdguardTeam / ContentBlocker

Content blocking extension for Samsung Internet and Yandex Browser
GNU General Public License v3.0
491 stars 91 forks source link

Recent versions of Chromium support :has() CSS selector, AG Content Blocker should support it #345

Open superlex opened 9 months ago

superlex commented 9 months ago

Prerequisites

Please answer the following questions for yourself before submitting an issue. YOU MAY DELETE THE PREREQUISITES SECTION.

Problem Description

Recent versions of Chromium support :has() CSS selector, AG Content Blocker supports it as well. Btw, AG Content Blocker recognizes only this syntax: example.org##body > div > p:has(>a) and it works like a charm. However, it should recognize this syntax too: example.org#?#body > div > p:-abp-has(>a) example.org#?#body > div > p:has(>a)

Proposed Solution

1) Change AG Content Blocker behavior in order to recognize the correct syntax; 2) Update android-content-blocker/filters/*.txt lists adding AG filters that use :has() css selector .

Alternatives Considered

Update android-content-blocker/filters/*.txt lists adding AG filters that use :has() css selector, using syntax recognized by Samsung Internet.

Additional Information

Android 13 - One UI 5 Samsung Internet 22.0.6.9 AG Content Blocker 2.7.2

superlex commented 9 months ago

Some additional thoughts. As more and more browsers support :has() native pseudo-class, maybe best solution is to add all rules having :has() to android-content-blocker/filters/*.txt lists with the syntax ##, like explained in the wiki:

Rules with the :has() pseudo-class should use native implementation of :has() if they use ## marker and if it is possible, i.e. with no other extended selectors inside.

In this way no additional code would be necessary for ContentBlocker, furthermore other browser having a (basic) built-in adblock can take advantage of android-content-blocker/filters/*.txt lists, for example Vivaldi. This is not a priority for AG, of course, but it could prove beneficial in the future.

References https://github.com/AdguardTeam/ExtendedCss#extended-css-has https://developer.mozilla.org/en-US/docs/Web/CSS/:has https://caniuse.com/css-has

223047 commented 8 months ago

Hoang van canh