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
| Parameter | Type | Description |
|---|---|---|
page | Page | The PuppeteerPage object representing the browser page. |
agent | Agent | The Agent object representing the user agent interacting with the page. |
opts? | object | Optional parameters for additional configuration. |
opts.apiKey? | string | An optional API key for accessing collective memory. |
opts.disableMemory? | boolean | - |
opts.endpoint? | string | An optional endpoint for collective memory. |
opts.inventory? | Inventory | An optional inventory object for storing and retrieving user data. |
opts.logger? | Logger | An optional logger for logging events; if not provided, logging may be absent. |
opts.pageId? | string | An optional unique identifier for the page; if not provided, a UUID will be generated. |
Returns
Defined in
Properties
agent
agent:
Agent
Defined in
error
error:
undefined|string
Defined in
logger?
optionallogger:Logger
Defined in
page
page:
Page
Defined in
pageId
pageId:
string
Defined in
progress
progress:
string[] =[]
Defined in
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
| Parameter | Type | Description |
|---|---|---|
objective | string | - |
opts | object | Additional options. |
opts.agent? | Agent | The agent to use (optional). |
opts.inventory? | Inventory | The inventory object (optional). |
opts.maxTurns | number | The 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
close()
close():
Promise<void>
Closes the page.
Returns
Promise<void>
Defined in
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
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
| Parameter | Type | Description |
|---|---|---|
request | string | The request or objective. |
opts? | object | Additional options. |
opts.agent? | Agent | The agent to use (optional). |
opts.delay? | number | The delay in milliseconds after performing the action (default: 100). |
opts.inventory? | Inventory | The 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
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
| Parameter | Type | Description |
|---|---|---|
memoryId | string | The memory sequence ID. |
opts? | object | Additional options. |
opts.delay? | number | The delay in milliseconds after performing the action (default: 100). |
opts.inventory? | Inventory | The inventory object (optional). |
opts.maxTurns? | number | The 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
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
| Parameter | Type | Description |
|---|---|---|
request | string | The request or objective. |
opts | object | Additional options. |
opts.agent? | Agent | The agent to use (optional). |
opts.inventory? | Inventory | The inventory object (optional). |
opts.progress? | string[] | The progress towards the objective (optional). |
opts.schema | T | The Zod schema for the return type. |
Returns
Promise<TypeOf<T>>
Defined in
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 Parameter | Description |
|---|---|
T extends ZodType<any, ZodTypeDef, any> | The type of the return value. |
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
request | string | undefined | The request or objective. |
outputSchema | ZodType<any, ZodTypeDef, any> | ObjectiveComplete | The Zod schema for the return type. |
opts? | object | undefined | Additional options. |
opts.agent? | Agent | undefined | The agent to use (optional). |
opts.mode? | "text" | "html" | "aria" | "markdown" | "image" | undefined | - |
opts.progress? | string[] | undefined | The progress towards the objective (optional). |
Returns
Promise<TypeOf<T>>
A promise that resolves to the retrieved data.
Defined in
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
goto()
goto(
url:string,opts?: {delay:number; }):Promise<void>
Navigates to a URL.
Parameters
| Parameter | Type | Description |
|---|---|---|
url | string | The URL to navigate to. |
opts? | object | The navigation options. |
opts.delay? | number | The delay in milliseconds after navigating to the URL. |
Returns
Promise<void>
Defined in
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
injectBoundingBoxes()
injectBoundingBoxes():
Promise<void>
Injects bounding boxes around clickable elements on the page.
Returns
Promise<void>
Defined in
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
| Parameter | Type | Description |
|---|---|---|
request | string | The request or objective. |
opts? | object | The navigation options. |
opts.agent? | Agent | The 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
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
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
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
| Parameter | Type | Description |
|---|---|---|
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? | object | Additional options. |
opts.delay? | number | The delay in milliseconds after performing the action (default: 100). |
opts.inventory? | Inventory | The inventory object (optional). |
Returns
Promise<void>
Defined in
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
| Parameter | Type | Description |
|---|---|---|
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? | object | Additional options. |
opts.delay? | number | The delay in milliseconds after performing the action (default: 100). |
opts.inventory? | Inventory | The inventory object (optional). |
Returns
Promise<void>
Defined in
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
| Parameter | Type | Description |
|---|---|---|
memory | object | The memory to perform |
memory.actionStep | object | - |
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? | object | Additional options |
opts.agent? | Agent | - |
opts.delay? | number | The delay in milliseconds after performing the action (default: 100). |
opts.inventory? | Inventory | The 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
returnErrorState()
returnErrorState(
failureReason:string):Promise<{objectiveFailed: {kind:"ObjectiveFailed";result:failureReason;url:string; }; }>
Parameters
| Parameter | Type |
|---|---|
failureReason | string |
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
screenshot()
screenshot():
Promise<Buffer>
Takes a screenshot of the page.
Returns
Promise<Buffer>
A promise that resolves to the screenshot buffer
Defined in
setViewport()
setViewport(
width:number,height:number,deviceScaleFactor:number):Promise<void>
Sets the viewport size of the page.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
width | number | undefined | The width of the viewport. |
height | number | undefined | The height of the viewport. |
deviceScaleFactor | number | 1 | The device scale factor (default: 1). |
Returns
Promise<void>
Defined in
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
| Parameter | Type | Description |
|---|---|---|
objective | string | The 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
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
| Parameter | Type | Description |
|---|---|---|
objective | string | - |
outputSchema? | ZodObject<any, UnknownKeysParam, ZodTypeAny, {}, {}> | - |
opts? | object | Additional options. |
opts.agent? | Agent | The agent to use (optional). |
opts.delay? | number | - |
opts.inventory? | Inventory | The 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?
optionalcommand: ({index:number;kind:"Click"; } | {index:number;kind:"Type";text:string; } | {kind:"Back"; } | {kind:"Wait"; })[]
description
description:
string
objectiveComplete?
optionalobjectiveComplete: {} =updatedObjectiveComplete
progressAssessment
progressAssessment:
string
Defined in
title()
title():
Promise<string>
Returns the title of the page.
Returns
Promise<string>
The title of the page.
Defined in
url()
url():
string
Returns the URL of the page.
Returns
string
The URL of the page.