A seleniumbase-rs plugin that stops pages from loading some resources.
Blocking images, fonts or media makes pages load faster and use less data in
tests and scrapers that do not look at them. It uses the Chrome DevTools
Protocol (Network.setBlockedURLs), so it needs a Chromium-based browser.
Plugin name: block-resources. Needs a Chromium browser.
Constructors: BlockResources::images_and_fonts(), BlockResources::media() and BlockResources::patterns(...).
Install it from the same revision of the plugins repository that your seleniumbase-rs pins; see Installing a plugin.
Use it#
Give the set to LaunchOptionsBuilder::plugins, as shown in the
Browser Plugins guide.
Constructors#
| Constructor | Blocks |
|---|---|
BlockResources::images_and_fonts() | Images (*.png, *.jpg, *.jpeg, *.gif, *.webp, *.avif, *.svg, *.ico) and web fonts (*.woff, *.woff2, *.ttf, *.otf) |
BlockResources::media() | Audio and video files (*.mp4, *.webm, *.mp3, *.ogg, *.wav, *.m4a) |
BlockResources::patterns(...) | URLs that match these patterns, such as *://ads.example.com/* (* matches anything) |
How it works#
The plugin is named block-resources and requires a Chromium browser
(Requirements::CHROMIUM_ONLY). In on_page_created it sends Network.enable
and then Network.setBlockedURLs with the patterns, to every tab. A failed
command stops the tab, and the error names the plugin and the hook.
What block-resources sends to every tab