pub enum Rule {
Block {
pattern: UrlPattern,
},
Redirect {
from: UrlPattern,
to: String,
},
Respond {
pattern: UrlPattern,
status: u16,
headers: Vec<(String, String)>,
body: Vec<u8>,
},
Modify {
pattern: UrlPattern,
modify: Arc<dyn Fn(&RequestInfo) -> RequestOverrides + Send + Sync>,
},
ModifyResponse {
pattern: UrlPattern,
modify: Arc<dyn Fn(&ResponseInfo) -> ResponseOverrides + Send + Sync>,
},
BlockHosts {
matcher: Arc<HostMatcher>,
},
}Expand description
A single interception rule.
Each variant carries its own UrlPattern, so different rules in the same
InterceptBuilder can match disjoint
URL sets. Rules are evaluated in registration order — earlier rules
shadow later ones for overlapping patterns.
Variants§
Block
Abort matching requests with Fetch.failRequest
(errorReason: "BlockedByClient").
Fields
pattern: UrlPatternURL pattern matched against Fetch.requestPaused.request.url.
Redirect
Redirect matching requests to to via Fetch.continueRequest { url }.
Fields
from: UrlPatternURL pattern matched against the incoming request URL.
Respond
Serve a synthesized response with Fetch.fulfillRequest.
Fields
pattern: UrlPatternURL pattern matched against the incoming request URL.
Modify
Rewrite the outgoing request per-field via a user closure, then
continue. The closure receives the live RequestInfo and returns
the RequestOverrides to apply.
Fields
pattern: UrlPatternURL pattern matched against the incoming request URL.
modify: Arc<dyn Fn(&RequestInfo) -> RequestOverrides + Send + Sync>Closure invoked per matching request to produce overrides.
Wrapped in Arc so the actor can cheaply share the closure
across the rule list without forcing the rule itself to be Clone
or Send-by-value.
ModifyResponse
Rewrite an upstream response’s status/headers per a user closure, then
continue with Fetch.continueResponse (keeping Chrome’s body). Only
fires at the Response stage — the closure receives the live
ResponseInfo and returns the ResponseOverrides to apply. A rule
of this kind that matches at the Request stage is a no-op (there is
no response yet).
Fields
pattern: UrlPatternURL pattern matched against the incoming request URL.
modify: Arc<dyn Fn(&ResponseInfo) -> ResponseOverrides + Send + Sync>BlockHosts
Abort requests whose host is in a HostMatcher with
Fetch.failRequest { errorReason: "BlockedByClient" } — the same
net::ERR_BLOCKED_BY_CLIENT a real adblocker / Brave raises.
Unlike Block, which globs the full URL, this matches
host-set membership (exact + parent-domain suffix on dot boundaries),
so a curated list of thousands of hosts is one O(1) set lookup per
request rather than N glob comparisons. Powers the tracker blocklist.
Fields
matcher: Arc<HostMatcher>Shared host set; cheap to clone across tabs/rules.