contentrules

package
v0.1.18 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package contentrules matches loads against rules in WebKit's content blocker format, for the backends whose engine has no content blockers (WebView2). Only the backends' content rules reach it, so that apps that never compile rules don't link it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HidingScript

func HidingScript(lists []*List) string

HidingScript returns JavaScript that hides, in a document of a page applying the lists, the elements their css-display-none rules select for its URL, or "" when the lists hide nothing. Each selector gets a style rule of its own, so that one the engine does not take leaves the others be.

Types

type List

type List struct {
	// contains filtered or unexported fields
}

List is a list of rules, parsed. Match it from one goroutine at a time: it compiles the rules' regular expressions as it first needs them.

func Parse

func Parse(rules string) (*List, error)

Parse parses rules in WebKit's content blocker format, failing as WebKit does on what it would not compile.

type Request

type Request struct {
	// URL is what loads, TopURL the page it loads for, the URL itself
	// for a page.
	URL, TopURL string
	// Type is what kind of resource it is: a type or several, any of
	// which a rule's resource-type may name.
	Type Type
}

Request is a load to match.

type Result

type Result struct {
	Block, BlockCookies, MakeHTTPS bool
}

Result is what rules do to a load.

func Match

func Match(lists []*List, r Request) Result

Match returns what the lists do to the load: each list applies its rules in order, and a list's ignore-previous-rules undoes only what its own rules before it did.

type Type

type Type uint16

Type is a set of the kinds of resources of WebKit's resource-type.

const (
	Document Type = 1 << iota
	Image
	StyleSheet
	Script
	Font
	Raw
	SVGDocument
	Media
	Popup
	Ping
	Fetch
	WebSocket
	Other
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL