-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathsnapshot.ts
More file actions
54 lines (46 loc) · 1.49 KB
/
snapshot.ts
File metadata and controls
54 lines (46 loc) · 1.49 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
/**
* @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} from './ToolDefinition.js';
export const takeSnapshot = defineTool({
name: 'take_snapshot',
description: `Take a text snapshot of the currently selected page. 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: {},
handler: async (_request, response) => {
response.setIncludeSnapshot(true);
},
});
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'),
},
handler: async (request, response, context) => {
const page = context.getSelectedPage();
const frames = page.frames();
const locators = frames.flatMap(frame => [
frame.locator(`aria/${request.params.text}`),
frame.locator(`text/${request.params.text}`),
]);
await Locator.race(locators).wait();
response.appendResponseLine(
`Element with text "${request.params.text}" found.`,
);
response.setIncludeSnapshot(true);
},
});