Skip to main content
The Palyra Browser Extension (Relay Companion) is a Manifest V3 compliant tool designed to bridge the gap between a user’s active browsing session and the Palyra Daemon (palyrad). It enables secure, local-only relaying of DOM snapshots, screenshots, and browser actions to the daemon’s loopback interface, allowing agents to interact with the user’s real-time web context without requiring full remote control of the browser.

Architecture and Data Flow

The extension consists of a background service worker for orchestration, a content script for DOM manipulation, and a popup UI for configuration. It communicates exclusively with the local daemon via a validated loopback URL. Relay Communication Overview Code Entity Map: Communication Flow Sources: apps/browser-extension/background.js#159-187, apps/browser-extension/popup.js#27-33, apps/browser-extension/content_script.js#184-208

Core Components

1. Content Script (DOM/Text Capture)

The content_script.js is responsible for extracting page content. It avoids high-overhead properties like outerHTML or innerText to prevent browser hangs on large pages. Instead, it performs a manual, capped traversal of the DOM tree.

2. Background Service Worker

The background.js script acts as the central relay hub. It manages extension state, handles messages from the popup, and dispatches actions to the daemon.

3. Relay Actions

The extension supports three primary relay actions defined in the dispatchRelayAction logic:
ActionFunctionDescription
open_tabrunRelayOpenTabOpens a URL in a new tab, guarded by an allowlist apps/browser-extension/background.js#189-200.
capture_selectionrunRelayCaptureSelectionCaptures a specific DOM element via CSS selector apps/browser-extension/background.js#202-214.
send_page_snapshotrunRelaySendPageSnapshotSends the full URL, Title, and DOM snapshot to the daemon apps/browser-extension/background.js#216-224.

Security Posture

The extension implements a “Narrow Capability” security model to minimize the attack surface of the browser-to-daemon bridge. Logic Flow: URL Validation & Safety Sources: apps/browser-extension/lib.mjs#126-192, apps/browser-extension/README.md#15-21

Technical Constants

ConstantValueSource
DEFAULT_RELAY_BASE_URLhttp://127.0.0.1:7142apps/browser-extension/lib.mjs#1
MAX_EXTENSION_ID_BYTES128apps/browser-extension/lib.mjs#7
MAX_SESSION_ID_BYTES128apps/browser-extension/lib.mjs#8
MAX_RELAY_TOKEN_BYTES2,048apps/browser-extension/lib.mjs#9
Sources: apps/browser-extension/lib.mjs#1-12, apps/browser-extension/background.js#1-15, apps/browser-extension/content_script.js#1-53