@playwright/mcp 0.0.13 → 0.0.15
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 +134 -30
- package/index.d.ts +37 -24
- package/lib/context.js +169 -85
- package/lib/index.js +64 -9
- package/lib/manualPromise.js +116 -0
- package/lib/program.js +4 -53
- package/lib/server.js +23 -5
- package/lib/tools/common.js +34 -38
- package/lib/{resources → tools}/console.js +23 -13
- package/lib/tools/dialogs.js +52 -0
- package/lib/tools/files.js +21 -17
- package/lib/tools/install.js +7 -8
- package/lib/tools/keyboard.js +16 -19
- package/lib/tools/navigate.js +41 -43
- package/lib/tools/network.js +51 -0
- package/lib/tools/pdf.js +47 -11
- package/lib/tools/screen.js +140 -76
- package/lib/tools/snapshot.js +145 -100
- package/lib/tools/tabs.js +52 -56
- package/lib/tools/tool.js +4 -0
- package/lib/tools/utils.js +2 -2
- package/package.json +6 -3
package/lib/tools/screen.js
CHANGED
|
@@ -14,133 +14,197 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
20
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
21
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
22
|
+
}
|
|
23
|
+
Object.defineProperty(o, k2, desc);
|
|
24
|
+
}) : (function(o, m, k, k2) {
|
|
25
|
+
if (k2 === undefined) k2 = k;
|
|
26
|
+
o[k2] = m[k];
|
|
27
|
+
}));
|
|
28
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
29
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
+
}) : function(o, v) {
|
|
31
|
+
o["default"] = v;
|
|
32
|
+
});
|
|
33
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
34
|
+
var ownKeys = function(o) {
|
|
35
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
36
|
+
var ar = [];
|
|
37
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
38
|
+
return ar;
|
|
39
|
+
};
|
|
40
|
+
return ownKeys(o);
|
|
41
|
+
};
|
|
42
|
+
return function (mod) {
|
|
43
|
+
if (mod && mod.__esModule) return mod;
|
|
44
|
+
var result = {};
|
|
45
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
46
|
+
__setModuleDefault(result, mod);
|
|
47
|
+
return result;
|
|
48
|
+
};
|
|
49
|
+
})();
|
|
17
50
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
51
|
const zod_1 = require("zod");
|
|
19
|
-
const
|
|
20
|
-
const
|
|
52
|
+
const tool_1 = require("./tool");
|
|
53
|
+
const javascript = __importStar(require("../javascript"));
|
|
54
|
+
const elementSchema = zod_1.z.object({
|
|
55
|
+
element: zod_1.z.string().describe('Human-readable element description used to obtain permission to interact with the element'),
|
|
56
|
+
});
|
|
57
|
+
const screenshot = (0, tool_1.defineTool)({
|
|
21
58
|
capability: 'core',
|
|
22
59
|
schema: {
|
|
23
60
|
name: 'browser_screen_capture',
|
|
24
61
|
description: 'Take a screenshot of the current page',
|
|
25
|
-
inputSchema:
|
|
62
|
+
inputSchema: zod_1.z.object({}),
|
|
26
63
|
},
|
|
27
64
|
handle: async (context) => {
|
|
28
65
|
const tab = await context.ensureTab();
|
|
29
|
-
const
|
|
66
|
+
const options = { type: 'jpeg', quality: 50, scale: 'css' };
|
|
67
|
+
const code = [
|
|
68
|
+
`// Take a screenshot of the current page`,
|
|
69
|
+
`await page.screenshot(${javascript.formatObject(options)});`,
|
|
70
|
+
];
|
|
71
|
+
const action = () => tab.page.screenshot(options).then(buffer => {
|
|
72
|
+
return {
|
|
73
|
+
content: [{ type: 'image', data: buffer.toString('base64'), mimeType: 'image/jpeg' }],
|
|
74
|
+
};
|
|
75
|
+
});
|
|
30
76
|
return {
|
|
31
|
-
|
|
77
|
+
code,
|
|
78
|
+
action,
|
|
79
|
+
captureSnapshot: false,
|
|
80
|
+
waitForNetwork: false
|
|
32
81
|
};
|
|
33
82
|
},
|
|
34
|
-
};
|
|
35
|
-
const elementSchema = zod_1.z.object({
|
|
36
|
-
element: zod_1.z.string().describe('Human-readable element description used to obtain permission to interact with the element'),
|
|
37
|
-
});
|
|
38
|
-
const moveMouseSchema = elementSchema.extend({
|
|
39
|
-
x: zod_1.z.number().describe('X coordinate'),
|
|
40
|
-
y: zod_1.z.number().describe('Y coordinate'),
|
|
41
83
|
});
|
|
42
|
-
const moveMouse = {
|
|
84
|
+
const moveMouse = (0, tool_1.defineTool)({
|
|
43
85
|
capability: 'core',
|
|
44
86
|
schema: {
|
|
45
87
|
name: 'browser_screen_move_mouse',
|
|
46
88
|
description: 'Move mouse to a given position',
|
|
47
|
-
inputSchema:
|
|
89
|
+
inputSchema: elementSchema.extend({
|
|
90
|
+
x: zod_1.z.number().describe('X coordinate'),
|
|
91
|
+
y: zod_1.z.number().describe('Y coordinate'),
|
|
92
|
+
}),
|
|
48
93
|
},
|
|
49
94
|
handle: async (context, params) => {
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
|
|
95
|
+
const tab = context.currentTabOrDie();
|
|
96
|
+
const code = [
|
|
97
|
+
`// Move mouse to (${params.x}, ${params.y})`,
|
|
98
|
+
`await page.mouse.move(${params.x}, ${params.y});`,
|
|
99
|
+
];
|
|
100
|
+
const action = () => tab.page.mouse.move(params.x, params.y);
|
|
53
101
|
return {
|
|
54
|
-
|
|
102
|
+
code,
|
|
103
|
+
action,
|
|
104
|
+
captureSnapshot: false,
|
|
105
|
+
waitForNetwork: false
|
|
55
106
|
};
|
|
56
107
|
},
|
|
57
|
-
};
|
|
58
|
-
const clickSchema = elementSchema.extend({
|
|
59
|
-
x: zod_1.z.number().describe('X coordinate'),
|
|
60
|
-
y: zod_1.z.number().describe('Y coordinate'),
|
|
61
108
|
});
|
|
62
|
-
const click = {
|
|
109
|
+
const click = (0, tool_1.defineTool)({
|
|
63
110
|
capability: 'core',
|
|
64
111
|
schema: {
|
|
65
112
|
name: 'browser_screen_click',
|
|
66
113
|
description: 'Click left mouse button',
|
|
67
|
-
inputSchema:
|
|
114
|
+
inputSchema: elementSchema.extend({
|
|
115
|
+
x: zod_1.z.number().describe('X coordinate'),
|
|
116
|
+
y: zod_1.z.number().describe('Y coordinate'),
|
|
117
|
+
}),
|
|
68
118
|
},
|
|
69
119
|
handle: async (context, params) => {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
await tab.page.mouse.move(
|
|
120
|
+
const tab = context.currentTabOrDie();
|
|
121
|
+
const code = [
|
|
122
|
+
`// Click mouse at coordinates (${params.x}, ${params.y})`,
|
|
123
|
+
`await page.mouse.move(${params.x}, ${params.y});`,
|
|
124
|
+
`await page.mouse.down();`,
|
|
125
|
+
`await page.mouse.up();`,
|
|
126
|
+
];
|
|
127
|
+
const action = async () => {
|
|
128
|
+
await tab.page.mouse.move(params.x, params.y);
|
|
79
129
|
await tab.page.mouse.down();
|
|
80
130
|
await tab.page.mouse.up();
|
|
81
|
-
|
|
82
|
-
|
|
131
|
+
};
|
|
132
|
+
return {
|
|
133
|
+
code,
|
|
134
|
+
action,
|
|
135
|
+
captureSnapshot: false,
|
|
136
|
+
waitForNetwork: true,
|
|
137
|
+
};
|
|
83
138
|
},
|
|
84
|
-
};
|
|
85
|
-
const dragSchema = elementSchema.extend({
|
|
86
|
-
startX: zod_1.z.number().describe('Start X coordinate'),
|
|
87
|
-
startY: zod_1.z.number().describe('Start Y coordinate'),
|
|
88
|
-
endX: zod_1.z.number().describe('End X coordinate'),
|
|
89
|
-
endY: zod_1.z.number().describe('End Y coordinate'),
|
|
90
139
|
});
|
|
91
|
-
const drag = {
|
|
140
|
+
const drag = (0, tool_1.defineTool)({
|
|
92
141
|
capability: 'core',
|
|
93
142
|
schema: {
|
|
94
143
|
name: 'browser_screen_drag',
|
|
95
144
|
description: 'Drag left mouse button',
|
|
96
|
-
inputSchema:
|
|
145
|
+
inputSchema: elementSchema.extend({
|
|
146
|
+
startX: zod_1.z.number().describe('Start X coordinate'),
|
|
147
|
+
startY: zod_1.z.number().describe('Start Y coordinate'),
|
|
148
|
+
endX: zod_1.z.number().describe('End X coordinate'),
|
|
149
|
+
endY: zod_1.z.number().describe('End Y coordinate'),
|
|
150
|
+
}),
|
|
97
151
|
},
|
|
98
152
|
handle: async (context, params) => {
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
153
|
+
const tab = context.currentTabOrDie();
|
|
154
|
+
const code = [
|
|
155
|
+
`// Drag mouse from (${params.startX}, ${params.startY}) to (${params.endX}, ${params.endY})`,
|
|
156
|
+
`await page.mouse.move(${params.startX}, ${params.startY});`,
|
|
157
|
+
`await page.mouse.down();`,
|
|
158
|
+
`await page.mouse.move(${params.endX}, ${params.endY});`,
|
|
159
|
+
`await page.mouse.up();`,
|
|
160
|
+
];
|
|
161
|
+
const action = async () => {
|
|
162
|
+
await tab.page.mouse.move(params.startX, params.startY);
|
|
102
163
|
await tab.page.mouse.down();
|
|
103
|
-
await tab.page.mouse.move(
|
|
164
|
+
await tab.page.mouse.move(params.endX, params.endY);
|
|
104
165
|
await tab.page.mouse.up();
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
return { code };
|
|
113
|
-
});
|
|
166
|
+
};
|
|
167
|
+
return {
|
|
168
|
+
code,
|
|
169
|
+
action,
|
|
170
|
+
captureSnapshot: false,
|
|
171
|
+
waitForNetwork: true,
|
|
172
|
+
};
|
|
114
173
|
},
|
|
115
|
-
};
|
|
116
|
-
const typeSchema = zod_1.z.object({
|
|
117
|
-
text: zod_1.z.string().describe('Text to type into the element'),
|
|
118
|
-
submit: zod_1.z.boolean().optional().describe('Whether to submit entered text (press Enter after)'),
|
|
119
174
|
});
|
|
120
|
-
const type = {
|
|
175
|
+
const type = (0, tool_1.defineTool)({
|
|
121
176
|
capability: 'core',
|
|
122
177
|
schema: {
|
|
123
178
|
name: 'browser_screen_type',
|
|
124
179
|
description: 'Type text',
|
|
125
|
-
inputSchema:
|
|
180
|
+
inputSchema: zod_1.z.object({
|
|
181
|
+
text: zod_1.z.string().describe('Text to type into the element'),
|
|
182
|
+
submit: zod_1.z.boolean().optional().describe('Whether to submit entered text (press Enter after)'),
|
|
183
|
+
}),
|
|
126
184
|
},
|
|
127
185
|
handle: async (context, params) => {
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
await tab.page.keyboard.type(
|
|
135
|
-
if (
|
|
136
|
-
code.push(`// Submit text`);
|
|
137
|
-
code.push(`await page.keyboard.press('Enter');`);
|
|
186
|
+
const tab = context.currentTabOrDie();
|
|
187
|
+
const code = [
|
|
188
|
+
`// Type ${params.text}`,
|
|
189
|
+
`await page.keyboard.type('${params.text}');`,
|
|
190
|
+
];
|
|
191
|
+
const action = async () => {
|
|
192
|
+
await tab.page.keyboard.type(params.text);
|
|
193
|
+
if (params.submit)
|
|
138
194
|
await tab.page.keyboard.press('Enter');
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
195
|
+
};
|
|
196
|
+
if (params.submit) {
|
|
197
|
+
code.push(`// Submit text`);
|
|
198
|
+
code.push(`await page.keyboard.press('Enter');`);
|
|
199
|
+
}
|
|
200
|
+
return {
|
|
201
|
+
code,
|
|
202
|
+
action,
|
|
203
|
+
captureSnapshot: false,
|
|
204
|
+
waitForNetwork: true,
|
|
205
|
+
};
|
|
142
206
|
},
|
|
143
|
-
};
|
|
207
|
+
});
|
|
144
208
|
exports.default = [
|
|
145
209
|
screenshot,
|
|
146
210
|
moveMouse,
|
package/lib/tools/snapshot.js
CHANGED
|
@@ -51,175 +51,220 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
51
51
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
52
52
|
};
|
|
53
53
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
const path_1 = __importDefault(require("path"));
|
|
55
|
+
const os_1 = __importDefault(require("os"));
|
|
54
56
|
const zod_1 = require("zod");
|
|
55
|
-
const
|
|
57
|
+
const utils_1 = require("./utils");
|
|
56
58
|
const context_1 = require("../context");
|
|
57
59
|
const javascript = __importStar(require("../javascript"));
|
|
58
|
-
const
|
|
60
|
+
const tool_1 = require("./tool");
|
|
61
|
+
const snapshot = (0, tool_1.defineTool)({
|
|
59
62
|
capability: 'core',
|
|
60
63
|
schema: {
|
|
61
64
|
name: 'browser_snapshot',
|
|
62
65
|
description: 'Capture accessibility snapshot of the current page, this is better than screenshot',
|
|
63
|
-
inputSchema:
|
|
66
|
+
inputSchema: zod_1.z.object({}),
|
|
64
67
|
},
|
|
65
68
|
handle: async (context) => {
|
|
66
|
-
|
|
67
|
-
return
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
await context.ensureTab();
|
|
70
|
+
return {
|
|
71
|
+
code: [`// <internal code to capture accessibility snapshot>`],
|
|
72
|
+
captureSnapshot: true,
|
|
73
|
+
waitForNetwork: false,
|
|
74
|
+
};
|
|
71
75
|
},
|
|
72
|
-
};
|
|
76
|
+
});
|
|
73
77
|
const elementSchema = zod_1.z.object({
|
|
74
78
|
element: zod_1.z.string().describe('Human-readable element description used to obtain permission to interact with the element'),
|
|
75
79
|
ref: zod_1.z.string().describe('Exact target element reference from the page snapshot'),
|
|
76
80
|
});
|
|
77
|
-
const click = {
|
|
81
|
+
const click = (0, tool_1.defineTool)({
|
|
78
82
|
capability: 'core',
|
|
79
83
|
schema: {
|
|
80
84
|
name: 'browser_click',
|
|
81
85
|
description: 'Perform click on a web page',
|
|
82
|
-
inputSchema:
|
|
86
|
+
inputSchema: elementSchema,
|
|
83
87
|
},
|
|
84
88
|
handle: async (context, params) => {
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
89
|
+
const tab = context.currentTabOrDie();
|
|
90
|
+
const locator = tab.snapshotOrDie().refLocator(params.ref);
|
|
91
|
+
const code = [
|
|
92
|
+
`// Click ${params.element}`,
|
|
93
|
+
`await page.${await (0, context_1.generateLocator)(locator)}.click();`
|
|
94
|
+
];
|
|
95
|
+
return {
|
|
96
|
+
code,
|
|
97
|
+
action: () => locator.click(),
|
|
98
|
+
captureSnapshot: true,
|
|
99
|
+
waitForNetwork: true,
|
|
100
|
+
};
|
|
95
101
|
},
|
|
96
|
-
};
|
|
97
|
-
const dragSchema = zod_1.z.object({
|
|
98
|
-
startElement: zod_1.z.string().describe('Human-readable source element description used to obtain the permission to interact with the element'),
|
|
99
|
-
startRef: zod_1.z.string().describe('Exact source element reference from the page snapshot'),
|
|
100
|
-
endElement: zod_1.z.string().describe('Human-readable target element description used to obtain the permission to interact with the element'),
|
|
101
|
-
endRef: zod_1.z.string().describe('Exact target element reference from the page snapshot'),
|
|
102
102
|
});
|
|
103
|
-
const drag = {
|
|
103
|
+
const drag = (0, tool_1.defineTool)({
|
|
104
104
|
capability: 'core',
|
|
105
105
|
schema: {
|
|
106
106
|
name: 'browser_drag',
|
|
107
107
|
description: 'Perform drag and drop between two elements',
|
|
108
|
-
inputSchema:
|
|
108
|
+
inputSchema: zod_1.z.object({
|
|
109
|
+
startElement: zod_1.z.string().describe('Human-readable source element description used to obtain the permission to interact with the element'),
|
|
110
|
+
startRef: zod_1.z.string().describe('Exact source element reference from the page snapshot'),
|
|
111
|
+
endElement: zod_1.z.string().describe('Human-readable target element description used to obtain the permission to interact with the element'),
|
|
112
|
+
endRef: zod_1.z.string().describe('Exact target element reference from the page snapshot'),
|
|
113
|
+
}),
|
|
109
114
|
},
|
|
110
115
|
handle: async (context, params) => {
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
116
|
+
const snapshot = context.currentTabOrDie().snapshotOrDie();
|
|
117
|
+
const startLocator = snapshot.refLocator(params.startRef);
|
|
118
|
+
const endLocator = snapshot.refLocator(params.endRef);
|
|
119
|
+
const code = [
|
|
120
|
+
`// Drag ${params.startElement} to ${params.endElement}`,
|
|
121
|
+
`await page.${await (0, context_1.generateLocator)(startLocator)}.dragTo(page.${await (0, context_1.generateLocator)(endLocator)});`
|
|
122
|
+
];
|
|
123
|
+
return {
|
|
124
|
+
code,
|
|
125
|
+
action: () => startLocator.dragTo(endLocator),
|
|
126
|
+
captureSnapshot: true,
|
|
127
|
+
waitForNetwork: true,
|
|
128
|
+
};
|
|
122
129
|
},
|
|
123
|
-
};
|
|
124
|
-
const hover = {
|
|
130
|
+
});
|
|
131
|
+
const hover = (0, tool_1.defineTool)({
|
|
125
132
|
capability: 'core',
|
|
126
133
|
schema: {
|
|
127
134
|
name: 'browser_hover',
|
|
128
135
|
description: 'Hover over element on page',
|
|
129
|
-
inputSchema:
|
|
136
|
+
inputSchema: elementSchema,
|
|
130
137
|
},
|
|
131
138
|
handle: async (context, params) => {
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
139
|
+
const snapshot = context.currentTabOrDie().snapshotOrDie();
|
|
140
|
+
const locator = snapshot.refLocator(params.ref);
|
|
141
|
+
const code = [
|
|
142
|
+
`// Hover over ${params.element}`,
|
|
143
|
+
`await page.${await (0, context_1.generateLocator)(locator)}.hover();`
|
|
144
|
+
];
|
|
145
|
+
return {
|
|
146
|
+
code,
|
|
147
|
+
action: () => locator.hover(),
|
|
148
|
+
captureSnapshot: true,
|
|
149
|
+
waitForNetwork: true,
|
|
150
|
+
};
|
|
142
151
|
},
|
|
143
|
-
};
|
|
152
|
+
});
|
|
144
153
|
const typeSchema = elementSchema.extend({
|
|
145
154
|
text: zod_1.z.string().describe('Text to type into the element'),
|
|
146
155
|
submit: zod_1.z.boolean().optional().describe('Whether to submit entered text (press Enter after)'),
|
|
147
156
|
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.'),
|
|
148
157
|
});
|
|
149
|
-
const type = {
|
|
158
|
+
const type = (0, tool_1.defineTool)({
|
|
150
159
|
capability: 'core',
|
|
151
160
|
schema: {
|
|
152
161
|
name: 'browser_type',
|
|
153
162
|
description: 'Type text into editable element',
|
|
154
|
-
inputSchema:
|
|
163
|
+
inputSchema: typeSchema,
|
|
155
164
|
},
|
|
156
165
|
handle: async (context, params) => {
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
166
|
+
const snapshot = context.currentTabOrDie().snapshotOrDie();
|
|
167
|
+
const locator = snapshot.refLocator(params.ref);
|
|
168
|
+
const code = [];
|
|
169
|
+
const steps = [];
|
|
170
|
+
if (params.slowly) {
|
|
171
|
+
code.push(`// Press "${params.text}" sequentially into "${params.element}"`);
|
|
172
|
+
code.push(`await page.${await (0, context_1.generateLocator)(locator)}.pressSequentially(${javascript.quote(params.text)});`);
|
|
173
|
+
steps.push(() => locator.pressSequentially(params.text));
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
code.push(`// Fill "${params.text}" into "${params.element}"`);
|
|
177
|
+
code.push(`await page.${await (0, context_1.generateLocator)(locator)}.fill(${javascript.quote(params.text)});`);
|
|
178
|
+
steps.push(() => locator.fill(params.text));
|
|
179
|
+
}
|
|
180
|
+
if (params.submit) {
|
|
181
|
+
code.push(`// Submit text`);
|
|
182
|
+
code.push(`await page.${await (0, context_1.generateLocator)(locator)}.press('Enter');`);
|
|
183
|
+
steps.push(() => locator.press('Enter'));
|
|
184
|
+
}
|
|
185
|
+
return {
|
|
186
|
+
code,
|
|
187
|
+
action: () => steps.reduce((acc, step) => acc.then(step), Promise.resolve()),
|
|
188
|
+
captureSnapshot: true,
|
|
189
|
+
waitForNetwork: true,
|
|
190
|
+
};
|
|
178
191
|
},
|
|
179
|
-
};
|
|
192
|
+
});
|
|
180
193
|
const selectOptionSchema = elementSchema.extend({
|
|
181
194
|
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.'),
|
|
182
195
|
});
|
|
183
|
-
const selectOption = {
|
|
196
|
+
const selectOption = (0, tool_1.defineTool)({
|
|
184
197
|
capability: 'core',
|
|
185
198
|
schema: {
|
|
186
199
|
name: 'browser_select_option',
|
|
187
200
|
description: 'Select an option in a dropdown',
|
|
188
|
-
inputSchema:
|
|
201
|
+
inputSchema: selectOptionSchema,
|
|
189
202
|
},
|
|
190
203
|
handle: async (context, params) => {
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
204
|
+
const snapshot = context.currentTabOrDie().snapshotOrDie();
|
|
205
|
+
const locator = snapshot.refLocator(params.ref);
|
|
206
|
+
const code = [
|
|
207
|
+
`// Select options [${params.values.join(', ')}] in ${params.element}`,
|
|
208
|
+
`await page.${await (0, context_1.generateLocator)(locator)}.selectOption(${javascript.formatObject(params.values)});`
|
|
209
|
+
];
|
|
210
|
+
return {
|
|
211
|
+
code,
|
|
212
|
+
action: () => locator.selectOption(params.values).then(() => { }),
|
|
213
|
+
captureSnapshot: true,
|
|
214
|
+
waitForNetwork: true,
|
|
215
|
+
};
|
|
201
216
|
},
|
|
202
|
-
};
|
|
217
|
+
});
|
|
203
218
|
const screenshotSchema = zod_1.z.object({
|
|
204
219
|
raw: zod_1.z.boolean().optional().describe('Whether to return without compression (in PNG format). Default is false, which returns a JPEG image.'),
|
|
220
|
+
element: zod_1.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.'),
|
|
221
|
+
ref: zod_1.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.'),
|
|
222
|
+
}).refine(data => {
|
|
223
|
+
return !!data.element === !!data.ref;
|
|
224
|
+
}, {
|
|
225
|
+
message: 'Both element and ref must be provided or neither.',
|
|
226
|
+
path: ['ref', 'element']
|
|
205
227
|
});
|
|
206
|
-
const screenshot = {
|
|
228
|
+
const screenshot = (0, tool_1.defineTool)({
|
|
207
229
|
capability: 'core',
|
|
208
230
|
schema: {
|
|
209
231
|
name: 'browser_take_screenshot',
|
|
210
232
|
description: `Take a screenshot of the current page. You can't perform actions based on the screenshot, use browser_snapshot for actions.`,
|
|
211
|
-
inputSchema:
|
|
233
|
+
inputSchema: screenshotSchema,
|
|
212
234
|
},
|
|
213
235
|
handle: async (context, params) => {
|
|
214
|
-
const
|
|
215
|
-
const
|
|
216
|
-
const
|
|
217
|
-
const
|
|
236
|
+
const tab = context.currentTabOrDie();
|
|
237
|
+
const snapshot = tab.snapshotOrDie();
|
|
238
|
+
const fileType = params.raw ? 'png' : 'jpeg';
|
|
239
|
+
const fileName = path_1.default.join(os_1.default.tmpdir(), (0, utils_1.sanitizeForFilePath)(`page-${new Date().toISOString()}`)) + `.${fileType}`;
|
|
240
|
+
const options = { type: fileType, quality: fileType === 'png' ? undefined : 50, scale: 'css', path: fileName };
|
|
241
|
+
const isElementScreenshot = params.element && params.ref;
|
|
242
|
+
const code = [
|
|
243
|
+
`// Screenshot ${isElementScreenshot ? params.element : 'viewport'} and save it as ${fileName}`,
|
|
244
|
+
];
|
|
245
|
+
const locator = params.ref ? snapshot.refLocator(params.ref) : null;
|
|
246
|
+
if (locator)
|
|
247
|
+
code.push(`await page.${await (0, context_1.generateLocator)(locator)}.screenshot(${javascript.formatObject(options)});`);
|
|
248
|
+
else
|
|
249
|
+
code.push(`await page.screenshot(${javascript.formatObject(options)});`);
|
|
250
|
+
const action = async () => {
|
|
251
|
+
const screenshot = locator ? await locator.screenshot(options) : await tab.page.screenshot(options);
|
|
252
|
+
return {
|
|
253
|
+
content: [{
|
|
254
|
+
type: 'image',
|
|
255
|
+
data: screenshot.toString('base64'),
|
|
256
|
+
mimeType: fileType === 'png' ? 'image/png' : 'image/jpeg',
|
|
257
|
+
}]
|
|
258
|
+
};
|
|
259
|
+
};
|
|
218
260
|
return {
|
|
219
|
-
|
|
261
|
+
code,
|
|
262
|
+
action,
|
|
263
|
+
captureSnapshot: true,
|
|
264
|
+
waitForNetwork: false,
|
|
220
265
|
};
|
|
221
|
-
}
|
|
222
|
-
};
|
|
266
|
+
}
|
|
267
|
+
});
|
|
223
268
|
exports.default = [
|
|
224
269
|
snapshot,
|
|
225
270
|
click,
|