Class: Page

Represents a web page and provides methods to interact with it.

Constructors

new Page()

new Page(page: Page, agent: Agent, opts?: {apiKey: string;disableMemory: boolean;endpoint: string;inventory: Inventory;logger: Logger;pageId: string; }): Page

Creates a new Page instance.

Parameters

ParameterTypeDescription
pagePageThe PuppeteerPage object representing the browser page.
agentAgentThe Agent object representing the user agent interacting with the page.
opts?objectOptional parameters for additional configuration.
opts.apiKey?stringAn optional API key for accessing collective memory.
opts.disableMemory?boolean-
opts.endpoint?stringAn optional endpoint for collective memory.
opts.inventory?InventoryAn optional inventory object for storing and retrieving user data.
opts.logger?LoggerAn optional logger for logging events; if not provided, logging may be absent.
opts.pageId?stringAn optional unique identifier for the page; if not provided, a UUID will be generated.

Returns

Page

Defined in

src/browser/page.ts:68

Properties

agent

agent: Agent

Defined in

src/browser/page.ts:51


error

error: undefined | string

Defined in

src/browser/page.ts:55


logger?

optional logger: Logger

Defined in

src/browser/page.ts:52


page

page: Page

Defined in

src/browser/page.ts:42


pageId

pageId: string

Defined in

src/browser/page.ts:50


progress

progress: string[] = []

Defined in

src/browser/page.ts:53

Methods

browse()

browse(objective: string, opts: {agent: Agent;inventory: Inventory;maxTurns: number;progress: string[];schema: ZodObject<any, UnknownKeysParam, ZodTypeAny, {}, {}>; }): Promise<{command: ({index: number;kind: "Click"; } | {index: number;kind: "Type";text: string; } | {kind: "Back"; } | {kind: "Wait"; })[];description: string;objectiveComplete: updatedObjectiveComplete;progressAssessment: string; } | {objectiveFailed: {kind: "ObjectiveFailed";result: failureReason;url: string; }; }>

Browses the page based on the request and return type.

Parameters

ParameterTypeDescription
objectivestring-
optsobjectAdditional options.
opts.agent?AgentThe agent to use (optional).
opts.inventory?InventoryThe inventory object (optional).
opts.maxTurnsnumberThe maximum number of turns to browse.
opts.progress?string[]The progress towards the objective (optional).
opts.schema?ZodObject<any, UnknownKeysParam, ZodTypeAny, {}, {}>The Zod schema for the return type.

Returns

Promise<{command: ({index: number;kind: "Click"; } | {index: number;kind: "Type";text: string; } | {kind: "Back"; } | {kind: "Wait"; })[];description: string;objectiveComplete: updatedObjectiveComplete;progressAssessment: string; } | {objectiveFailed: {kind: "ObjectiveFailed";result: failureReason;url: string; }; }>

A promise that resolves to the retrieved data.

Defined in

src/browser/page.ts:634


close()

close(): Promise<void>

Closes the page.

Returns

Promise<void>

Defined in

src/browser/page.ts:154


content()

content(): Promise<string>

Returns the text content of the page.

Returns

Promise<string>

A promise that resolves to the text content of the page.

Defined in

src/browser/page.ts:102


do()

do(request: string, opts?: {agent: Agent;delay: number;inventory: Inventory;progress: string[];schema: ZodType<any, ZodTypeDef, any>; }): Promise<void>

Performs a request on the page.

Parameters

ParameterTypeDescription
requeststringThe request or objective.
opts?objectAdditional options.
opts.agent?AgentThe agent to use (optional).
opts.delay?numberThe delay in milliseconds after performing the action (default: 100).
opts.inventory?InventoryThe inventory object (optional).
opts.progress?string[]The progress towards the objective (optional).
opts.schema?ZodType<any, ZodTypeDef, any>The Zod schema for the return type.

Returns

Promise<void>

Defined in

src/browser/page.ts:511


followRoute()

followRoute(memoryId: string, opts?: {delay: number;inventory: Inventory;maxTurns: number;schema: ZodObject<any, UnknownKeysParam, ZodTypeAny, {}, {}>; }): Promise<any>

Follows a route based on a memory sequence.

Parameters

