Browser Tools SDK

The Browser Tools SDK (@allternit/browser-tools) is a type-safe browser automation toolkit for Allternit agent task execution. It is built on Playwright and exposes high-level functions for session management, navigation, DOM extraction, element interaction, screenshots, real-time event streaming, and safety controls.

Overview

Use this SDK when you want to:
  • Control a browser programmatically from TypeScript or Node.js.
  • Extract structured page content such as links, forms, tables, and images.
  • Perform element actions like clicks, typing, selects, scrolls, hovers, and key presses.
  • Stream browser events such as navigation, DOM changes, clicks, inputs, and screenshots.
  • Enforce host restrictions, action approvals, and audit logging for agent-driven browsing.

Installation

The SDK depends on Playwright, which downloads browser binaries on install. If you need to install browsers separately:
@allternit/mcp-apps-adapter is a peer dependency for MCP-style tool registration. Install it if you are registering Browser Tools with an MCP server.

Quick start

Session management

A session represents an isolated browser context. Each session has its own viewport, lifecycle status, navigation history, and quarantine policy.
Navigate between pages and control browser history.
waitUntil accepts load, domcontentloaded, or networkidle.

Content extraction

Extract readable text and structured data from the current page.
extractContent returns an ExtractedContent object: findElement returns a DOMElement with tag, text, attributes, bounds, isVisible, isInteractive, and a generated selector.

Actions

Perform element-level interactions on the current page.
wait supports visible, hidden, attached, and detached states.

Event streaming

Subscribe to real-time browser events during a session.

Server-Sent Events

For HTTP APIs, format browser events as SSE using SSEEventStream:

Safety and quarantine

Browser Tools includes a safety layer to restrict navigation, require approvals for sensitive actions, and maintain audit logs.

Built-in policies

Policy fields

Tool registries

The SDK exposes grouped tool registries for use with agent tool-calling frameworks:

Types

All TypeScript types are exported from the package entry point:

Error handling

Most functions return a ToolResult<T> object that surfaces success, data, and errors without throwing.
Common error codes:

Browser support

The SDK uses Playwright and supports Chromium, Firefox, and WebKit. Chromium is the default browser engine.