Implementation:MarketSquare Robotframework browser Start Grpc Server
| Knowledge Sources | |
|---|---|
| Domains | Browser_Automation, Installation |
| Last Updated | 2026-02-12 04:00 GMT |
Overview
Concrete tool for launching a prebuilt gRPC server binary provided by the BrowserBatteries package within the robotframework-browser library.
Description
The start_grpc_server function is the entry point used by the BrowserBatteries installation path to start the Playwright gRPC server without requiring a Node.js runtime. It locates the prebuilt platform-specific binary (grpc_server on Unix, grpc_server.exe on Windows) within the BrowserBatteries/bin/ directory and spawns it as a subprocess.
The function performs several setup steps before launching the server:
- OS-specific binary selection: On Windows (
os.name == "nt"), it appends.exeto the binary name - PLAYWRIGHT_BROWSERS_PATH configuration: If the environment variable is not already set, it defaults to
"0", which tells Playwright to look for browsers relative to the package directory - Playwright debug logging: When
enable_playwright_debugis set toPlaywrightLogTypes.playwright, it enables Playwright API-level debug output by settingDEBUG=pw:api - Node debug options guard: Logs a trace message noting that
ROBOT_FRAMEWORK_BROWSER_NODE_DEBUG_OPTIONSis not supported in BrowserBatteries mode
The server is started via subprocess.Popen with its working directory set to the bin/ folder, and stdout/stderr is redirected to the provided log file handle.
Usage
This function is called internally by the Browser library when it detects that the BrowserBatteries package is installed. Users do not typically call this function directly. It is invoked during library initialization to replace the standard Node.js-based gRPC server startup.
Code Reference
Source Location
- Repository: robotframework-browser
- File:
browser_batteries/BrowserBatteries/__init__.py - Lines: 27-57
Signature
def start_grpc_server(
logfile: TextIO,
host: str,
port: str,
enable_playwright_debug: "PlaywrightLogTypes | bool",
) -> Popen:
Import
from BrowserBatteries import start_grpc_server
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| logfile | TextIO |
Yes | A writable file-like object where the gRPC server stdout and stderr output will be redirected |
| host | str |
Yes | The hostname or IP address on which the gRPC server should listen (e.g., "127.0.0.1")
|
| port | str |
Yes | The TCP port number for the gRPC server to bind to (e.g., "0" for auto-assignment)
|
| enable_playwright_debug | bool | Yes | Controls Playwright debug logging; when set to PlaywrightLogTypes.playwright, sets DEBUG=pw:api in the environment
|
Outputs
| Name | Type | Description |
|---|---|---|
| return | Popen |
A subprocess.Popen instance representing the running gRPC server process, which can be used to monitor or terminate it
|
Usage Examples
Basic Example
import sys
from BrowserBatteries import start_grpc_server
# Start gRPC server on localhost with auto-assigned port
with open("grpc_server.log", "w") as logfile:
process = start_grpc_server(
logfile=logfile,
host="127.0.0.1",
port="0",
enable_playwright_debug=False,
)
print(f"gRPC server started with PID: {process.pid}")
# ... use the server ...
process.terminate()
process.wait()
With Playwright Debug Logging
from BrowserBatteries import start_grpc_server
from Browser.utils.data_types import PlaywrightLogTypes
with open("grpc_debug.log", "w") as logfile:
process = start_grpc_server(
logfile=logfile,
host="127.0.0.1",
port="8282",
enable_playwright_debug=PlaywrightLogTypes.playwright,
)