Skip to main content

seleniumbase-rs supports multiple configuration layers: built-in defaults, a global config file, SB_* environment variables, and programmatic BrowserConfig overrides. This makes it easy to keep environment-specific settings out of source code while still allowing per-test customization.

This page explains the configuration hierarchy, the available settings, and how to load and combine them.

Configuration hierarchy#

Settings are resolved from lowest to highest priority. A higher-priority source overrides a lower-priority one:

  1. Built-in defaults.
  2. Global config file (sbase_config.toml, .sbase_config.toml, or .sbase_config).
  3. Environment variables (SB_*).
  4. Programmatic BrowserConfig.
  5. CLI flags (when using sbrs).
Info

This means a BrowserConfig value in code wins over an environment variable, and a CLI flag wins over everything else.

Global config file#

Create sbase_config.toml in your project root (or a .sbase_config file in JSON; a flat KEY=VALUE file is not supported):

The file is optional. If it is missing, built-in defaults are used. The Settings::load_global() function searches for sbase_config.toml, then .sbase_config.toml, then .sbase_config in the current directory.

Loading settings programmatically#

Settings::load() reads the global config file and Settings::load_from(path) reads the file you name; both apply the environment variables on top. Settings::from_file reads the file alone. All three refuse a browser or mode that is not a known name (SB_BROWSER=chrom is an error, not Chrome), and a window_width without a window_height.

Environment variables#

Every setting in Settings can be overridden with an SB_ prefixed variable:

VariableMaps to
SB_BROWSERbrowser
SB_HEADLESSheadless (see Headless and headed browsers for which entry points read it)
SB_TIMEOUTtimeout_seconds: the default wait run_browser_test gives its BaseCase
SB_SCREENSHOT_DIRscreenshot_dir (stored for your code; the library does not read it)
SB_PROXYproxy
SB_PROXY_PAC_URLproxy_pac_url
SB_WINDOW_WIDTHwindow_width: with window_height, the browser window’s size
SB_WINDOW_HEIGHTwindow_height
SB_WEBDRIVER_URLwebdriver_url (default http://localhost:4444)
SB_CHROME_BINchrome_bin: the browser binary
SB_USER_DATA_DIRuser_data_dir
SB_EXTENSION_DIRextension_dir
SB_LOCALElocale
SB_USER_AGENTuser_agent
SB_MODEmode (webdriver, cdp, or uc)
SB_AD_BLOCKad_block
SB_REUSE_SESSIONreuse_session
SB_REUSE_CLASS_SESSIONreuse_class_session
SB_MOBILEmobile
SB_THREADSthreads
SB_ESC_ENDesc_end: pressing ESC in the browser ends the test (Python’s --esc-end)
SB_REC_SB_CDPrec_sb_cdp: recordings are written as pure CDP code (Python’s --rec-sb-cdp)
SB_REMOTE_WEBDRIVER_TIMEOUTremote_webdriver_timeout_seconds

Boolean values accept true/false, 1/0, yes/no, or on/off.

Example:

Runtime environment variables#

In addition to Settings, the crate reads SB_* runtime configuration for library behavior:

SB_WEBDRIVER_URLstring#

WebDriver endpoint.

Default: "http://localhost:4444"

SB_CHROME_BINstring#

Explicit Chrome/Chromium binary path.

Default: "auto-detect"

SB_PATCH_CACHE_DIRstring#

Directory for patched Chrome/Chromedriver copies.

Default: "platform cache"

SB_LOG_LEVELstring#

The tracing filter. Unset, blank or invalid, sbrs and sbrs-mcp use RUST_LOG, then info.

SB_LOG_FORMATstring#

pretty or json output.

Default: "pretty"

SB_SHUTDOWN_TIMEOUT_SECSinteger#

Graceful shutdown timeout.

Default: "30"

SB_CHROMEDRIVER_PORTinteger#
Not read yet

Parsed into RuntimeConfig::chromedriver_port; nothing in the crate reads it yet.

Default: "0"

SB_IMPLICIT_WAIT_SECSinteger#
Not read yet

Parsed into RuntimeConfig::implicit_wait; nothing in the crate reads it yet. For the default wait of a test, use SB_TIMEOUT or BaseCase::set_timeout.

Default: "30"

SB_REMOTE_WEBDRIVER_TIMEOUTinteger#

Unset by default. Client-side timeout, in seconds, for each HTTP request sent to a Remote WebDriver server.

Remote WebDriver timeout#

When tests run against a Selenium Grid, a node that dies mid-session can leave a command waiting forever, because the WebDriver client has no reason to give up on a connection that never closes. remote_webdriver_timeout_seconds (or the SB_REMOTE_WEBDRIVER_TIMEOUT variable) puts a client-side limit on each HTTP request sent to the server.

It is unset by default, matching SeleniumBase’s REMOTE_WEBDRIVER_TIMEOUT, so the client keeps its own default until you opt in.

Warning

If you set it, make it larger than your page-load timeout and larger than the longest a new-session request may wait in the grid’s queue. A value below either one cuts off sessions that were healthy.

BrowserConfig in code#

For per-test overrides, build a BrowserConfig directly:

BrowserConfig also supports from_env() to load runtime variables directly:

Proxy lists and ad-block lists#

Two small types in seleniumbase_rs::config hold lists that are too long for a config file field.

ProxyList is Python’s PROXY_LIST: proxies, optionally named, read from a text file (see CLI usage for the format). Each entry is validated when it is read. It resolves a name or a literal proxy (resolve), and hands proxies out in turn (next_round_robin) or at random (random); the turn counter is atomic, so one list can serve parallel tests:

ProxyEntry’s Debug and Display never show a password; only spec() does.

AdBlockList is a set of hosts to refuse, with their subdomains. AdBlockList::builtin() is the crate’s starter list of advertising and tracking hosts, AdBlockList::parse reads the host rules of a hosts file or an Adblock Plus list (and counts the rules it cannot express), and url_patterns() gives the patterns for the DevTools command Network.setBlockedURLs. is_blocked(url) matches on the parsed host, so a blocked name inside a query string does not block the page.

A Chromium WebDriver session sends such a list to the browser when BrowserConfig::ad_block is on: the built-in list, or yours through with_ad_block_list(list), which replaces it. bounded_url_patterns() is what is sent. It leaves out a host whose parent domain is also listed and refuses a list that needs more than 2,000 patterns, so the browser is never given half of what you asked for. See Blocking ads.

Best practices#

  • Commit a sample config file (e.g., sbase_config.example.toml) to the repo so new contributors know what settings exist.
  • Keep secrets (passwords, API keys) out of config files; use environment variables or a secrets manager.
  • Use Settings::load_global() in test harnesses and BrowserConfig overrides for individual tests.
  • Use BrowserConfig::from_env() in deployable applications so operators can change behavior without rebuilding.

Configuration checklist#

  • A sample config file is committed to the repository.
  • Secrets are loaded from environment variables.
  • Per-test overrides use BrowserConfig builders.
  • CI uses environment variables or a dedicated config file.
  • SB_* variables are documented for operators.