Implementation:MarketSquare Robotframework browser Rfbrowser Init
| Knowledge Sources | |
|---|---|
| Domains | Browser_Automation, Dependency_Management |
| Last Updated | 2026-02-12 04:00 GMT |
Overview
Concrete tool for installing Node.js dependencies and Playwright browser binaries provided by the robotframework-browser library's rfbrowser init CLI command.
Description
The rfbrowser_init function is the core implementation behind the rfbrowser init CLI command. It performs the complete Node.js-side initialization of the Browser library in two phases:
Phase 1 -- Node.js Dependency Installation:
- Verifies that
package.jsonexists in theBrowser/wrapper/directory - Checks that the installation directory is writable
- Confirms that
npmis available in the system PATH - Runs
npm ci --production --parseable true --progress falseas a subprocess - Polls the subprocess output and logs progress
Phase 2 -- Browser Binary Installation (optional):
- Builds the command
npx --quiet playwright install - Appends specific browser names if requested (e.g.,
chromium,firefox) - Appends
--with-depsif system dependency installation is requested - On Unix systems with
ptysupport, uses a pseudo-terminal to display progress bars - On Windows or systems without
pty, falls back to standard subprocess polling
The function manages the PLAYWRIGHT_BROWSERS_PATH and PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD environment variables to control where and whether browser binaries are downloaded.
Usage
This function is called by the rfbrowser init CLI command. It can also be imported and called directly from Python code for programmatic initialization in custom setup scripts or CI pipelines.
Code Reference
Source Location
- Repository: robotframework-browser
- File:
Browser/entry/rfbrowser_init.py - Lines: 205-259
Signature
def rfbrowser_init(
skip_browser_install: bool,
silent_mode: bool,
with_deps: bool,
browser: list,
) -> None:
Import
from Browser.entry.rfbrowser_init import rfbrowser_init
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| skip_browser_install | bool |
Yes | When True, sets PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 and skips the npx playwright install step entirely
|
| silent_mode | bool |
Yes | When True, suppresses all log output (both console and file logging)
|
| with_deps | bool |
Yes | When True, appends --with-deps to the Playwright install command, causing system-level dependencies (fonts, libraries) to be installed automatically
|
| browser | list |
Yes | A list of browser names to install (e.g., ["chromium", "firefox"]); an empty list installs all default browsers
|
Outputs
| Name | Type | Description |
|---|---|---|
| return | None |
The function returns nothing on success |
| side effects | environment changes | Modifies PLAYWRIGHT_BROWSERS_PATH and potentially PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD environment variables; installs packages into Browser/wrapper/node_modules/
|
| exceptions | RuntimeError |
Raised if npm or npx processes exit with non-zero return codes, or if package.json is missing or the directory is not writable
|
Usage Examples
Basic Example
from Browser.entry.rfbrowser_init import rfbrowser_init
# Full initialization: install Node.js deps and all default browser binaries
rfbrowser_init(
skip_browser_install=False,
silent_mode=False,
with_deps=False,
browser=[],
)
Install Only Specific Browsers
from Browser.entry.rfbrowser_init import rfbrowser_init
# Install Node.js deps and only chromium and firefox binaries
rfbrowser_init(
skip_browser_install=False,
silent_mode=False,
with_deps=False,
browser=["chromium", "firefox"],
)
CI Environment With System Dependencies
from Browser.entry.rfbrowser_init import rfbrowser_init
# Silent mode for CI, with automatic system dependency installation
rfbrowser_init(
skip_browser_install=False,
silent_mode=True,
with_deps=True,
browser=["chromium"],
)
Skip Browser Download
from Browser.entry.rfbrowser_init import rfbrowser_init
# Only install Node.js dependencies, skip browser binaries
rfbrowser_init(
skip_browser_install=True,
silent_mode=False,
with_deps=False,
browser=[],
)
CLI Equivalent Commands
# Full init (all browsers)
rfbrowser init
# Specific browsers only
rfbrowser init chromium firefox
# With system dependencies for CI
rfbrowser init --with-deps
# Skip browser download
rfbrowser init --skip-browsers
# Silent mode
rfbrowser --silent init