1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//! Demonstrates the P5 interception API by blocking any subresource whose
//! URL matches `*/ads/*`, then navigating to a real page.
//!
//! Sequence:
//! 1. Build a [`Browser`] in headless mode.
//! 2. Register a `block` rule on the main tab via the [`InterceptBuilder`]
//! fluent API; `start()` spawns the per-tab actor that drives
//! `Fetch.enable` + `Fetch.continueRequest` / `Fetch.failRequest` in
//! the background. Bind the returned [`InterceptHandle`] — its `Drop`
//! tears the actor down, so letting it go out of scope mid-flow would
//! silently disable interception.
//! 3. `goto` + `wait_for_load` example.com. The page itself doesn't load
//! anything under `/ads/`, so no rule fires; the example is here to
//! show the *shape* of the API, not a hit count. Adapt the URL and
//! pattern to whatever you actually want to block.
//! 4. Print the page title to prove the navigation succeeded with the
//! actor in the loop.
//!
//! Requires the `interception` cargo feature:
//! `cargo run --example intercept_block_ads --features interception`.
use Browser;
// example boundary; users wrap in their own Error
async