Type-safe browser automation toolkit for Allternit agent task execution.
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
npm install @allternit/browser-tools
The SDK depends on Playwright, which downloads browser binaries on install. If you need to install browsers separately:
npx playwright install
@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.
For HTTP APIs, format browser events as SSE using SSEEventStream:
import { sseEventStream } from '@allternit/browser-tools';const browserEvent = { id: 'evt-1', sessionId: session.id, timestamp: new Date(), type: 'navigation', payload: { to: 'https://example.com' },};const bytes = sseEventStream.formatBrowserEvent(browserEvent);
Safety and quarantine
Browser Tools includes a safety layer to restrict navigation, require approvals for sensitive actions, and maintain audit logs.
import { DEFAULT_SAFETY_POLICY, STRICT_SAFETY_POLICY, checkNavigationSafety, checkActionSafety, quarantineManager, approvalQueue,} from '@allternit/browser-tools';// Check whether a URL is allowedconst safety = checkNavigationSafety( 'https://example.com', DEFAULT_SAFETY_POLICY, 0);if (!safety.allowed) { console.log('Blocked:', safety.reason);}// Create a quarantine session with a custom policyquarantineManager.createSession(session.id, 'incognito', { allowedHosts: ['example.com', '*.example.com'], blockedHosts: ['localhost', '127.0.0.1'], allowedSchemes: ['https:'], maxNavigationDepth: 10, requireApprovalFor: ['click', 'type'], dataSensitivity: 'high',});// Check whether an action requires approvalconst actionSafety = checkActionSafety('click', '#submit', quarantineManager.getPolicy(session.id)!);if (actionSafety.requiresApproval) { approvalQueue.requestApproval({ id: 'approval-1', sessionId: session.id, action: 'click', target: '#submit', timestamp: new Date(), expiresAt: new Date(Date.now() + 60000), });}// Inspect the audit logconst log = quarantineManager.getAuditLog(session.id);
Built-in policies
Policy
Behavior
DEFAULT_SAFETY_POLICY
Allows all public hosts, blocks localhost and private networks, and requires approval for click, type, select, and clear actions.
STRICT_SAFETY_POLICY
Requires explicit host allowlists, allows only HTTPS, limits navigation depth, and requires approval for most actions.
Policy fields
Field
Description
allowedHosts
Host patterns that are allowed. Use * to allow all.
blockedHosts
Host patterns that are blocked, including wildcard and IP-range patterns.
allowedSchemes
Permitted URL schemes, such as https:.
maxNavigationDepth
Maximum number of navigations before further navigation is blocked.
requireApprovalFor
Action types that trigger an approval request.
dataSensitivity
low, medium, or high.
Tool registries
The SDK exposes grouped tool registries for use with agent tool-calling frameworks:
import { browserControlTools, domExtractionTools, actionTools,} from '@allternit/browser-tools';// Each registry maps a tool name to its functionconsole.log(Object.keys(browserControlTools));// ['browser.create_session', 'browser.close_session', 'browser.get_session_info', ...]console.log(Object.keys(actionTools));// ['browser.click', 'browser.type', 'browser.clear', ...]console.log(Object.keys(domExtractionTools));// ['extractContent', 'findElement']