agentBrowser
import { agentBrowser } from '@routecraft/os'
Automate a browser session using the agent-browser library. Each exchange gets an isolated session (derived from exchange.id), so split()/aggregate() flows work correctly. The adapter is an enricher: use with .to() or bare .enrich() (the AgentBrowserResult replaces the body; pass an aggregator such as only() to merge), or .tap() (result discarded). Requires agent-browser as a peer dependency.
Navigate and take a snapshot:
import { agentBrowser } from '@routecraft/os'
craft()
.id('scrape-page')
.from(simple({ url: 'https://example.com' }))
.to(agentBrowser('open', { url: (ex) => ex.body.url }))
.enrich(agentBrowser('snapshot', { json: true }))
.to(log())
// Result replaces the body: { stdout: '...', parsed: { snapshot: '...', refs: {...} }, exitCode: 0 }
Click an element and get text:
craft()
.id('click-and-read')
.from(source)
.to(agentBrowser('click', { selector: '#submit-btn' }))
.enrich(agentBrowser('get', { info: 'text', selector: '.result' }))
.to(log())
Dynamic URL from exchange body:
craft()
.id('dynamic-browse')
.from(simple({ link: 'https://example.com/page' }))
.enrich(agentBrowser('open', { url: (ex) => ex.body.link }))
.enrich(agentBrowser('snapshot'))
.to(log())
Close the session explicitly:
.to(agentBrowser('close'))
Commands:
Command-specific option values that accept Resolvable<T, V> can be a static value or a function (exchange) => value for dynamic resolution.
Base options (available on every command):
Result shape (AgentBrowserResult):