HerdClient

The HerdClient is the main entry point for interacting with the Herd platform. It provides methods for managing devices, pages, and executing browser automation commands.

Installation

npm install @monitoro/herd
# or
yarn add @monitoro/herd

Usage

import { HerdClient } from '@monitoro/herd';

// Create a client instance
const client = new HerdClient({
    token: 'your-auth-token' // Get your token at herd.garden
});

// Initialize the client
await client.initialize();

Methods

initialize()

Initializes the client by establishing connections to the Herd platform. Must be called before using other methods.

await client.initialize();

listDevices()

Returns a list of all available devices.

const devices = await client.listDevices();
console.log('Available devices:', devices);

getDevice(deviceId)

Gets a specific device by ID.

const device = await client.getDevice('device-123');

registerDevice(options)

Registers a new device with the platform.

const device = await client.registerDevice({
    deviceId: 'my-device',
    type: 'browser',
    name: 'My Test Browser'
});

sendCommand(deviceId, command, params)

Sends a command to a specific device. This is a low-level method that allows you to send arbitrary commands to a device and is not recommended for most use cases.

const result = await client.sendCommand('device-123', 'Page.click', {
    selector: '#submit-button'
});

subscribeToDeviceEvents(deviceId, callback)

Subscribes to all events from a device.

const unsubscribe = client.subscribeToDeviceEvents('device-123', (event) => {
    console.log('Device event:', event);
});

// Later: unsubscribe to stop receiving events
unsubscribe();

subscribeToDeviceEvent(deviceId, eventName, callback)

Subscribes to a specific event from a device.

const unsubscribe = client.subscribeToDeviceEvent('device-123', 'navigation', (event) => {
    console.log('Navigation event:', event);
});

close()

Closes the client and cleans up resources.

await client.close();
No headings found
Last updated: 4/2/2025