ParameterTypeDescription
memoryIdstringThe memory sequence ID.
opts?objectAdditional options.
opts.delay?numberThe delay in milliseconds after performing the action (default: 100).
opts.inventory?InventoryThe inventory object (optional).
opts.maxTurns?numberThe maximum number of turns to follow the route. Currently not used.
opts.schema?ZodObject<any, UnknownKeysParam, ZodTypeAny, {}, {}>-

Returns

Promise<any>

A promise that resolves to the retrieved data.

Throws

An error is thrown if no memories are found for the memory sequence ID.

Defined in

src/browser/page.ts:710


generateCommand()

generateCommand<T>(request: string, opts: {agent: Agent;inventory: Inventory;progress: string[];schema: T; }): Promise<TypeOf<T>>

Generates a command based on the request and current state.

Type Parameters

Type Parameter
T extends ZodType<any, ZodTypeDef, any>

Parameters

ParameterTypeDescription
requeststringThe request or objective.
optsobjectAdditional options.
opts.agent?AgentThe agent to use (optional).
opts.inventory?InventoryThe inventory object (optional).
opts.progress?string[]The progress towards the objective (optional).
opts.schemaTThe Zod schema for the return type.

Returns

Promise<TypeOf<T>>

Defined in

src/browser/page.ts:474


get()

get<T>(request: string, outputSchema: ZodType<any, ZodTypeDef, any>, opts?: {agent: Agent;mode: "text" | "html" | "aria" | "markdown" | "image";progress: string[]; }): Promise<TypeOf<T>>

Retrieves data from the page based on the request and return type.

Type Parameters

Type ParameterDescription
T extends ZodType<any, ZodTypeDef, any>The type of the return value.

Parameters

ParameterTypeDefault valueDescription
requeststringundefinedThe request or objective.
outputSchemaZodType<any, ZodTypeDef, any>ObjectiveCompleteThe Zod schema for the return type.
opts?objectundefinedAdditional options.
opts.agent?AgentundefinedThe agent to use (optional).
opts.mode?"text" | "html" | "aria" | "markdown" | "image"undefined-
opts.progress?string[]undefinedThe progress towards the objective (optional).

Returns

Promise<TypeOf<T>>

A promise that resolves to the retrieved data.

Defined in

src/browser/page.ts:546


getState()

getState(): undefined | {ariaTree: string;kind: "ObjectiveState";objective: string;progress: string[];url: string; }

Returns the current state of the page.

Returns

undefined | {ariaTree: string;kind: "ObjectiveState";objective: string;progress: string[];url: string; }

The objective state of the page.

Defined in

src/browser/page.ts:347


goto()

goto(url: string, opts?: {delay: number; }): Promise<void>

Navigates to a URL.

Parameters

ParameterTypeDescription
urlstringThe URL to navigate to.
opts?objectThe navigation options.
opts.delay?numberThe delay in milliseconds after navigating to the URL.

Returns

Promise<void>

Defined in

src/browser/page.ts:189


html()

html(): Promise<string>

Returns the HTML content of the page.

Returns

Promise<string>

A promise that resolves to the HTML content of the page.

Defined in

src/browser/page.ts:132


injectBoundingBoxes()

injectBoundingBoxes(): Promise<void>

Injects bounding boxes around clickable elements on the page.

Returns

Promise<void>

Defined in

src/browser/page.ts:742


makePrompt()

makePrompt(request: string, opts?: {agent: Agent;inventory: Inventory;progress: string[]; }): Promise<{prompt: CoreMessage[];state: {ariaTree: string;kind: "ObjectiveState";objective: string;progress: string[];url: string; }; }>

Creates a prompt for the agent based on the request and current state.

Parameters

ParameterTypeDescription
requeststringThe request or objective.
opts?objectThe navigation options.
opts.agent?AgentThe agent to create the prompt for.
opts.inventory?Inventory-
opts.progress?string[]The progress of the objective (optional).

Returns

Promise<{prompt: CoreMessage[];state: {ariaTree: string;kind: "ObjectiveState";objective: string;progress: string[];url: string; }; }>

A promise that resolves to the created prompt.

prompt

prompt: CoreMessage[]

state

state: {ariaTree: string;kind: "ObjectiveState";objective: string;progress: string[];url: string; }

state.ariaTree

ariaTree: string

state.kind

