Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:MarketSquare Robotframework browser Start Grpc Server

From Leeroopedia
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 .exe to 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_debug is set to PlaywrightLogTypes.playwright, it enables Playwright API-level debug output by setting DEBUG=pw:api
  • Node debug options guard: Logs a trace message noting that ROBOT_FRAMEWORK_BROWSER_NODE_DEBUG_OPTIONS is 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

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,
    )

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment