botonomus.browser¶
Executable discovery, the Chrome backend, launch arguments and the Botonomus Chromium installer.
botonomus.browser
¶
Browser executables, processes, installed builds and the Chrome backend.
BUILD_MARKER
module-attribute
¶
File placed next to the executable of every Botonomus Chromium build.
Backend
¶
Bases: Protocol
Starts browsers and guarantees their shutdown.
launch
async
¶
launch(profile_path: Path, config: BrowserConfig) -> BrowserHandle
Launch a browser for profile_path and attach to it.
Raises:
| Type | Description |
|---|---|
BrowserUnavailableError
|
If no executable is available. |
BrowserStartupError
|
If the process or attachment fails; anything started has been cleaned up. |
BrowserCleanupError
|
If a failed launch left processes that could not be confirmed stopped. |
close
async
¶
Stop every browser this backend owns and release shared resources.
Raises:
| Type | Description |
|---|---|
BrowserCleanupError
|
If any owned browser could not be confirmed stopped; ownership is retained. |
BrowserHandle
¶
Bases: Protocol
One running browser attached to a dedicated profile.
context
property
¶
The browser context (native Context or a Playwright BrowserContext).
close
async
¶
Stop the browser.
Returns only after every owned process is confirmed stopped.
Raises:
| Type | Description |
|---|---|
BrowserCleanupError
|
If that cannot be confirmed. |
ChromeBackend
¶
ChromeBackend(driver: DriverName | Driver = 'native')
Launches Chrome (or a named Chromium build) and attaches a driver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
driver
|
DriverName | Driver
|
A driver name, or a |
'native'
|
start
async
¶
Start the driver runtime. Idempotent.
Raises:
| Type | Description |
|---|---|
BrowserStartupError
|
If the driver cannot start. |
launch
async
¶
launch(profile_path: Path, config: BrowserConfig) -> ChromeHandle
Launch a browser for profile_path and attach the driver.
Raises:
| Type | Description |
|---|---|
BrowserUnavailableError
|
If no executable is found. |
ConfigurationError
|
If |
BrowserStartupError
|
If launch, attachment or the virtual display fails or times out. |
BrowserCleanupError
|
If a failed launch could not be cleaned up. |
close
async
¶
Stop every owned browser, then the virtual display and the driver runtime.
Raises:
| Type | Description |
|---|---|
BrowserCleanupError
|
If any owned browser could not be stopped; the driver is left running and ownership retained. The virtual display is stopped regardless, so no Xvfb server outlives the manager. |
ChromeHandle
¶
One launched browser process, its attachment and its proxy forwarder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
process
|
Process
|
The browser's root process. |
required |
timeout
|
float
|
Seconds for the whole close sequence (graceful, then forced). |
required |
context
property
¶
The driver's browser context.
Raises:
| Type | Description |
|---|---|
BrowserStartupError
|
If the driver has not attached yet. |
page
property
¶
The driver's initial page.
Raises:
| Type | Description |
|---|---|
BrowserStartupError
|
If the driver has not attached yet. |
close
async
¶
Close gracefully, then terminate owned processes. Idempotent and shielded.
Raises:
| Type | Description |
|---|---|
BrowserCleanupError
|
If owned processes could not be confirmed stopped. |
VirtualDisplay
¶
VirtualDisplay(*, width: int = 1920, height: int = 1080, depth: int = 24, executable: str = 'Xvfb', start_timeout: float = 10.0)
An Xvfb server shared by the browsers of one manager.
Xvfb picks a free display number itself (-displayfd), so concurrent managers
and processes never race for the same display.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
int
|
Screen width in pixels. |
1920
|
height
|
int
|
Screen height in pixels. |
1080
|
depth
|
int
|
Colour depth. |
24
|
executable
|
str
|
The Xvfb program. |
'Xvfb'
|
start_timeout
|
float
|
Seconds to wait for the server to report its display. |
10.0
|
Attributes:
| Name | Type | Description |
|---|---|---|
display |
str | None
|
|
width |
Screen width. |
|
height |
Screen height. |
start
async
¶
Start the server. Idempotent.
Raises:
| Type | Description |
|---|---|
BrowserStartupError
|
If Xvfb is missing, fails or does not report a display in time. The server is stopped on any failure, including cancellation. |
InstalledBinary
dataclass
¶
InstalledBinary(version: str, chromium_version: str, channel: str, platform: str, sha256: str, installed_at: datetime, directory: Path, executable: Path)
A complete, verified Botonomus Chromium install on disk.
Attributes:
| Name | Type | Description |
|---|---|---|
version |
str
|
Botonomus build version, e.g. |
chromium_version |
str
|
Upstream Chromium version. |
channel |
str
|
Release channel the build came from. |
platform |
str
|
Platform tag of the build, e.g. |
sha256 |
str
|
SHA-256 of the archive the install was unpacked from. |
installed_at |
datetime
|
When the install completed (UTC). |
directory |
Path
|
The install directory |
executable |
Path
|
The browser executable inside |
launch_arguments
¶
launch_arguments(executable: Path, profile_path: Path, port: int, config: BrowserConfig, *, proxy_server: str | None = None, platform_args: Sequence[str] = ()) -> list[str]
Build the full browser command line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
executable
|
Path
|
Browser executable. |
required |
profile_path
|
Path
|
Dedicated |
required |
port
|
int
|
Explicit, nonzero loopback debugging port. |
required |
config
|
BrowserConfig
|
Session configuration. |
required |
proxy_server
|
str | None
|
Credential-free |
None
|
platform_args
|
Sequence[str]
|
Flags the platform needs (container flags, virtual-display
window geometry), placed before the user's |
()
|
Returns:
| Type | Description |
|---|---|
list[str]
|
Arguments in launch order, ending with the initial |
find_botonomus_chromium
¶
find_botonomus_chromium(version: str | None = None, *, cache_dir: Path | None = None) -> Path | None
Return the executable of an installed Botonomus Chromium build, if any.
Not consulted by find_chrome; callers decide the precedence between an
installed Botonomus build and Google Chrome.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
str | None
|
A specific build version, or |
None
|
cache_dir
|
Path | None
|
Botonomus data directory; |
None
|
Returns:
| Type | Description |
|---|---|
Path | None
|
The executable path, or |
Raises:
| Type | Description |
|---|---|
ConfigurationError
|
If |
find_chrome
¶
Return the browser executable to launch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
explicit
|
Path | None
|
A caller-supplied executable. When given, it is the only candidate. |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
The resolved path of an existing executable. |
Raises:
| Type | Description |
|---|---|
BrowserUnavailableError
|
If |
is_botonomus_build
¶
Whether executable is a Botonomus Chromium build.
True when the build marker sits next to the executable, or the executable lives
inside a verified install made by
botonomus.browser.install. Blocking.
is_testing_build
¶
Whether executable looks like Chrome for Testing or a Playwright download.
Those builds show a permanent "only for automated testing" infobar, which also shrinks the viewport, and are not what ordinary users run.
container_flags
¶
Flags Chrome needs in containers. None of them is visible to pages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
platform
|
str
|
|
required |
shm_bytes
|
int | None
|
Size of |
required |
euid
|
int | None
|
Effective user id, or |
required |
Returns:
| Type | Description |
|---|---|
str
|
|
...
|
default is 64 MB, which crashes renderers), and |
tuple[str, ...]
|
as root, where Chrome refuses to start otherwise. |
needs_virtual_display
¶
needs_virtual_display(config: BrowserConfig, platform: str = platform, environ: Mapping[str, str] = environ) -> bool
Whether a launch under config should run on a virtual display.
Headless sessions never need one. virtual_display=None (the default) means:
on Linux, when neither DISPLAY nor WAYLAND_DISPLAY is set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
BrowserConfig
|
Session configuration. |
required |
platform
|
str
|
|
platform
|
environ
|
Mapping[str, str]
|
Process environment. |
environ
|
Raises:
| Type | Description |
|---|---|
ConfigurationError
|
If |
find_installed
¶
Return the executable of the newest (or the given) install for this platform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
str | None
|
A specific build version, or |
None
|
cache_dir
|
Path | None
|
Botonomus data directory; |
None
|
Returns:
| Type | Description |
|---|---|
Path | None
|
The executable path, or |
Raises:
| Type | Description |
|---|---|
ConfigurationError
|
If |
install
async
¶
install(*, version: str | None = None, manifest_url: str | None = None, cache_dir: Path | None = None, progress: ProgressCallback | None = None, public_key: bytes = RELEASE_PUBLIC_KEY, allow_insecure_loopback: bool = False, timeout: float = 60.0) -> InstalledBinary
Download, verify and install Botonomus Chromium for this platform.
Returns immediately, without network access, when version is given and
already installed. Otherwise the manifest is fetched and verified first; if its
release is already installed that install is returned. Concurrent installs into
the same cache_dir, from any process, are serialised by a file lock.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
str | None
|
A specific build version; |
None
|
manifest_url
|
str | None
|
Channel manifest URL. |
None
|
cache_dir
|
Path | None
|
Botonomus data directory; |
None
|
progress
|
ProgressCallback | None
|
Called on the event loop thread as |
None
|
public_key
|
bytes
|
Release verification key. Only tests should change this. |
RELEASE_PUBLIC_KEY
|
allow_insecure_loopback
|
bool
|
Accept |
False
|
timeout
|
float
|
Socket timeout in seconds for each network operation. |
60.0
|
Returns:
| Type | Description |
|---|---|
InstalledBinary
|
The installed binary. |
Raises:
| Type | Description |
|---|---|
ConfigurationError
|
If |
BinaryDownloadError
|
If the manifest, signature or archive cannot be fetched. |
BinaryVerificationError
|
If the signature, manifest, archive size or hash, or an archive entry fails verification. |
BinaryNotInstalledError
|
If the release has no build for this platform. |
OSError
|
On local filesystem failures such as a full disk. |
installed_binaries
¶
installed_binaries(cache_dir: Path | None = None) -> list[InstalledBinary]
List complete installs, newest version first.
Directories without a valid installed.json record or whose executable is
missing are ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cache_dir
|
Path | None
|
Botonomus data directory; |
None
|
Returns:
| Type | Description |
|---|---|
list[InstalledBinary]
|
Installed binaries for every platform found, sorted by version descending. |
uninstall
¶
Remove an install.
The directory is first renamed out of place, so a partially deleted install is
never mistaken for a valid one; leftovers are cleaned by the next install.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
str
|
The build version to remove. |
required |
cache_dir
|
Path | None
|
Botonomus data directory; |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
|
Raises:
| Type | Description |
|---|---|
ConfigurationError
|
If |
OSError
|
If the files are in use (for example by a running browser). |
executable_sha256
¶
SHA-256 of the executable's bytes, or None if it cannot be read. Blocking.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
executable
|
Path
|
The browser executable. |
required |
executable_version
¶
Return the browser version for executable, or None if unknown.
Chrome installs on Windows keep a sibling directory named after the version
(Application/141.0.7390.55); the highest such name is used. Otherwise, on
Windows, the executable's VS_FIXEDFILEINFO version resource is read.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
executable
|
Path
|
The browser executable. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
A dotted version such as |