Skip to main content
The palyra-browserd component is a specialized service responsible for high-fidelity browser automation and state management within the Palyra ecosystem. It integrates with Chromium via the headless_chrome crate to provide a programmable interface for agents and users to interact with the web while maintaining strict security boundaries and session persistence.

System Overview

The browser daemon operates as a standalone process that exposes a gRPC interface for control and an HTTP interface for health and relay operations. It manages a pool of browser sessions, each potentially backed by a persistent profile and protected by domain-level allowlists.

Key Responsibilities

Implementation & Data Flow

The daemon is initialized via the run function in the bootstrap module crates/palyra-browserd/src/lib.rs#12-12. It sets up a BrowserRuntimeState which serves as the central coordination point for all shared resources.

Code Entity Space Mapping

The following diagram illustrates how natural language concepts map to specific Rust structs and services within the palyra-browserd crate. Entity Relationship Diagram Sources: crates/palyra-browserd/src/transport/grpc/service.rs#9-11, crates/palyra-browserd/src/support/tests.rs#8-12, crates/palyra-browserd/src/engine/chromium.rs#71-75.

Session Lifecycle

Sessions are created via the create_session gRPC call. This process involves resolving a profile, checking for existing persisted state, and initializing a new HeadlessBrowser instance or tab.
  1. Authorization: The request is validated using the PRINCIPAL_HEADER and an optional auth token crates/palyra-browserd/src/transport/grpc/service.rs#33-38.
  2. Profile Resolution: If a profile_id is provided, the daemon loads the profile metadata and state encryption keys crates/palyra-browserd/src/transport/grpc/service.rs#42-48.
  3. Persistence Loading: If persistence is enabled, a PersistedSessionSnapshot is loaded from the PersistedStateStore crates/palyra-browserd/src/transport/grpc/service.rs#75-91.
  4. Budgeting: A SessionBudget is applied, defining limits for navigation timeouts, screenshot sizes, and action rates crates/palyra-browserd/src/transport/grpc/service.rs#107-161.

Action Flow: Navigation & Interaction

When an action like Navigate or Click is requested, the daemon executes a blocking task on the engine. Action Execution Sequence Sources: crates/palyra-cli/src/commands/browser.rs#201-218, crates/palyra-browserd/src/transport/grpc/service.rs#29-32, crates/palyra-browserd/src/support/tests.rs#2-8.

Download Handling & Sandboxing

The daemon provides a managed download system to prevent malicious files from reaching the host filesystem directly.

Security Implementation

Target Validation

The daemon enforces strict URL validation to prevent SSRF (Server-Side Request Forgery). The validate_target_url function checks if the requested URL is allowed based on the session’s action_allowed_domains and global settings like allow_private_targets crates/palyra-browserd/src/support/tests.rs#8-8.

State Encryption

Browser profiles are persisted using AES-GCM (ChaCha20-Poly1305) encryption.

Configuration Defaults

ParameterDefault ValueDescription
grpc_port7543gRPC service port crates/palyra-browserd/src/app/config.rs#3-3
max_sessions128Max concurrent browser sessions crates/palyra-browserd/src/app/config.rs#5-5
idle_ttl10 minutesSession timeout after inactivity crates/palyra-browserd/src/app/config.rs#4-4
max_screenshot_bytes256 KBMax size for captured screenshots crates/palyra-browserd/src/app/config.rs#8-8
max_tabs_per_session32Limit on tabs per browser instance crates/palyra-browserd/src/app/config.rs#25-25

CLI Integration

The Palyra CLI provides a comprehensive command set for interacting with palyra-browserd, including lifecycle management (start, stop, status) and session interaction (open, click, type, snapshot) crates/palyra-cli/src/args/browser.rs#4-175. Sources: crates/palyra-browserd/src/app/config.rs#1-100, crates/palyra-browserd/src/domain/downloads.rs#1-173, crates/palyra-browserd/src/transport/grpc/service.rs#1-161, crates/palyra-cli/src/commands/browser.rs#1-240.