1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135# class: PageAgent
* since: v1.58
* langs: js
## event: PageAgent.turn
* since: v1.58
- argument: <[Object]>
- `role` <[string]>
- `message` <[string]>
- `usage` ?<[Object]>
- `inputTokens` <[int]>
- `outputTokens` <[int]>
Emitted when the agent makes a turn.
## async method: PageAgent.dispose
* since: v1.58
Dispose this agent.
## async method: PageAgent.expect
* since: v1.58
Expect certain condition to be met.
**Usage**
```js
await agent.expect('"0 items" to be reported');
```
### param: PageAgent.expect.expectation
* since: v1.58
- `expectation` <[string]>
Expectation to assert.
### option: PageAgent.expect.timeout
* since: v1.58
- `timeout` <[float]>
Expect timeout in milliseconds. Defaults to `5000`. The default value can be changed via `expect.timeout` option in the config, or by specifying the `expect` property of the [`option: Page.agent.expect`] option. Pass `0` to disable timeout.
### option: PageAgent.expect.-inline- = %%-page-agent-call-options-v1.58-%%
* since: v1.58
## async method: PageAgent.extract
* since: v1.58
- returns: <[Object]>
- `result` <[any]>
- `usage` <[Object]>
- `turns` <[int]>
- `inputTokens` <[int]>
- `outputTokens` <[int]>
Extract information from the page using the agentic loop, return it in a given Zod format.
**Usage**
```js
await agent.extract('List of items in the cart', z.object({
title: z.string().describe('Item title to extract'),
price: z.string().describe('Item price to extract'),
}).array());
```
### param: PageAgent.extract.query
* since: v1.58
- `query` <[string]>
Task to perform using agentic loop.
### param: PageAgent.extract.schema
* since: v1.58
- `schema` <[z.ZodSchema]>
### option: PageAgent.extract.timeout
* since: v1.58
- `timeout` <[float]>
Extract timeout in milliseconds. Defaults to `5000`. The default value can be changed via `actionTimeout` option in the config, or by using the [`method: BrowserContext.setDefaultTimeout`] or
[`method: Page.setDefaultTimeout`] methods. Pass `0` to disable timeout.
### option: PageAgent.extract.-inline- = %%-page-agent-call-options-v1.58-%%
* since: v1.58
## async method: PageAgent.perform
* since: v1.58
- returns: <[Object]>
- `usage` <[Object]>
- `turns` <[int]>
- `inputTokens` <[int]>
- `outputTokens` <[int]>
Perform action using agentic loop.
**Usage**
```js
await agent.perform('Click submit button');
```
### param: PageAgent.perform.task
* since: v1.58
- `task` <[string]>
Task to perform using agentic loop.
### option: PageAgent.perform.timeout
* since: v1.58
- `timeout` <[float]>
Perform timeout in milliseconds. Defaults to `5000`. The default value can be changed via `actionTimeout` option in the config, or by using the [`method: BrowserContext.setDefaultTimeout`] or
[`method: Page.setDefaultTimeout`] methods. Pass `0` to disable timeout.
### option: PageAgent.perform.-inline- = %%-page-agent-call-options-v1.58-%%
* since: v1.58
## async method: PageAgent.usage
* since: v1.58
- returns: <[Object]>
- `turns` <[int]>
- `inputTokens` <[int]>
- `outputTokens` <[int]>
Returns the current token usage for this agent.
**Usage**
```js
const usage = await agent.usage();
console.log(`Tokens used: ${usage.inputTokens} in, ${usage.outputTokens} out`);
```