@playwright/mcp 0.0.9 → 0.0.10
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 +78 -73
- package/index.d.ts +7 -0
- package/lib/context.js +210 -105
- package/lib/index.js +30 -65
- package/lib/program.js +2 -0
- package/lib/resources/console.js +1 -1
- package/lib/tools/common.js +8 -127
- package/lib/tools/files.js +44 -0
- package/lib/tools/install.js +59 -0
- package/lib/tools/keyboard.js +45 -0
- package/lib/tools/navigate.js +79 -0
- package/lib/tools/pdf.js +48 -0
- package/lib/tools/{screenshot.js → screen.js} +45 -29
- package/lib/tools/snapshot.js +60 -26
- package/lib/tools/tabs.js +100 -0
- package/lib/tools/utils.js +1 -26
- package/package.json +1 -1
|
@@ -15,19 +15,18 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.type = exports.drag = exports.click = exports.moveMouse = exports.screenshot = void 0;
|
|
19
18
|
const zod_1 = require("zod");
|
|
20
19
|
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
21
|
-
const
|
|
22
|
-
|
|
20
|
+
const screenshot = {
|
|
21
|
+
capability: 'core',
|
|
23
22
|
schema: {
|
|
24
|
-
name: '
|
|
23
|
+
name: 'browser_screen_capture',
|
|
25
24
|
description: 'Take a screenshot of the current page',
|
|
26
25
|
inputSchema: (0, zod_to_json_schema_1.zodToJsonSchema)(zod_1.z.object({})),
|
|
27
26
|
},
|
|
28
27
|
handle: async (context) => {
|
|
29
|
-
const
|
|
30
|
-
const screenshot = await page.screenshot({ type: 'jpeg', quality: 50, scale: 'css' });
|
|
28
|
+
const tab = context.currentTab();
|
|
29
|
+
const screenshot = await tab.page.screenshot({ type: 'jpeg', quality: 50, scale: 'css' });
|
|
31
30
|
return {
|
|
32
31
|
content: [{ type: 'image', data: screenshot.toString('base64'), mimeType: 'image/jpeg' }],
|
|
33
32
|
};
|
|
@@ -40,16 +39,17 @@ const moveMouseSchema = elementSchema.extend({
|
|
|
40
39
|
x: zod_1.z.number().describe('X coordinate'),
|
|
41
40
|
y: zod_1.z.number().describe('Y coordinate'),
|
|
42
41
|
});
|
|
43
|
-
|
|
42
|
+
const moveMouse = {
|
|
43
|
+
capability: 'core',
|
|
44
44
|
schema: {
|
|
45
|
-
name: '
|
|
45
|
+
name: 'browser_screen_move_mouse',
|
|
46
46
|
description: 'Move mouse to a given position',
|
|
47
47
|
inputSchema: (0, zod_to_json_schema_1.zodToJsonSchema)(moveMouseSchema),
|
|
48
48
|
},
|
|
49
49
|
handle: async (context, params) => {
|
|
50
50
|
const validatedParams = moveMouseSchema.parse(params);
|
|
51
|
-
const
|
|
52
|
-
await page.mouse.move(validatedParams.x, validatedParams.y);
|
|
51
|
+
const tab = context.currentTab();
|
|
52
|
+
await tab.page.mouse.move(validatedParams.x, validatedParams.y);
|
|
53
53
|
return {
|
|
54
54
|
content: [{ type: 'text', text: `Moved mouse to (${validatedParams.x}, ${validatedParams.y})` }],
|
|
55
55
|
};
|
|
@@ -59,18 +59,21 @@ const clickSchema = elementSchema.extend({
|
|
|
59
59
|
x: zod_1.z.number().describe('X coordinate'),
|
|
60
60
|
y: zod_1.z.number().describe('Y coordinate'),
|
|
61
61
|
});
|
|
62
|
-
|
|
62
|
+
const click = {
|
|
63
|
+
capability: 'core',
|
|
63
64
|
schema: {
|
|
64
|
-
name: '
|
|
65
|
+
name: 'browser_screen_click',
|
|
65
66
|
description: 'Click left mouse button',
|
|
66
67
|
inputSchema: (0, zod_to_json_schema_1.zodToJsonSchema)(clickSchema),
|
|
67
68
|
},
|
|
68
69
|
handle: async (context, params) => {
|
|
69
|
-
return await (
|
|
70
|
+
return await context.currentTab().runAndWait(async (tab) => {
|
|
70
71
|
const validatedParams = clickSchema.parse(params);
|
|
71
|
-
await page.mouse.move(validatedParams.x, validatedParams.y);
|
|
72
|
-
await page.mouse.down();
|
|
73
|
-
await page.mouse.up();
|
|
72
|
+
await tab.page.mouse.move(validatedParams.x, validatedParams.y);
|
|
73
|
+
await tab.page.mouse.down();
|
|
74
|
+
await tab.page.mouse.up();
|
|
75
|
+
}, {
|
|
76
|
+
status: 'Clicked mouse',
|
|
74
77
|
});
|
|
75
78
|
},
|
|
76
79
|
};
|
|
@@ -80,38 +83,51 @@ const dragSchema = elementSchema.extend({
|
|
|
80
83
|
endX: zod_1.z.number().describe('End X coordinate'),
|
|
81
84
|
endY: zod_1.z.number().describe('End Y coordinate'),
|
|
82
85
|
});
|
|
83
|
-
|
|
86
|
+
const drag = {
|
|
87
|
+
capability: 'core',
|
|
84
88
|
schema: {
|
|
85
|
-
name: '
|
|
89
|
+
name: 'browser_screen_drag',
|
|
86
90
|
description: 'Drag left mouse button',
|
|
87
91
|
inputSchema: (0, zod_to_json_schema_1.zodToJsonSchema)(dragSchema),
|
|
88
92
|
},
|
|
89
93
|
handle: async (context, params) => {
|
|
90
94
|
const validatedParams = dragSchema.parse(params);
|
|
91
|
-
return await (
|
|
92
|
-
await page.mouse.move(validatedParams.startX, validatedParams.startY);
|
|
93
|
-
await page.mouse.down();
|
|
94
|
-
await page.mouse.move(validatedParams.endX, validatedParams.endY);
|
|
95
|
-
await page.mouse.up();
|
|
95
|
+
return await context.currentTab().runAndWait(async (tab) => {
|
|
96
|
+
await tab.page.mouse.move(validatedParams.startX, validatedParams.startY);
|
|
97
|
+
await tab.page.mouse.down();
|
|
98
|
+
await tab.page.mouse.move(validatedParams.endX, validatedParams.endY);
|
|
99
|
+
await tab.page.mouse.up();
|
|
100
|
+
}, {
|
|
101
|
+
status: `Dragged mouse from (${validatedParams.startX}, ${validatedParams.startY}) to (${validatedParams.endX}, ${validatedParams.endY})`,
|
|
96
102
|
});
|
|
97
103
|
},
|
|
98
104
|
};
|
|
99
105
|
const typeSchema = zod_1.z.object({
|
|
100
106
|
text: zod_1.z.string().describe('Text to type into the element'),
|
|
101
|
-
submit: zod_1.z.boolean().describe('Whether to submit entered text (press Enter after)'),
|
|
107
|
+
submit: zod_1.z.boolean().optional().describe('Whether to submit entered text (press Enter after)'),
|
|
102
108
|
});
|
|
103
|
-
|
|
109
|
+
const type = {
|
|
110
|
+
capability: 'core',
|
|
104
111
|
schema: {
|
|
105
|
-
name: '
|
|
112
|
+
name: 'browser_screen_type',
|
|
106
113
|
description: 'Type text',
|
|
107
114
|
inputSchema: (0, zod_to_json_schema_1.zodToJsonSchema)(typeSchema),
|
|
108
115
|
},
|
|
109
116
|
handle: async (context, params) => {
|
|
110
117
|
const validatedParams = typeSchema.parse(params);
|
|
111
|
-
return await (
|
|
112
|
-
await page.keyboard.type(validatedParams.text);
|
|
118
|
+
return await context.currentTab().runAndWait(async (tab) => {
|
|
119
|
+
await tab.page.keyboard.type(validatedParams.text);
|
|
113
120
|
if (validatedParams.submit)
|
|
114
|
-
await page.keyboard.press('Enter');
|
|
121
|
+
await tab.page.keyboard.press('Enter');
|
|
122
|
+
}, {
|
|
123
|
+
status: `Typed text "${validatedParams.text}"`,
|
|
115
124
|
});
|
|
116
125
|
},
|
|
117
126
|
};
|
|
127
|
+
exports.default = [
|
|
128
|
+
screenshot,
|
|
129
|
+
moveMouse,
|
|
130
|
+
click,
|
|
131
|
+
drag,
|
|
132
|
+
type,
|
|
133
|
+
];
|
package/lib/tools/snapshot.js
CHANGED
|
@@ -18,25 +18,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
18
18
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
19
|
};
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.screenshot = exports.selectOption = exports.type = exports.hover = exports.drag = exports.click = exports.snapshot = void 0;
|
|
22
21
|
const zod_1 = require("zod");
|
|
23
22
|
const zod_to_json_schema_1 = __importDefault(require("zod-to-json-schema"));
|
|
24
|
-
const
|
|
25
|
-
|
|
23
|
+
const snapshot = {
|
|
24
|
+
capability: 'core',
|
|
26
25
|
schema: {
|
|
27
26
|
name: 'browser_snapshot',
|
|
28
27
|
description: 'Capture accessibility snapshot of the current page, this is better than screenshot',
|
|
29
28
|
inputSchema: (0, zod_to_json_schema_1.default)(zod_1.z.object({})),
|
|
30
29
|
},
|
|
31
30
|
handle: async (context) => {
|
|
32
|
-
return await (
|
|
31
|
+
return await context.currentTab().run(async () => { }, { captureSnapshot: true });
|
|
33
32
|
},
|
|
34
33
|
};
|
|
35
34
|
const elementSchema = zod_1.z.object({
|
|
36
35
|
element: zod_1.z.string().describe('Human-readable element description used to obtain permission to interact with the element'),
|
|
37
36
|
ref: zod_1.z.string().describe('Exact target element reference from the page snapshot'),
|
|
38
37
|
});
|
|
39
|
-
|
|
38
|
+
const click = {
|
|
39
|
+
capability: 'core',
|
|
40
40
|
schema: {
|
|
41
41
|
name: 'browser_click',
|
|
42
42
|
description: 'Perform click on a web page',
|
|
@@ -44,7 +44,12 @@ exports.click = {
|
|
|
44
44
|
},
|
|
45
45
|
handle: async (context, params) => {
|
|
46
46
|
const validatedParams = elementSchema.parse(params);
|
|
47
|
-
return
|
|
47
|
+
return await context.currentTab().runAndWaitWithSnapshot(async (tab) => {
|
|
48
|
+
const locator = tab.lastSnapshot().refLocator(validatedParams.ref);
|
|
49
|
+
await locator.click();
|
|
50
|
+
}, {
|
|
51
|
+
status: `Clicked "${validatedParams.element}"`,
|
|
52
|
+
});
|
|
48
53
|
},
|
|
49
54
|
};
|
|
50
55
|
const dragSchema = zod_1.z.object({
|
|
@@ -53,7 +58,8 @@ const dragSchema = zod_1.z.object({
|
|
|
53
58
|
endElement: zod_1.z.string().describe('Human-readable target element description used to obtain the permission to interact with the element'),
|
|
54
59
|
endRef: zod_1.z.string().describe('Exact target element reference from the page snapshot'),
|
|
55
60
|
});
|
|
56
|
-
|
|
61
|
+
const drag = {
|
|
62
|
+
capability: 'core',
|
|
57
63
|
schema: {
|
|
58
64
|
name: 'browser_drag',
|
|
59
65
|
description: 'Perform drag and drop between two elements',
|
|
@@ -61,14 +67,17 @@ exports.drag = {
|
|
|
61
67
|
},
|
|
62
68
|
handle: async (context, params) => {
|
|
63
69
|
const validatedParams = dragSchema.parse(params);
|
|
64
|
-
return
|
|
65
|
-
const startLocator =
|
|
66
|
-
const endLocator =
|
|
70
|
+
return await context.currentTab().runAndWaitWithSnapshot(async (tab) => {
|
|
71
|
+
const startLocator = tab.lastSnapshot().refLocator(validatedParams.startRef);
|
|
72
|
+
const endLocator = tab.lastSnapshot().refLocator(validatedParams.endRef);
|
|
67
73
|
await startLocator.dragTo(endLocator);
|
|
68
|
-
},
|
|
74
|
+
}, {
|
|
75
|
+
status: `Dragged "${validatedParams.startElement}" to "${validatedParams.endElement}"`,
|
|
76
|
+
});
|
|
69
77
|
},
|
|
70
78
|
};
|
|
71
|
-
|
|
79
|
+
const hover = {
|
|
80
|
+
capability: 'core',
|
|
72
81
|
schema: {
|
|
73
82
|
name: 'browser_hover',
|
|
74
83
|
description: 'Hover over element on page',
|
|
@@ -76,14 +85,21 @@ exports.hover = {
|
|
|
76
85
|
},
|
|
77
86
|
handle: async (context, params) => {
|
|
78
87
|
const validatedParams = elementSchema.parse(params);
|
|
79
|
-
return
|
|
88
|
+
return await context.currentTab().runAndWaitWithSnapshot(async (tab) => {
|
|
89
|
+
const locator = tab.lastSnapshot().refLocator(validatedParams.ref);
|
|
90
|
+
await locator.hover();
|
|
91
|
+
}, {
|
|
92
|
+
status: `Hovered over "${validatedParams.element}"`,
|
|
93
|
+
});
|
|
80
94
|
},
|
|
81
95
|
};
|
|
82
96
|
const typeSchema = elementSchema.extend({
|
|
83
97
|
text: zod_1.z.string().describe('Text to type into the element'),
|
|
84
|
-
submit: zod_1.z.boolean().describe('Whether to submit entered text (press Enter after)'),
|
|
98
|
+
submit: zod_1.z.boolean().optional().describe('Whether to submit entered text (press Enter after)'),
|
|
99
|
+
slowly: zod_1.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.'),
|
|
85
100
|
});
|
|
86
|
-
|
|
101
|
+
const type = {
|
|
102
|
+
capability: 'core',
|
|
87
103
|
schema: {
|
|
88
104
|
name: 'browser_type',
|
|
89
105
|
description: 'Type text into editable element',
|
|
@@ -91,18 +107,24 @@ exports.type = {
|
|
|
91
107
|
},
|
|
92
108
|
handle: async (context, params) => {
|
|
93
109
|
const validatedParams = typeSchema.parse(params);
|
|
94
|
-
return await (
|
|
95
|
-
const locator =
|
|
96
|
-
|
|
110
|
+
return await context.currentTab().runAndWaitWithSnapshot(async (tab) => {
|
|
111
|
+
const locator = tab.lastSnapshot().refLocator(validatedParams.ref);
|
|
112
|
+
if (validatedParams.slowly)
|
|
113
|
+
await locator.pressSequentially(validatedParams.text);
|
|
114
|
+
else
|
|
115
|
+
await locator.fill(validatedParams.text);
|
|
97
116
|
if (validatedParams.submit)
|
|
98
117
|
await locator.press('Enter');
|
|
99
|
-
},
|
|
118
|
+
}, {
|
|
119
|
+
status: `Typed "${validatedParams.text}" into "${validatedParams.element}"`,
|
|
120
|
+
});
|
|
100
121
|
},
|
|
101
122
|
};
|
|
102
123
|
const selectOptionSchema = elementSchema.extend({
|
|
103
124
|
values: zod_1.z.array(zod_1.z.string()).describe('Array of values to select in the dropdown. This can be a single value or multiple values.'),
|
|
104
125
|
});
|
|
105
|
-
|
|
126
|
+
const selectOption = {
|
|
127
|
+
capability: 'core',
|
|
106
128
|
schema: {
|
|
107
129
|
name: 'browser_select_option',
|
|
108
130
|
description: 'Select an option in a dropdown',
|
|
@@ -110,16 +132,19 @@ exports.selectOption = {
|
|
|
110
132
|
},
|
|
111
133
|
handle: async (context, params) => {
|
|
112
134
|
const validatedParams = selectOptionSchema.parse(params);
|
|
113
|
-
return await (
|
|
114
|
-
const locator =
|
|
135
|
+
return await context.currentTab().runAndWaitWithSnapshot(async (tab) => {
|
|
136
|
+
const locator = tab.lastSnapshot().refLocator(validatedParams.ref);
|
|
115
137
|
await locator.selectOption(validatedParams.values);
|
|
116
|
-
},
|
|
138
|
+
}, {
|
|
139
|
+
status: `Selected option in "${validatedParams.element}"`,
|
|
140
|
+
});
|
|
117
141
|
},
|
|
118
142
|
};
|
|
119
143
|
const screenshotSchema = zod_1.z.object({
|
|
120
144
|
raw: zod_1.z.boolean().optional().describe('Whether to return without compression (in PNG format). Default is false, which returns a JPEG image.'),
|
|
121
145
|
});
|
|
122
|
-
|
|
146
|
+
const screenshot = {
|
|
147
|
+
capability: 'core',
|
|
123
148
|
schema: {
|
|
124
149
|
name: 'browser_take_screenshot',
|
|
125
150
|
description: `Take a screenshot of the current page. You can't perform actions based on the screenshot, use browser_snapshot for actions.`,
|
|
@@ -127,11 +152,20 @@ exports.screenshot = {
|
|
|
127
152
|
},
|
|
128
153
|
handle: async (context, params) => {
|
|
129
154
|
const validatedParams = screenshotSchema.parse(params);
|
|
130
|
-
const
|
|
155
|
+
const tab = context.currentTab();
|
|
131
156
|
const options = validatedParams.raw ? { type: 'png', scale: 'css' } : { type: 'jpeg', quality: 50, scale: 'css' };
|
|
132
|
-
const screenshot = await page.screenshot(options);
|
|
157
|
+
const screenshot = await tab.page.screenshot(options);
|
|
133
158
|
return {
|
|
134
159
|
content: [{ type: 'image', data: screenshot.toString('base64'), mimeType: validatedParams.raw ? 'image/png' : 'image/jpeg' }],
|
|
135
160
|
};
|
|
136
161
|
},
|
|
137
162
|
};
|
|
163
|
+
exports.default = [
|
|
164
|
+
snapshot,
|
|
165
|
+
click,
|
|
166
|
+
drag,
|
|
167
|
+
hover,
|
|
168
|
+
type,
|
|
169
|
+
selectOption,
|
|
170
|
+
screenshot,
|
|
171
|
+
];
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Microsoft Corporation.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
const zod_1 = require("zod");
|
|
19
|
+
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
20
|
+
const listTabs = {
|
|
21
|
+
capability: 'tabs',
|
|
22
|
+
schema: {
|
|
23
|
+
name: 'browser_tab_list',
|
|
24
|
+
description: 'List browser tabs',
|
|
25
|
+
inputSchema: (0, zod_to_json_schema_1.zodToJsonSchema)(zod_1.z.object({})),
|
|
26
|
+
},
|
|
27
|
+
handle: async (context) => {
|
|
28
|
+
return {
|
|
29
|
+
content: [{
|
|
30
|
+
type: 'text',
|
|
31
|
+
text: await context.listTabs(),
|
|
32
|
+
}],
|
|
33
|
+
};
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
const selectTabSchema = zod_1.z.object({
|
|
37
|
+
index: zod_1.z.number().describe('The index of the tab to select'),
|
|
38
|
+
});
|
|
39
|
+
const selectTab = captureSnapshot => ({
|
|
40
|
+
capability: 'tabs',
|
|
41
|
+
schema: {
|
|
42
|
+
name: 'browser_tab_select',
|
|
43
|
+
description: 'Select a tab by index',
|
|
44
|
+
inputSchema: (0, zod_to_json_schema_1.zodToJsonSchema)(selectTabSchema),
|
|
45
|
+
},
|
|
46
|
+
handle: async (context, params) => {
|
|
47
|
+
const validatedParams = selectTabSchema.parse(params);
|
|
48
|
+
await context.selectTab(validatedParams.index);
|
|
49
|
+
const currentTab = await context.ensureTab();
|
|
50
|
+
return await currentTab.run(async () => { }, { captureSnapshot });
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
const newTabSchema = zod_1.z.object({
|
|
54
|
+
url: zod_1.z.string().optional().describe('The URL to navigate to in the new tab. If not provided, the new tab will be blank.'),
|
|
55
|
+
});
|
|
56
|
+
const newTab = {
|
|
57
|
+
capability: 'tabs',
|
|
58
|
+
schema: {
|
|
59
|
+
name: 'browser_tab_new',
|
|
60
|
+
description: 'Open a new tab',
|
|
61
|
+
inputSchema: (0, zod_to_json_schema_1.zodToJsonSchema)(newTabSchema),
|
|
62
|
+
},
|
|
63
|
+
handle: async (context, params) => {
|
|
64
|
+
const validatedParams = newTabSchema.parse(params);
|
|
65
|
+
await context.newTab();
|
|
66
|
+
if (validatedParams.url)
|
|
67
|
+
await context.currentTab().navigate(validatedParams.url);
|
|
68
|
+
return await context.currentTab().run(async () => { }, { captureSnapshot: true });
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
const closeTabSchema = zod_1.z.object({
|
|
72
|
+
index: zod_1.z.number().optional().describe('The index of the tab to close. Closes current tab if not provided.'),
|
|
73
|
+
});
|
|
74
|
+
const closeTab = captureSnapshot => ({
|
|
75
|
+
capability: 'tabs',
|
|
76
|
+
schema: {
|
|
77
|
+
name: 'browser_tab_close',
|
|
78
|
+
description: 'Close a tab',
|
|
79
|
+
inputSchema: (0, zod_to_json_schema_1.zodToJsonSchema)(closeTabSchema),
|
|
80
|
+
},
|
|
81
|
+
handle: async (context, params) => {
|
|
82
|
+
const validatedParams = closeTabSchema.parse(params);
|
|
83
|
+
await context.closeTab(validatedParams.index);
|
|
84
|
+
const currentTab = await context.currentTab();
|
|
85
|
+
if (currentTab)
|
|
86
|
+
return await currentTab.run(async () => { }, { captureSnapshot });
|
|
87
|
+
return {
|
|
88
|
+
content: [{
|
|
89
|
+
type: 'text',
|
|
90
|
+
text: await context.listTabs(),
|
|
91
|
+
}],
|
|
92
|
+
};
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
exports.default = (captureSnapshot) => [
|
|
96
|
+
listTabs,
|
|
97
|
+
newTab,
|
|
98
|
+
selectTab(captureSnapshot),
|
|
99
|
+
closeTab(captureSnapshot),
|
|
100
|
+
];
|
package/lib/tools/utils.js
CHANGED
|
@@ -15,8 +15,7 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.
|
|
19
|
-
exports.captureAriaSnapshot = captureAriaSnapshot;
|
|
18
|
+
exports.waitForCompletion = waitForCompletion;
|
|
20
19
|
exports.sanitizeForFilePath = sanitizeForFilePath;
|
|
21
20
|
async function waitForCompletion(page, callback) {
|
|
22
21
|
const requests = new Set();
|
|
@@ -65,30 +64,6 @@ async function waitForCompletion(page, callback) {
|
|
|
65
64
|
dispose();
|
|
66
65
|
}
|
|
67
66
|
}
|
|
68
|
-
async function runAndWait(context, status, callback, snapshot = false) {
|
|
69
|
-
const page = context.existingPage();
|
|
70
|
-
const dismissFileChooser = context.hasFileChooser();
|
|
71
|
-
await waitForCompletion(page, () => callback(page));
|
|
72
|
-
if (dismissFileChooser)
|
|
73
|
-
context.clearFileChooser();
|
|
74
|
-
const result = snapshot ? await captureAriaSnapshot(context, status) : {
|
|
75
|
-
content: [{ type: 'text', text: status }],
|
|
76
|
-
};
|
|
77
|
-
return result;
|
|
78
|
-
}
|
|
79
|
-
async function captureAriaSnapshot(context, status = '') {
|
|
80
|
-
const page = context.existingPage();
|
|
81
|
-
const lines = [];
|
|
82
|
-
if (status)
|
|
83
|
-
lines.push(`${status}`);
|
|
84
|
-
lines.push('', `- Page URL: ${page.url()}`, `- Page Title: ${await page.title()}`);
|
|
85
|
-
if (context.hasFileChooser())
|
|
86
|
-
lines.push(`- There is a file chooser visible that requires browser_choose_file to be called`);
|
|
87
|
-
lines.push(`- Page Snapshot`, '```yaml', await context.allFramesSnapshot(), '```', '');
|
|
88
|
-
return {
|
|
89
|
-
content: [{ type: 'text', text: lines.join('\n') }],
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
67
|
function sanitizeForFilePath(s) {
|
|
93
68
|
return s.replace(/[\x00-\x2C\x2E-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+/g, '-');
|
|
94
69
|
}
|