jbrowser.services.adfilter
Generated from the source code of JBrowser 1.5.1.
Adblock Plus / EasyList filter engine: URL-pattern blocking, exceptions and element hiding.
The downloaded lists (see privacy.BLOCKLIST_SOURCES) are split by the updater into:
blocklist.txt: plain||domain^rules and hosts-file entries. Fast set lookups injbrowser.services.privacy.Blocklist.filters.txt: everything else this engine understands. That is URL patterns such as/ads/banner*.js$third-party, exceptions (@@), and element-hiding rules (##.ad-slot,example.com##.promo), which hide the empty boxes and "Advertisement" frames that domain blocking alone leaves behind.
Matching uses the same trick as Adblock Plus: every filter is filed under one "token" (a word it must contain), so a request only checks the handful of filters whose token appears in its URL. Unsupported syntax (procedural cosmetics, scriptlets, regex filters) is skipped.
Constants#
| Name | Value |
|---|---|
MAX_WILDCARDS |
4 |
MAX_URL |
2048 |
TYPE_OPTIONS |
{'script': 'script', 'image': 'image', 'stylesheet': 'stylesheet', 'css': 'stylesheet',… |
ALL_TYPES |
frozenset(TYPE_OPTIONS.values()) |
NetworkFilter#
class NetworkFiltersource
NetworkFilter(pattern: str, types: frozenset, third: bool | None, include: tuple, exclude: tuple, important: bool)
NetworkFilter.matches#
matches(url: str, first: str, rtype: str, third: bool) -> boolsource
FilterEngine#
class FilterEnginesource
Parsed filters.txt: network filters indexed by token, plus element-hiding rules.
FilterEngine.from_text#
class method from_text(text: str) -> 'FilterEngine'source
FilterEngine.load#
class method load(path: Path) -> 'FilterEngine | None'source
FilterEngine.site_allowed#
site_allowed(first: str) -> boolsource
The list itself exempts this site from blocking (@@||site^$document).
FilterEngine.blocking_filter#
blocking_filter(url: str, first: str, rtype: str, third: bool) -> NetworkFilter | Nonesource
FilterEngine.excepted#
excepted(url: str, first: str, rtype: str, third: bool) -> boolsource
FilterEngine.cosmetic_data#
cosmetic_data() -> dictsource
Element-hiding rules in the compact form the page script uses (see engine/js.py
cosmetic_js): the script picks the rules for its own site as the page starts. That is
the only way they apply to the very first page of a site, because a script added while
a navigation is already under way only takes effect from the next one.
FilterEngine.css_for#
css_for(host: str) -> strsource
The style sheet the page script builds for host (for tests and diagnostics).
Functions#
split_list#
split_list(text: str) -> tuple[set[str], list[str]]source
Split a downloaded list into plain domains (for blocklist.txt) and the lines the
FilterEngine handles (for filters.txt). Hosts files only produce domains.