kind: "ObjectiveState"

state.objective

objective: string

state.progress

progress: string[]

state.url

url: string

Defined in

src/browser/page.ts:442


markdown()

markdown(): Promise<string>

Returns the Markdown representation of the page's HTML content.

Returns

Promise<string>

A promise that resolves to the Markdown content of the page.

Defined in

src/browser/page.ts:139


parseContent()

parseContent(): Promise<string>

Parses the content of the page and returns a simplified accessibility tree.

Returns

Promise<string>

A promise that resolves to the simplified accessibility tree as a JSON string.

Defined in

src/browser/page.ts:310


performAction()

performAction(command: {index: number;kind: "Click"; } | {index: number;kind: "Type";text: string; } | {index: number;kind: "Enter"; } | {kind: "Back"; } | {kind: "Wait"; } | {index: number;kind: "Hover"; } | {direction: "up" | "down";kind: "Scroll"; } | {kind: "GoTo";url: string; } | {kind: "Get";request: string;type: "text" | "html" | "aria" | "markdown" | "image"; }, opts?: {delay: number;inventory: Inventory; }): Promise<void>

Performs a browser action on the page.

Parameters

ParameterTypeDescription
command{index: number;kind: "Click"; } | {index: number;kind: "Type";text: string; } | {index: number;kind: "Enter"; } | {kind: "Back"; } | {kind: "Wait"; } | {index: number;kind: "Hover"; } | {direction: "up" | "down";kind: "Scroll"; } | {kind: "GoTo";url: string; } | {kind: "Get";request: string;type: "text" | "html" | "aria" | "markdown" | "image"; }The browser action to perform.
opts?objectAdditional options.
opts.delay?numberThe delay in milliseconds after performing the action (default: 100).
opts.inventory?InventoryThe inventory object (optional).

Returns

Promise<void>

Defined in

src/browser/page.ts:358


performManyActions()

performManyActions(commands: ({index: number;kind: "Click"; } | {index: number;kind: "Type";text: string; } | {index: number;kind: "Enter"; } | {kind: "Back"; } | {kind: "Wait"; } | {index: number;kind: "Hover"; } | {direction: "up" | "down";kind: "Scroll"; } | {kind: "GoTo";url: string; } | {kind: "Get";request: string;type: "text" | "html" | "aria" | "markdown" | "image"; })[], opts?: {delay: number;inventory: Inventory; }): Promise<void>

Performs multiple browser actions on the page.

Parameters

ParameterTypeDescription
commands({index: number;kind: "Click"; } | {index: number;kind: "Type";text: string; } | {index: number;kind: "Enter"; } | {kind: "Back"; } | {kind: "Wait"; } | {index: number;kind: "Hover"; } | {direction: "up" | "down";kind: "Scroll"; } | {kind: "GoTo";url: string; } | {kind: "Get";request: string;type: "text" | "html" | "aria" | "markdown" | "image"; })[]An array of browser actions to perform.
opts?objectAdditional options.
opts.delay?numberThe delay in milliseconds after performing the action (default: 100).
opts.inventory?InventoryThe inventory object (optional).

Returns

Promise<void>

Defined in

src/browser/page.ts:425


performMemory()

performMemory(memory: {actionStep: {command: any;description: string;objectiveComplete: {kind: "ObjectiveComplete";result: string; } | {};progressAssessment: string; };objectiveState: ObjectiveState; }, opts?: {agent: Agent;delay: number;inventory: Inventory;memoryDelay: number;schema: ZodObject<any, UnknownKeysParam, ZodTypeAny, {}, {}>; }): Promise<any>

Performs a memory on a page

Parameters

ParameterTypeDescription
memoryobjectThe memory to perform
memory.actionStepobject-
memory.actionStep.command?any-
memory.actionStep.description?string-
memory.actionStep.objectiveComplete?{kind: "ObjectiveComplete";result: string; } | {}-
memory.actionStep.progressAssessment?string-
memory.objectiveState?object-
memory.objectiveState.ariaTree?string-
memory.objectiveState.kind?"ObjectiveState"-
memory.objectiveState.objective?string-
memory.objectiveState.progress?string[]-
memory.objectiveState.url?string-
opts?objectAdditional options
opts.agent?Agent-
opts.delay?numberThe delay in milliseconds after performing the action (default: 100).
opts.inventory?InventoryThe inventory object (optional).
opts.memoryDelay?number-
opts.schema?ZodObject<any, UnknownKeysParam, ZodTypeAny, {}, {}>The Zod schema for the return type (optional).

