@playwright/mcp 0.0.30 → 0.0.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +180 -320
- package/config.d.ts +5 -14
- package/index.d.ts +1 -6
- package/lib/browserContextFactory.js +3 -35
- package/lib/browserServerBackend.js +54 -0
- package/lib/config.js +64 -7
- package/lib/context.js +50 -163
- package/lib/extension/cdpRelay.js +370 -0
- package/lib/extension/main.js +33 -0
- package/lib/httpServer.js +20 -182
- package/lib/index.js +3 -2
- package/lib/log.js +21 -0
- package/lib/loop/loop.js +69 -0
- package/lib/loop/loopClaude.js +152 -0
- package/lib/loop/loopOpenAI.js +141 -0
- package/lib/loop/main.js +60 -0
- package/lib/loopTools/context.js +66 -0
- package/lib/loopTools/main.js +49 -0
- package/lib/loopTools/perform.js +32 -0
- package/lib/loopTools/snapshot.js +29 -0
- package/lib/loopTools/tool.js +18 -0
- package/lib/mcp/inProcessTransport.js +72 -0
- package/lib/mcp/server.js +88 -0
- package/lib/{transport.js → mcp/transport.js} +30 -42
- package/lib/package.js +3 -3
- package/lib/program.js +47 -17
- package/lib/response.js +98 -0
- package/lib/sessionLog.js +70 -0
- package/lib/tab.js +166 -21
- package/lib/tools/common.js +13 -25
- package/lib/tools/console.js +4 -15
- package/lib/tools/dialogs.js +14 -19
- package/lib/tools/evaluate.js +53 -0
- package/lib/tools/files.js +13 -19
- package/lib/tools/install.js +4 -8
- package/lib/tools/keyboard.js +51 -17
- package/lib/tools/mouse.js +99 -0
- package/lib/tools/navigate.js +22 -42
- package/lib/tools/network.js +5 -15
- package/lib/tools/pdf.js +8 -15
- package/lib/tools/screenshot.js +29 -30
- package/lib/tools/snapshot.js +49 -109
- package/lib/tools/tabs.js +21 -52
- package/lib/tools/tool.js +14 -0
- package/lib/tools/utils.js +7 -6
- package/lib/tools/wait.js +8 -11
- package/lib/tools.js +15 -26
- package/package.json +12 -5
- package/lib/browserServer.js +0 -151
- package/lib/connection.js +0 -82
- package/lib/pageSnapshot.js +0 -43
- package/lib/server.js +0 -48
- package/lib/tools/testing.js +0 -60
- package/lib/tools/vision.js +0 -189
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { z } from 'zod';
|
|
17
|
+
import { defineTabTool } from './tool.js';
|
|
18
|
+
const elementSchema = z.object({
|
|
19
|
+
element: z.string().describe('Human-readable element description used to obtain permission to interact with the element'),
|
|
20
|
+
});
|
|
21
|
+
const mouseMove = defineTabTool({
|
|
22
|
+
capability: 'vision',
|
|
23
|
+
schema: {
|
|
24
|
+
name: 'browser_mouse_move_xy',
|
|
25
|
+
title: 'Move mouse',
|
|
26
|
+
description: 'Move mouse to a given position',
|
|
27
|
+
inputSchema: elementSchema.extend({
|
|
28
|
+
x: z.number().describe('X coordinate'),
|
|
29
|
+
y: z.number().describe('Y coordinate'),
|
|
30
|
+
}),
|
|
31
|
+
type: 'readOnly',
|
|
32
|
+
},
|
|
33
|
+
handle: async (tab, params, response) => {
|
|
34
|
+
response.addCode(`// Move mouse to (${params.x}, ${params.y})`);
|
|
35
|
+
response.addCode(`await page.mouse.move(${params.x}, ${params.y});`);
|
|
36
|
+
await tab.waitForCompletion(async () => {
|
|
37
|
+
await tab.page.mouse.move(params.x, params.y);
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
const mouseClick = defineTabTool({
|
|
42
|
+
capability: 'vision',
|
|
43
|
+
schema: {
|
|
44
|
+
name: 'browser_mouse_click_xy',
|
|
45
|
+
title: 'Click',
|
|
46
|
+
description: 'Click left mouse button at a given position',
|
|
47
|
+
inputSchema: elementSchema.extend({
|
|
48
|
+
x: z.number().describe('X coordinate'),
|
|
49
|
+
y: z.number().describe('Y coordinate'),
|
|
50
|
+
}),
|
|
51
|
+
type: 'destructive',
|
|
52
|
+
},
|
|
53
|
+
handle: async (tab, params, response) => {
|
|
54
|
+
response.setIncludeSnapshot();
|
|
55
|
+
response.addCode(`// Click mouse at coordinates (${params.x}, ${params.y})`);
|
|
56
|
+
response.addCode(`await page.mouse.move(${params.x}, ${params.y});`);
|
|
57
|
+
response.addCode(`await page.mouse.down();`);
|
|
58
|
+
response.addCode(`await page.mouse.up();`);
|
|
59
|
+
await tab.waitForCompletion(async () => {
|
|
60
|
+
await tab.page.mouse.move(params.x, params.y);
|
|
61
|
+
await tab.page.mouse.down();
|
|
62
|
+
await tab.page.mouse.up();
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
const mouseDrag = defineTabTool({
|
|
67
|
+
capability: 'vision',
|
|
68
|
+
schema: {
|
|
69
|
+
name: 'browser_mouse_drag_xy',
|
|
70
|
+
title: 'Drag mouse',
|
|
71
|
+
description: 'Drag left mouse button to a given position',
|
|
72
|
+
inputSchema: elementSchema.extend({
|
|
73
|
+
startX: z.number().describe('Start X coordinate'),
|
|
74
|
+
startY: z.number().describe('Start Y coordinate'),
|
|
75
|
+
endX: z.number().describe('End X coordinate'),
|
|
76
|
+
endY: z.number().describe('End Y coordinate'),
|
|
77
|
+
}),
|
|
78
|
+
type: 'destructive',
|
|
79
|
+
},
|
|
80
|
+
handle: async (tab, params, response) => {
|
|
81
|
+
response.setIncludeSnapshot();
|
|
82
|
+
response.addCode(`// Drag mouse from (${params.startX}, ${params.startY}) to (${params.endX}, ${params.endY})`);
|
|
83
|
+
response.addCode(`await page.mouse.move(${params.startX}, ${params.startY});`);
|
|
84
|
+
response.addCode(`await page.mouse.down();`);
|
|
85
|
+
response.addCode(`await page.mouse.move(${params.endX}, ${params.endY});`);
|
|
86
|
+
response.addCode(`await page.mouse.up();`);
|
|
87
|
+
await tab.waitForCompletion(async () => {
|
|
88
|
+
await tab.page.mouse.move(params.startX, params.startY);
|
|
89
|
+
await tab.page.mouse.down();
|
|
90
|
+
await tab.page.mouse.move(params.endX, params.endY);
|
|
91
|
+
await tab.page.mouse.up();
|
|
92
|
+
});
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
export default [
|
|
96
|
+
mouseMove,
|
|
97
|
+
mouseClick,
|
|
98
|
+
mouseDrag,
|
|
99
|
+
];
|
package/lib/tools/navigate.js
CHANGED
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { z } from 'zod';
|
|
17
|
-
import { defineTool } from './tool.js';
|
|
18
|
-
const navigate =
|
|
17
|
+
import { defineTool, defineTabTool } from './tool.js';
|
|
18
|
+
const navigate = defineTool({
|
|
19
19
|
capability: 'core',
|
|
20
20
|
schema: {
|
|
21
21
|
name: 'browser_navigate',
|
|
@@ -26,22 +26,16 @@ const navigate = captureSnapshot => defineTool({
|
|
|
26
26
|
}),
|
|
27
27
|
type: 'destructive',
|
|
28
28
|
},
|
|
29
|
-
handle: async (context, params) => {
|
|
29
|
+
handle: async (context, params, response) => {
|
|
30
30
|
const tab = await context.ensureTab();
|
|
31
31
|
await tab.navigate(params.url);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
];
|
|
36
|
-
return {
|
|
37
|
-
code,
|
|
38
|
-
captureSnapshot,
|
|
39
|
-
waitForNetwork: false,
|
|
40
|
-
};
|
|
32
|
+
response.setIncludeSnapshot();
|
|
33
|
+
response.addCode(`// Navigate to ${params.url}`);
|
|
34
|
+
response.addCode(`await page.goto('${params.url}');`);
|
|
41
35
|
},
|
|
42
36
|
});
|
|
43
|
-
const goBack =
|
|
44
|
-
capability: '
|
|
37
|
+
const goBack = defineTabTool({
|
|
38
|
+
capability: 'core',
|
|
45
39
|
schema: {
|
|
46
40
|
name: 'browser_navigate_back',
|
|
47
41
|
title: 'Go back',
|
|
@@ -49,22 +43,15 @@ const goBack = captureSnapshot => defineTool({
|
|
|
49
43
|
inputSchema: z.object({}),
|
|
50
44
|
type: 'readOnly',
|
|
51
45
|
},
|
|
52
|
-
handle: async (
|
|
53
|
-
const tab = await context.ensureTab();
|
|
46
|
+
handle: async (tab, params, response) => {
|
|
54
47
|
await tab.page.goBack();
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
];
|
|
59
|
-
return {
|
|
60
|
-
code,
|
|
61
|
-
captureSnapshot,
|
|
62
|
-
waitForNetwork: false,
|
|
63
|
-
};
|
|
48
|
+
response.setIncludeSnapshot();
|
|
49
|
+
response.addCode(`// Navigate back`);
|
|
50
|
+
response.addCode(`await page.goBack();`);
|
|
64
51
|
},
|
|
65
52
|
});
|
|
66
|
-
const goForward =
|
|
67
|
-
capability: '
|
|
53
|
+
const goForward = defineTabTool({
|
|
54
|
+
capability: 'core',
|
|
68
55
|
schema: {
|
|
69
56
|
name: 'browser_navigate_forward',
|
|
70
57
|
title: 'Go forward',
|
|
@@ -72,22 +59,15 @@ const goForward = captureSnapshot => defineTool({
|
|
|
72
59
|
inputSchema: z.object({}),
|
|
73
60
|
type: 'readOnly',
|
|
74
61
|
},
|
|
75
|
-
handle: async (
|
|
76
|
-
const tab = context.currentTabOrDie();
|
|
62
|
+
handle: async (tab, params, response) => {
|
|
77
63
|
await tab.page.goForward();
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
];
|
|
82
|
-
return {
|
|
83
|
-
code,
|
|
84
|
-
captureSnapshot,
|
|
85
|
-
waitForNetwork: false,
|
|
86
|
-
};
|
|
64
|
+
response.setIncludeSnapshot();
|
|
65
|
+
response.addCode(`// Navigate forward`);
|
|
66
|
+
response.addCode(`await page.goForward();`);
|
|
87
67
|
},
|
|
88
68
|
});
|
|
89
|
-
export default
|
|
90
|
-
navigate
|
|
91
|
-
goBack
|
|
92
|
-
goForward
|
|
69
|
+
export default [
|
|
70
|
+
navigate,
|
|
71
|
+
goBack,
|
|
72
|
+
goForward,
|
|
93
73
|
];
|
package/lib/tools/network.js
CHANGED
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { z } from 'zod';
|
|
17
|
-
import {
|
|
18
|
-
const requests =
|
|
17
|
+
import { defineTabTool } from './tool.js';
|
|
18
|
+
const requests = defineTabTool({
|
|
19
19
|
capability: 'core',
|
|
20
20
|
schema: {
|
|
21
21
|
name: 'browser_network_requests',
|
|
@@ -24,19 +24,9 @@ const requests = defineTool({
|
|
|
24
24
|
inputSchema: z.object({}),
|
|
25
25
|
type: 'readOnly',
|
|
26
26
|
},
|
|
27
|
-
handle: async (
|
|
28
|
-
const requests =
|
|
29
|
-
|
|
30
|
-
return {
|
|
31
|
-
code: [`// <internal code to list network requests>`],
|
|
32
|
-
action: async () => {
|
|
33
|
-
return {
|
|
34
|
-
content: [{ type: 'text', text: log }]
|
|
35
|
-
};
|
|
36
|
-
},
|
|
37
|
-
captureSnapshot: false,
|
|
38
|
-
waitForNetwork: false,
|
|
39
|
-
};
|
|
27
|
+
handle: async (tab, params, response) => {
|
|
28
|
+
const requests = tab.requests();
|
|
29
|
+
[...requests.entries()].forEach(([req, res]) => response.addResult(renderRequest(req, res)));
|
|
40
30
|
},
|
|
41
31
|
});
|
|
42
32
|
function renderRequest(request, response) {
|
package/lib/tools/pdf.js
CHANGED
|
@@ -14,13 +14,13 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { z } from 'zod';
|
|
17
|
-
import {
|
|
17
|
+
import { defineTabTool } from './tool.js';
|
|
18
18
|
import * as javascript from '../javascript.js';
|
|
19
19
|
import { outputFile } from '../config.js';
|
|
20
20
|
const pdfSchema = z.object({
|
|
21
21
|
filename: z.string().optional().describe('File name to save the pdf to. Defaults to `page-{timestamp}.pdf` if not specified.'),
|
|
22
22
|
});
|
|
23
|
-
const pdf =
|
|
23
|
+
const pdf = defineTabTool({
|
|
24
24
|
capability: 'pdf',
|
|
25
25
|
schema: {
|
|
26
26
|
name: 'browser_pdf_save',
|
|
@@ -29,19 +29,12 @@ const pdf = defineTool({
|
|
|
29
29
|
inputSchema: pdfSchema,
|
|
30
30
|
type: 'readOnly',
|
|
31
31
|
},
|
|
32
|
-
handle: async (
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
];
|
|
39
|
-
return {
|
|
40
|
-
code,
|
|
41
|
-
action: async () => tab.page.pdf({ path: fileName }).then(() => { }),
|
|
42
|
-
captureSnapshot: false,
|
|
43
|
-
waitForNetwork: false,
|
|
44
|
-
};
|
|
32
|
+
handle: async (tab, params, response) => {
|
|
33
|
+
const fileName = await outputFile(tab.context.config, params.filename ?? `page-${new Date().toISOString()}.pdf`);
|
|
34
|
+
response.addCode(`// Save page as ${fileName}`);
|
|
35
|
+
response.addCode(`await page.pdf(${javascript.formatObject({ path: fileName })});`);
|
|
36
|
+
response.addResult(`Saved page as ${fileName}`);
|
|
37
|
+
await tab.page.pdf({ path: fileName });
|
|
45
38
|
},
|
|
46
39
|
});
|
|
47
40
|
export default [
|
package/lib/tools/screenshot.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { z } from 'zod';
|
|
17
|
-
import {
|
|
17
|
+
import { defineTabTool } from './tool.js';
|
|
18
18
|
import * as javascript from '../javascript.js';
|
|
19
19
|
import { outputFile } from '../config.js';
|
|
20
20
|
import { generateLocator } from './utils.js';
|
|
@@ -23,13 +23,19 @@ const screenshotSchema = z.object({
|
|
|
23
23
|
filename: z.string().optional().describe('File name to save the screenshot to. Defaults to `page-{timestamp}.{png|jpeg}` if not specified.'),
|
|
24
24
|
element: z.string().optional().describe('Human-readable element description used to obtain permission to screenshot the element. If not provided, the screenshot will be taken of viewport. If element is provided, ref must be provided too.'),
|
|
25
25
|
ref: z.string().optional().describe('Exact target element reference from the page snapshot. If not provided, the screenshot will be taken of viewport. If ref is provided, element must be provided too.'),
|
|
26
|
+
fullPage: z.boolean().optional().describe('When true, takes a screenshot of the full scrollable page, instead of the currently visible viewport. Cannot be used with element screenshots.'),
|
|
26
27
|
}).refine(data => {
|
|
27
28
|
return !!data.element === !!data.ref;
|
|
28
29
|
}, {
|
|
29
30
|
message: 'Both element and ref must be provided or neither.',
|
|
30
31
|
path: ['ref', 'element']
|
|
32
|
+
}).refine(data => {
|
|
33
|
+
return !(data.fullPage && (data.element || data.ref));
|
|
34
|
+
}, {
|
|
35
|
+
message: 'fullPage cannot be used with element screenshots.',
|
|
36
|
+
path: ['fullPage']
|
|
31
37
|
});
|
|
32
|
-
const screenshot =
|
|
38
|
+
const screenshot = defineTabTool({
|
|
33
39
|
capability: 'core',
|
|
34
40
|
schema: {
|
|
35
41
|
name: 'browser_take_screenshot',
|
|
@@ -38,38 +44,31 @@ const screenshot = defineTool({
|
|
|
38
44
|
inputSchema: screenshotSchema,
|
|
39
45
|
type: 'readOnly',
|
|
40
46
|
},
|
|
41
|
-
handle: async (
|
|
42
|
-
const tab = context.currentTabOrDie();
|
|
43
|
-
const snapshot = tab.snapshotOrDie();
|
|
47
|
+
handle: async (tab, params, response) => {
|
|
44
48
|
const fileType = params.raw ? 'png' : 'jpeg';
|
|
45
|
-
const fileName = await outputFile(context.config, params.filename ?? `page-${new Date().toISOString()}.${fileType}`);
|
|
46
|
-
const options = {
|
|
49
|
+
const fileName = await outputFile(tab.context.config, params.filename ?? `page-${new Date().toISOString()}.${fileType}`);
|
|
50
|
+
const options = {
|
|
51
|
+
type: fileType,
|
|
52
|
+
quality: fileType === 'png' ? undefined : 50,
|
|
53
|
+
scale: 'css',
|
|
54
|
+
path: fileName,
|
|
55
|
+
...(params.fullPage !== undefined && { fullPage: params.fullPage })
|
|
56
|
+
};
|
|
47
57
|
const isElementScreenshot = params.element && params.ref;
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const locator = params.ref ?
|
|
58
|
+
const screenshotTarget = isElementScreenshot ? params.element : (params.fullPage ? 'full page' : 'viewport');
|
|
59
|
+
response.addCode(`// Screenshot ${screenshotTarget} and save it as ${fileName}`);
|
|
60
|
+
// Only get snapshot when element screenshot is needed
|
|
61
|
+
const locator = params.ref ? await tab.refLocator({ element: params.element || '', ref: params.ref }) : null;
|
|
52
62
|
if (locator)
|
|
53
|
-
|
|
63
|
+
response.addCode(`await page.${await generateLocator(locator)}.screenshot(${javascript.formatObject(options)});`);
|
|
54
64
|
else
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
data: screenshot.toString('base64'),
|
|
63
|
-
mimeType: fileType === 'png' ? 'image/png' : 'image/jpeg',
|
|
64
|
-
}] : []
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
return {
|
|
68
|
-
code,
|
|
69
|
-
action,
|
|
70
|
-
captureSnapshot: true,
|
|
71
|
-
waitForNetwork: false,
|
|
72
|
-
};
|
|
65
|
+
response.addCode(`await page.screenshot(${javascript.formatObject(options)});`);
|
|
66
|
+
const buffer = locator ? await locator.screenshot(options) : await tab.page.screenshot(options);
|
|
67
|
+
response.addResult(`Took the ${screenshotTarget} screenshot and saved it as ${fileName}`);
|
|
68
|
+
response.addImage({
|
|
69
|
+
contentType: fileType === 'png' ? 'image/png' : 'image/jpeg',
|
|
70
|
+
data: buffer
|
|
71
|
+
});
|
|
73
72
|
}
|
|
74
73
|
});
|
|
75
74
|
export default [
|
package/lib/tools/snapshot.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { z } from 'zod';
|
|
17
|
-
import { defineTool } from './tool.js';
|
|
17
|
+
import { defineTabTool, defineTool } from './tool.js';
|
|
18
18
|
import * as javascript from '../javascript.js';
|
|
19
19
|
import { generateLocator } from './utils.js';
|
|
20
20
|
const snapshot = defineTool({
|
|
@@ -26,23 +26,20 @@ const snapshot = defineTool({
|
|
|
26
26
|
inputSchema: z.object({}),
|
|
27
27
|
type: 'readOnly',
|
|
28
28
|
},
|
|
29
|
-
handle: async (context) => {
|
|
29
|
+
handle: async (context, params, response) => {
|
|
30
30
|
await context.ensureTab();
|
|
31
|
-
|
|
32
|
-
code: [`// <internal code to capture accessibility snapshot>`],
|
|
33
|
-
captureSnapshot: true,
|
|
34
|
-
waitForNetwork: false,
|
|
35
|
-
};
|
|
31
|
+
response.setIncludeSnapshot();
|
|
36
32
|
},
|
|
37
33
|
});
|
|
38
|
-
const elementSchema = z.object({
|
|
34
|
+
export const elementSchema = z.object({
|
|
39
35
|
element: z.string().describe('Human-readable element description used to obtain permission to interact with the element'),
|
|
40
36
|
ref: z.string().describe('Exact target element reference from the page snapshot'),
|
|
41
37
|
});
|
|
42
38
|
const clickSchema = elementSchema.extend({
|
|
43
39
|
doubleClick: z.boolean().optional().describe('Whether to perform a double click instead of a single click'),
|
|
40
|
+
button: z.enum(['left', 'right', 'middle']).optional().describe('Button to click, defaults to left'),
|
|
44
41
|
});
|
|
45
|
-
const click =
|
|
42
|
+
const click = defineTabTool({
|
|
46
43
|
capability: 'core',
|
|
47
44
|
schema: {
|
|
48
45
|
name: 'browser_click',
|
|
@@ -51,27 +48,28 @@ const click = defineTool({
|
|
|
51
48
|
inputSchema: clickSchema,
|
|
52
49
|
type: 'destructive',
|
|
53
50
|
},
|
|
54
|
-
handle: async (
|
|
55
|
-
|
|
56
|
-
const locator = tab.
|
|
57
|
-
const
|
|
51
|
+
handle: async (tab, params, response) => {
|
|
52
|
+
response.setIncludeSnapshot();
|
|
53
|
+
const locator = await tab.refLocator(params);
|
|
54
|
+
const button = params.button;
|
|
55
|
+
const buttonAttr = button ? `{ button: '${button}' }` : '';
|
|
58
56
|
if (params.doubleClick) {
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
response.addCode(`// Double click ${params.element}`);
|
|
58
|
+
response.addCode(`await page.${await generateLocator(locator)}.dblclick(${buttonAttr});`);
|
|
61
59
|
}
|
|
62
60
|
else {
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
response.addCode(`// Click ${params.element}`);
|
|
62
|
+
response.addCode(`await page.${await generateLocator(locator)}.click(${buttonAttr});`);
|
|
65
63
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
};
|
|
64
|
+
await tab.waitForCompletion(async () => {
|
|
65
|
+
if (params.doubleClick)
|
|
66
|
+
await locator.dblclick({ button });
|
|
67
|
+
else
|
|
68
|
+
await locator.click({ button });
|
|
69
|
+
});
|
|
72
70
|
},
|
|
73
71
|
});
|
|
74
|
-
const drag =
|
|
72
|
+
const drag = defineTabTool({
|
|
75
73
|
capability: 'core',
|
|
76
74
|
schema: {
|
|
77
75
|
name: 'browser_drag',
|
|
@@ -85,23 +83,19 @@ const drag = defineTool({
|
|
|
85
83
|
}),
|
|
86
84
|
type: 'destructive',
|
|
87
85
|
},
|
|
88
|
-
handle: async (
|
|
89
|
-
|
|
90
|
-
const startLocator =
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
action: () => startLocator.dragTo(endLocator),
|
|
99
|
-
captureSnapshot: true,
|
|
100
|
-
waitForNetwork: true,
|
|
101
|
-
};
|
|
86
|
+
handle: async (tab, params, response) => {
|
|
87
|
+
response.setIncludeSnapshot();
|
|
88
|
+
const [startLocator, endLocator] = await tab.refLocators([
|
|
89
|
+
{ ref: params.startRef, element: params.startElement },
|
|
90
|
+
{ ref: params.endRef, element: params.endElement },
|
|
91
|
+
]);
|
|
92
|
+
await tab.waitForCompletion(async () => {
|
|
93
|
+
await startLocator.dragTo(endLocator);
|
|
94
|
+
});
|
|
95
|
+
response.addCode(`await page.${await generateLocator(startLocator)}.dragTo(page.${await generateLocator(endLocator)});`);
|
|
102
96
|
},
|
|
103
97
|
});
|
|
104
|
-
const hover =
|
|
98
|
+
const hover = defineTabTool({
|
|
105
99
|
capability: 'core',
|
|
106
100
|
schema: {
|
|
107
101
|
name: 'browser_hover',
|
|
@@ -110,67 +104,19 @@ const hover = defineTool({
|
|
|
110
104
|
inputSchema: elementSchema,
|
|
111
105
|
type: 'readOnly',
|
|
112
106
|
},
|
|
113
|
-
handle: async (
|
|
114
|
-
|
|
115
|
-
const locator =
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
return {
|
|
121
|
-
code,
|
|
122
|
-
action: () => locator.hover(),
|
|
123
|
-
captureSnapshot: true,
|
|
124
|
-
waitForNetwork: true,
|
|
125
|
-
};
|
|
126
|
-
},
|
|
127
|
-
});
|
|
128
|
-
const typeSchema = elementSchema.extend({
|
|
129
|
-
text: z.string().describe('Text to type into the element'),
|
|
130
|
-
submit: z.boolean().optional().describe('Whether to submit entered text (press Enter after)'),
|
|
131
|
-
slowly: z.boolean().optional().describe('Whether to type one character at a time. Useful for triggering key handlers in the page. By default entire text is filled in at once.'),
|
|
132
|
-
});
|
|
133
|
-
const type = defineTool({
|
|
134
|
-
capability: 'core',
|
|
135
|
-
schema: {
|
|
136
|
-
name: 'browser_type',
|
|
137
|
-
title: 'Type text',
|
|
138
|
-
description: 'Type text into editable element',
|
|
139
|
-
inputSchema: typeSchema,
|
|
140
|
-
type: 'destructive',
|
|
141
|
-
},
|
|
142
|
-
handle: async (context, params) => {
|
|
143
|
-
const snapshot = context.currentTabOrDie().snapshotOrDie();
|
|
144
|
-
const locator = snapshot.refLocator(params);
|
|
145
|
-
const code = [];
|
|
146
|
-
const steps = [];
|
|
147
|
-
if (params.slowly) {
|
|
148
|
-
code.push(`// Press "${params.text}" sequentially into "${params.element}"`);
|
|
149
|
-
code.push(`await page.${await generateLocator(locator)}.pressSequentially(${javascript.quote(params.text)});`);
|
|
150
|
-
steps.push(() => locator.pressSequentially(params.text));
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
code.push(`// Fill "${params.text}" into "${params.element}"`);
|
|
154
|
-
code.push(`await page.${await generateLocator(locator)}.fill(${javascript.quote(params.text)});`);
|
|
155
|
-
steps.push(() => locator.fill(params.text));
|
|
156
|
-
}
|
|
157
|
-
if (params.submit) {
|
|
158
|
-
code.push(`// Submit text`);
|
|
159
|
-
code.push(`await page.${await generateLocator(locator)}.press('Enter');`);
|
|
160
|
-
steps.push(() => locator.press('Enter'));
|
|
161
|
-
}
|
|
162
|
-
return {
|
|
163
|
-
code,
|
|
164
|
-
action: () => steps.reduce((acc, step) => acc.then(step), Promise.resolve()),
|
|
165
|
-
captureSnapshot: true,
|
|
166
|
-
waitForNetwork: true,
|
|
167
|
-
};
|
|
107
|
+
handle: async (tab, params, response) => {
|
|
108
|
+
response.setIncludeSnapshot();
|
|
109
|
+
const locator = await tab.refLocator(params);
|
|
110
|
+
response.addCode(`await page.${await generateLocator(locator)}.hover();`);
|
|
111
|
+
await tab.waitForCompletion(async () => {
|
|
112
|
+
await locator.hover();
|
|
113
|
+
});
|
|
168
114
|
},
|
|
169
115
|
});
|
|
170
116
|
const selectOptionSchema = elementSchema.extend({
|
|
171
117
|
values: z.array(z.string()).describe('Array of values to select in the dropdown. This can be a single value or multiple values.'),
|
|
172
118
|
});
|
|
173
|
-
const selectOption =
|
|
119
|
+
const selectOption = defineTabTool({
|
|
174
120
|
capability: 'core',
|
|
175
121
|
schema: {
|
|
176
122
|
name: 'browser_select_option',
|
|
@@ -179,19 +125,14 @@ const selectOption = defineTool({
|
|
|
179
125
|
inputSchema: selectOptionSchema,
|
|
180
126
|
type: 'destructive',
|
|
181
127
|
},
|
|
182
|
-
handle: async (
|
|
183
|
-
|
|
184
|
-
const locator =
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
code,
|
|
191
|
-
action: () => locator.selectOption(params.values).then(() => { }),
|
|
192
|
-
captureSnapshot: true,
|
|
193
|
-
waitForNetwork: true,
|
|
194
|
-
};
|
|
128
|
+
handle: async (tab, params, response) => {
|
|
129
|
+
response.setIncludeSnapshot();
|
|
130
|
+
const locator = await tab.refLocator(params);
|
|
131
|
+
response.addCode(`// Select options [${params.values.join(', ')}] in ${params.element}`);
|
|
132
|
+
response.addCode(`await page.${await generateLocator(locator)}.selectOption(${javascript.formatObject(params.values)});`);
|
|
133
|
+
await tab.waitForCompletion(async () => {
|
|
134
|
+
await locator.selectOption(params.values);
|
|
135
|
+
});
|
|
195
136
|
},
|
|
196
137
|
});
|
|
197
138
|
export default [
|
|
@@ -199,6 +140,5 @@ export default [
|
|
|
199
140
|
click,
|
|
200
141
|
drag,
|
|
201
142
|
hover,
|
|
202
|
-
type,
|
|
203
143
|
selectOption,
|
|
204
144
|
];
|