Skip to main content

A plugin is a type that implements Plugin. name is the only method without a default; every hook does nothing unless you override it. Items are in seleniumbase_rs_plugin (seleniumbase_rs::plugin_api from seleniumbase-rs), defined in crates/seleniumbase-rs-plugin/src/lib.rs. A walk-through is in Writing your own; when each hook runs on each engine is in When the hooks run.

Plugin#

trait seleniumbase_rs_plugin::Plugin

The trait is object safe through #[async_trait]: a set keeps plugins as Arc<dyn Plugin>. Write #[async_trait] on every impl Plugin too. The supertraits Send + Sync + 'static let one plugin serve several browsers and tasks at once, so keep mutable state behind atomics or a Mutex.

MethodKindDefaultCalled by
namedeclarationnone, requiredevery PluginSet method
dependenciesdeclaration&[]the run order and the check
requirementsdeclarationRequirements::empty()PluginSet::check_with, the run order
metadatadeclarationMetadata::legacy()the check, the run order, grants, audit
per_launchdeclarationNonePluginSet::for_launch
packagesdeclarationno packagesthe check, PluginSet::on_page_created
before_launchhookdoes nothingPluginSet::before_launch
on_browserhookdoes nothingPluginSet::on_browser
on_page_createdhookdoes nothingPluginSet::on_page_created
on_closehookdoes nothingPluginSet::on_close
Note

The set calls the declarations again whenever it orders, checks or audits the plugins, so return the same values every time and keep them cheap.

Plugin::name#

fn required
return&strrequired#

The plugin’s unique, lower-case name, such as block-resources.

A set refuses a second plugin with the same name (PluginError::DuplicateName). Other plugins refer to this name in dependencies, requires, conflicts_with, after and before. A plugin that is also Configurable returns Self::NAME, the name a registry builds it by.

Plugin::dependencies#

fn provided
return&[&str]#

The names of the plugins this one needs in the same set.

Default: "&[]"

Each name joins the plugin’s requires edges from Metadata::requires: the named plugin must be in the set, or the check fails with PluginError::MissingDependency, and it runs before this one.

Plugin::requirements#

fn provided
returnRequirements#

Conditions the plugin needs, combined with |: CHROMIUM_ONLY, LAUNCH_ONLY, HEADFUL, RUN_LAST. See Requirements.

Default: "Requirements::empty()"

The check refuses a browser that does not fit with PluginError::Requirement. RUN_LAST refuses nothing; it puts the plugin in the phase Last.

Plugin::metadata#

fn provided
returnMetadata#

What the plugin declares: category, version, summary, capabilities, ordering edges, phase, seals and budgets. See Metadata.

Default: "Metadata::legacy()"

The default, Metadata::legacy(), has no category and the legacy capability set (raw:cdp among them). Such a plugin is “undeclared”: a plain set runs it, a strict set refuses it with PluginError::Undeclared. The command line, the MCP server and every set built from names are strict.

Plugin::per_launch#

fn provided
returnOption<Arc<dyn Plugin>>#

A fresh instance for one browser, or None to share this one.

Default: "None"

PluginSet::for_launch replaces the plugin with the instance it returns, keeping its grants, so browsers launched from one set (a pool) do not share the plugin’s state and on_close reaches the instance that started. Both engines call for_launch before every launch and every attach. The fresh instance must have the same name; one with another name is ignored and the shared instance is kept.

Plugin::packages#

fn provided
returnVec<Package>#

JavaScript and CSS to load into every new tab. See Package.

Default: "empty"

Every package must say where it loads (only_on or everywhere), or the check refuses the plugin with PluginError::Requirement (one of its packages says neither `only_on` nor `everywhere` ). For each new tab, the set adds the plugin’s packages with PageHandle::add_init_script, then calls its on_page_created. A package that fails is reported as PluginError::Hook with the hook packages.

Plugin::before_launch#

fn async provided
launch&mut LaunchSettingsrequired#

The start-up settings of the browser about to start, as the host filled them in and earlier plugins changed them. See LaunchSettings.

returnResult<()>#

Ok(()) to go on; an error stops the launch.

Runs before the browser starts, in run order. It does not run when the program attaches to a running browser. After each plugin the set checks what it changed: each change needs its capability, list fields only grow, a refused switch or feature needs raw:switches, the profile is read-only, and a field another plugin sealed keeps its value. The rules are under PluginSet::before_launch.

Plugin::on_browser#

fn async provided
browser&dyn BrowserHandlerequired#

The running browser: its engine, its family and browser-level DevTools commands. See BrowserHandle.

returnResult<()>#

Ok(()) to go on; an error stops the launch or the attach.

Runs once the browser runs, whether the program started it or attached to it.

Plugin::on_page_created#

fn async provided
page&dyn PageHandlerequired#

The new tab: its engine, DevTools commands to it, scripts for every document and evaluation. See PageHandle.

returnResult<()>#

Ok(()) to go on; an error stops the tab.

Runs for every tab the library attaches to, before any command of the program runs in it. The plugin’s own packages are already added.

Plugin::on_close#

fn async provided
returnResult<()>#

An error is collected, not raised: the browser closes anyway.

Runs when the browser is about to close. Every plugin runs even when one fails; PluginSet::on_close returns the failures, and both engines log each one at WARN (cdp.plugin.close.failed, webdriver.plugin.close.failed). Use it to clean up, such as deleting temporary folders.

Result#

type seleniumbase_rs_plugin::Result

The result of every hook and of the fallible PluginSet and Registry methods. In a program that also uses std::result::Result, import it under another name: use seleniumbase_rs::plugin_api::Result as PluginResult;.

PluginError#

enum non_exhaustive seleniumbase_rs_plugin::PluginError

Why a plugin, or the set, refused to go on. It implements std::error::Error and Display; seleniumbase-rs turns it into SeleniumBaseError::Plugin with From. The Display text of each variant is shown below, with each field in capitals.

PluginErrorenum#

PluginError::other#

fn seleniumbase_rs_plugin::PluginError::other

messageimpl Into<String>required#

What went wrong, for the user.

returnPluginError#

PluginError::Other(message).

The usual way for a hook to fail. The set adds the plugin’s name and the hook when it wraps the error in PluginError::Hook.

async_trait#

macro seleniumbase_rs_plugin::async_trait

The async_trait attribute macro of the crate async-trait (0.1), re-exported so a plugin crate needs no dependency of its own for it. Put #[async_trait] on every impl Plugin, impl BrowserHandle and impl PageHandle.

See also#