Returns

Promise<any>

Oaram

opts.agent The agent to use (optional). Defaults to page agent.

Oaram

opts.memoryDelay The delay in milliseconds after performing the memory (optional).

Defined in

src/browser/page.ts:674


returnErrorState()

returnErrorState(failureReason: string): Promise<{objectiveFailed: {kind: "ObjectiveFailed";result: failureReason;url: string; }; }>

Parameters

ParameterType
failureReasonstring

Returns

Promise<{objectiveFailed: {kind: "ObjectiveFailed";result: failureReason;url: string; }; }>

objectiveFailed

objectiveFailed: {kind: "ObjectiveFailed";result: failureReason;url: string; }

objectiveFailed.kind

kind: string = "ObjectiveFailed"

objectiveFailed.result

result: string = failureReason

objectiveFailed.url

url: string

Defined in

src/browser/page.ts:609


screenshot()

screenshot(): Promise<Buffer>

Takes a screenshot of the page.

Returns

Promise<Buffer>

A promise that resolves to the screenshot buffer

Defined in

src/browser/page.ts:124


setViewport()

setViewport(width: number, height: number, deviceScaleFactor: number): Promise<void>

Sets the viewport size of the page.

Parameters

ParameterTypeDefault valueDescription
widthnumberundefinedThe width of the viewport.
heightnumberundefinedThe height of the viewport.
deviceScaleFactornumber1The device scale factor (default: 1).

Returns

Promise<void>

Defined in

src/browser/page.ts:112


state()

state(objective: string, objectiveProgress?: string[]): Promise<{ariaTree: string;kind: "ObjectiveState";objective: string;progress: string[];url: string; }>

Retrieves the current state of the page based on the objective and progress.

Parameters

ParameterTypeDescription
objectivestringThe objective of the page.
objectiveProgress?string[]The progress of the objective.

Returns

Promise<{ariaTree: string;kind: "ObjectiveState";objective: string;progress: string[];url: string; }>

A promise that resolves to the objective state of the page.

ariaTree

ariaTree: string

kind

kind: "ObjectiveState"

objective

objective: string

progress

progress: string[]

url

url: string

Defined in

src/browser/page.ts:326


step()

step(objective: string, outputSchema?: ZodObject<any, UnknownKeysParam, ZodTypeAny, {}, {}>, opts?: {agent: Agent;delay: number;inventory: Inventory;progress: string[]; }): Promise<{command: ({index: number;kind: "Click"; } | {index: number;kind: "Type";text: string; } | {kind: "Back"; } | {kind: "Wait"; })[];description: string;objectiveComplete: updatedObjectiveComplete;progressAssessment: string; }>

Take the next step towards the objective.

Parameters

ParameterTypeDescription
objectivestring-
outputSchema?ZodObject<any, UnknownKeysParam, ZodTypeAny, {}, {}>-
opts?objectAdditional options.
opts.agent?AgentThe agent to use (optional).
opts.delay?number-
opts.inventory?InventoryThe inventory object (optional).
opts.progress?string[]The progress towards the objective (optional).

Returns

Promise<{command: ({index: number;kind: "Click"; } | {index: number;kind: "Type";text: string; } | {kind: "Back"; } | {kind: "Wait"; })[];description: string;objectiveComplete: updatedObjectiveComplete;progressAssessment: string; }>

A promise that resolves to the retrieved data.

command?

optional command: ({index: number;kind: "Click"; } | {index: number;kind: "Type";text: string; } | {kind: "Back"; } | {kind: "Wait"; })[]

description

description: string

objectiveComplete?

optional objectiveComplete: {} = updatedObjectiveComplete

progressAssessment

progressAssessment: string

Defined in

src/browser/page.ts:582


title()

title(): Promise<string>

Returns the title of the page.

Returns

Promise<string>

The title of the page.

Defined in

src/browser/page.ts:162


url()

url(): string

Returns the URL of the page.

Returns

string

The URL of the page.

Defined in

src/browser/page.ts:94