Skip to main content

Module intercept

Module intercept 

Source
Expand description

Request interception logic for blocking unwanted network requests.

When a browser page has resource blocking or domain blocking enabled, every outgoing request is evaluated by the functions in this module before it is allowed to proceed. There are two independent blocking mechanisms:

  1. Resource-type blocking (should_block_resource) – drops requests for heavyweight resource types like images, fonts, stylesheets, and media when disable_resources is true. The exact list of blocked types is defined in [constants::EXTRA_RESOURCES].

  2. Domain blocking (is_domain_blocked) – drops requests whose hostname (or any parent domain suffix) appears in a blocklist. This powers both custom domain blocking and the built-in ad/tracker blocklist.

The top-level should_block_request function combines both checks and is the one wired into Playwright’s route handler in crate::fetcher.

Functions§

is_domain_blocked
Returns true if hostname (or any of its parent domains) appears in blocked_domains.
should_block_request
Returns true if a request should be blocked based on its resource type or domain.
should_block_resource
Returns true if the given resource type should be blocked when resource blocking is enabled.