Skip to main content

Two declarations of the Plugin trait that the set checks before anything starts: requirements says what browser a plugin can run with, and packages lists the scripts and styles it loads into every new tab. Both items are in seleniumbase_rs_plugin, defined in crates/seleniumbase-rs-plugin/src/lib.rs.

Requirements#

struct seleniumbase_rs_plugin::Requirements

Conditions a plugin needs, combined with |, returned by Plugin::requirements. PluginSet::check_with compares them with the LaunchContext and refuses a browser that does not fit with PluginError::Requirement, before anything starts. A refusal is an error, not a warning.

Requirementsflags#

sbrs plugin info prints them under needs as a Chromium-based browser, a browser it starts itself, not one it attaches to, a window, not headless and to run after the plugins without this flag.

Requirements::empty#

fn const
returnRequirements#

No requirements; also Requirements::default() and the default of Plugin::requirements.

Requirements::contains#

fn const
otherRequirementsrequired#

The flags to look for.

returnbool#

Whether every flag of other is set.

Package#

struct seleniumbase_rs_plugin::Package

JavaScript or CSS that a plugin loads into pages, returned by Plugin::packages. Make one with a constructor, then say where it loads with only_on or everywhere: the check refuses a plugin with a package that does neither (one of its packages says neither `only_on` nor `everywhere` ), so a plugin never loads a script into every site by accident. Pin the version in a URL and add integrity so the browser checks the file.

For every new tab, PluginSet::on_page_created hands each package’s init_script() to PageHandle::add_init_script, before the plugin’s own on_page_created. Declare the matching capability, page.script:HOSTS or page.script:*; this version does not compare the packages with it.

ConstructorLoadsWhen, in each matching document
Package::script(code)inline JavaScriptas soon as the document starts, before the page’s own scripts
Package::style(css)an inline style elementat DOMContentLoaded, or at once if the document has loaded
Package::script_url(url)a script element with src, crossOrigin = 'anonymous' and the integrityas style
Package::style_url(url)a link rel="stylesheet" element, crossOrigin = 'anonymous' and the integrityas style

The element goes into document.head, or the document element when there is no head. A document matches when location.hostname equals one of the hosts or ends with . and one of them; with everywhere, every document matches.

Package::script_url#

fn
urlimpl Into<String>required#

The script’s URL. Pin the version in it.

returnPackage#

A script loaded from url, with no hosts yet.

Package::style_url#

fn
urlimpl Into<String>required#

The stylesheet’s URL.

returnPackage#

A stylesheet loaded from url, with no hosts yet.

Package::script#

fn
codeimpl Into<String>required#

JavaScript run in every matching document before the page’s own scripts.

returnPackage#

An inline script, with no hosts yet.

Package::style#

fn
cssimpl Into<String>required#

CSS added to every matching document.

returnPackage#

An inline stylesheet, with no hosts yet.

Package::integrity#

fn
hashimpl Into<String>required#

The Subresource Integrity hash of the file at the URL, such as sha384-....

returnPackage#

The package with the hash; the browser refuses a file that does not match. It applies to script_url and style_url; inline code has no file to check.

Package::only_on#

fn
hostsimpl IntoIterator<Item = impl Into<String>>required#

Host names, such as ["example.com"]. Each also covers its subdomains. They are compared as written with location.hostname, which browsers keep in lower case.

returnPackage#

The package, loading only on these hosts. It replaces an earlier only_on or everywhere.

Package::everywhere#

fn
returnPackage#

The package, loading on every site. It replaces an earlier only_on.

Package::init_script#

fn
returnOption<String>#

The script that loads the package into a document, for PageHandle::add_init_script; None when the package does not say where it loads.

Every value (URL, hash, CSS, host list) goes into the script as a JSON literal, so a quote in it cannot break the script; inline script code is inserted as written, followed by a line break. The ResponseExample shows two results.