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.
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 constNo requirements; also Requirements::default() and the default of
Plugin::requirements.
Requirements::contains#
fn constThe flags to look for.
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.
| Constructor | Loads | When, in each matching document |
|---|---|---|
Package::script(code) | inline JavaScript | as soon as the document starts, before the page’s own scripts |
Package::style(css) | an inline style element | at DOMContentLoaded, or at once if the document has loaded |
Package::script_url(url) | a script element with src, crossOrigin = 'anonymous' and the integrity | as style |
Package::style_url(url) | a link rel="stylesheet" element, crossOrigin = 'anonymous' and the integrity | as 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#
fnThe script’s URL. Pin the version in it.
A script loaded from url, with no hosts yet.
Package::style_url#
fnThe stylesheet’s URL.
A stylesheet loaded from url, with no hosts yet.
Package::script#
fnJavaScript run in every matching document before the page’s own scripts.
An inline script, with no hosts yet.
Package::style#
fnCSS added to every matching document.
An inline stylesheet, with no hosts yet.
Package::integrity#
fnThe Subresource Integrity hash of the file at the URL, such as sha384-....
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#
fnHost names, such as ["example.com"]. Each also covers its subdomains. They
are compared as written with location.hostname, which browsers keep in lower
case.
The package, loading only on these hosts. It replaces an earlier only_on or
everywhere.
Package::everywhere#
fnThe package, loading on every site. It replaces an earlier only_on.
Package::init_script#
fnThe 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.