-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathsnapshot.ts
More file actions
68 lines (59 loc) · 1.86 KB
/
snapshot.ts
File metadata and controls
68 lines (59 loc) · 1.86 KB
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
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import {Locator} from 'puppeteer-core';
import z from 'zod';
import {ToolCategories} from './categories.js';
import {defineTool, timeoutSchema} from './ToolDefinition.js';
export const takeSnapshot = defineTool({
name: 'take_snapshot',
description: `Take a text snapshot of the currently selected page based on the a11y tree. The snapshot lists page elements along with a unique
identifier (uid). Always use the latest snapshot. Prefer taking a snapshot over taking a screenshot.`,
annotations: {
category: ToolCategories.DEBUGGING,
readOnlyHint: true,
},
schema: {
verbose: z
.boolean()
.optional()
.describe(
'Whether to include all possible information available in the full a11y tree. Default is false.',
),
},
handler: async (request, response) => {
response.setIncludeSnapshot(true, request.params.verbose ?? false);
},
});
export const waitFor = defineTool({
name: 'wait_for',
description: `Wait for the specified text to appear on the selected page.`,
annotations: {
category: ToolCategories.NAVIGATION_AUTOMATION,
readOnlyHint: true,
},
schema: {
text: z.string().describe('Text to appear on the page'),
...timeoutSchema,
},
handler: async (request, response, context) => {
const page = context.getSelectedPage();
const frames = page.frames();
const locator = Locator.race(
frames.flatMap(frame => [
frame.locator(`aria/${request.params.text}`),
frame.locator(`text/${request.params.text}`),
]),
);
if (request.params.timeout) {
locator.setTimeout(request.params.timeout);
}
await locator.wait();
response.appendResponseLine(
`Element with text "${request.params.text}" found.`,
);
response.setIncludeSnapshot(true);
},
});