Skip to main content
The palyra-browserd service is a specialized daemon providing headless Chromium automation via a gRPC interface. It manages the lifecycle of browser sessions, profiles, and tabs, while enforcing strict security boundaries through target validation and isolated network proxies.

System Architecture

The daemon is built on top of the headless_chrome crate and provides a high-level abstraction for complex browser interactions like DOM observation, action retries, and state persistence.

Component Interaction Diagram

This diagram illustrates the relationship between the gRPC service, the runtime state, and the underlying browser engine. Title: Browser Daemon Internal Flow Sources: crates/palyra-browserd/src/transport/grpc/service.rs#9-11, crates/palyra-browserd/src/engine/chromium.rs#71-75, crates/palyra-browserd/src/lib.rs#36-40

Session Lifecycle & Management

The BrowserRuntimeState acts as the central orchestrator for all active browser sessions crates/palyra-browserd/src/transport/grpc/service.rs#10-11.
  1. Creation: Sessions are created via create_session with specific SessionBudget constraints (timeouts, max screenshot bytes, etc.) crates/palyra-browserd/src/transport/grpc/service.rs#29-107.
  2. Profiles: Sessions can be attached to a BrowserProfileRecord. If persistence_enabled is true, the daemon restores the session state (cookies, localStorage) from the PersistedStateStore crates/palyra-browserd/src/transport/grpc/service.rs#51-91.
  3. Idle TTL: The daemon automatically cleans up sessions that have been inactive longer than the idle_ttl_ms crates/palyra-browserd/src/transport/grpc/service.rs#95-99.
  4. Concurrency: The daemon enforces a max_sessions limit (default 128) to prevent resource exhaustion crates/palyra-browserd/src/lib.rs#84-84.

Session State Persistence

State is stored in an encrypted format using CHACHA20_POLY1305 crates/palyra-browserd/src/lib.rs#47-47. The PersistedStateStore manages profiles.enc and individual profile data blobs crates/palyra-browserd/src/lib.rs#131-140. Sources: crates/palyra-browserd/src/transport/grpc/service.rs#29-130, crates/palyra-browserd/src/lib.rs#131-145

Engine Integration & SOCKS5 Proxy

To ensure security and prevent Server-Side Request Forgery (SSRF), every browser session is isolated behind a per-session SOCKS5 proxy: ChromiumSessionProxy crates/palyra-browserd/src/engine/chromium.rs#71-75.

Security Flow: Target Validation

Title: Network Request Validation Pipeline Sources: crates/palyra-browserd/src/engine/chromium.rs#114-145, crates/palyra-browserd/src/security/target_validation.rs#184-206, crates/palyra-browserd/src/engine/chromium.rs#147-149 Key validation logic:

Download Management

Downloads are handled within a DownloadSandboxSession. Files are initially placed in a quarantine directory if they do not match the allowlisted extensions or MIME types crates/palyra-browserd/src/domain/downloads.rs#20-44. Sources: crates/palyra-browserd/src/domain/downloads.rs#20-173, crates/palyra-browserd/src/lib.rs#147-162

CLI Browser Commands

The palyra CLI provides a comprehensive suite of commands to interact with palyra-browserd.
CommandFunctionKey Code Entity
palyra browser startSpawns the daemon as a background processrun_browser_start
palyra browser openCreates a session and navigates to a URLrun_browser_open
palyra browser clickClicks a DOM element via CSS selectorrun_browser_click
palyra browser snapshotCaptures DOM, Accessibility Tree, and Textrun_browser_snapshot
palyra browser traceExports session debug artifactsBrowserCommand::Trace
Sources: crates/palyra-cli/src/commands/browser.rs#165-235, crates/palyra-cli/src/args/browser.rs#4-227

Implementation of run_browser_start

When starting the daemon, the CLI:
  1. Locates the palyra-browserd binary crates/palyra-cli/src/commands/browser.rs#74-74.
  2. Configures stdout/stderr log redirection to browserd.stdout.log crates/palyra-cli/src/commands/browser.rs#32-33.
  3. Writes a browser-service.json metadata file containing the PID and gRPC URL crates/palyra-cli/src/commands/browser.rs#71-80.
  4. Polls the health endpoint until the service is ready crates/palyra-cli/src/commands/browser.rs#29-29.
Sources: crates/palyra-cli/src/commands/browser.rs#1-108