@playwright/mcp 0.0.22 → 0.0.25
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 +363 -186
- package/config.d.ts +6 -1
- package/index.js +1 -1
- package/lib/config.js +45 -5
- package/lib/connection.js +2 -2
- package/lib/context.js +50 -41
- package/lib/index.js +2 -1
- package/lib/pageSnapshot.js +8 -55
- package/lib/program.js +22 -13
- package/lib/tab.js +6 -9
- package/lib/tools/common.js +1 -22
- package/lib/tools/console.js +1 -1
- package/lib/tools/install.js +1 -1
- package/lib/tools/pdf.js +6 -3
- package/lib/tools/screenshot.js +77 -0
- package/lib/tools/snapshot.js +1 -58
- package/lib/tools/utils.js +3 -0
- package/lib/tools/wait.js +59 -0
- package/lib/tools.js +8 -3
- package/package.json +3 -4
- /package/lib/tools/{screen.js → vision.js} +0 -0
package/lib/tools/snapshot.js
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
import { z } from 'zod';
|
|
17
17
|
import { defineTool } from './tool.js';
|
|
18
18
|
import * as javascript from '../javascript.js';
|
|
19
|
-
import {
|
|
19
|
+
import { generateLocator } from './utils.js';
|
|
20
20
|
const snapshot = defineTool({
|
|
21
21
|
capability: 'core',
|
|
22
22
|
schema: {
|
|
@@ -186,62 +186,6 @@ const selectOption = defineTool({
|
|
|
186
186
|
};
|
|
187
187
|
},
|
|
188
188
|
});
|
|
189
|
-
const screenshotSchema = z.object({
|
|
190
|
-
raw: z.boolean().optional().describe('Whether to return without compression (in PNG format). Default is false, which returns a JPEG image.'),
|
|
191
|
-
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.'),
|
|
192
|
-
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.'),
|
|
193
|
-
}).refine(data => {
|
|
194
|
-
return !!data.element === !!data.ref;
|
|
195
|
-
}, {
|
|
196
|
-
message: 'Both element and ref must be provided or neither.',
|
|
197
|
-
path: ['ref', 'element']
|
|
198
|
-
});
|
|
199
|
-
const screenshot = defineTool({
|
|
200
|
-
capability: 'core',
|
|
201
|
-
schema: {
|
|
202
|
-
name: 'browser_take_screenshot',
|
|
203
|
-
title: 'Take a screenshot',
|
|
204
|
-
description: `Take a screenshot of the current page. You can't perform actions based on the screenshot, use browser_snapshot for actions.`,
|
|
205
|
-
inputSchema: screenshotSchema,
|
|
206
|
-
type: 'readOnly',
|
|
207
|
-
},
|
|
208
|
-
handle: async (context, params) => {
|
|
209
|
-
const tab = context.currentTabOrDie();
|
|
210
|
-
const snapshot = tab.snapshotOrDie();
|
|
211
|
-
const fileType = params.raw ? 'png' : 'jpeg';
|
|
212
|
-
const fileName = await outputFile(context.config, `page-${new Date().toISOString()}.${fileType}`);
|
|
213
|
-
const options = { type: fileType, quality: fileType === 'png' ? undefined : 50, scale: 'css', path: fileName };
|
|
214
|
-
const isElementScreenshot = params.element && params.ref;
|
|
215
|
-
const code = [
|
|
216
|
-
`// Screenshot ${isElementScreenshot ? params.element : 'viewport'} and save it as ${fileName}`,
|
|
217
|
-
];
|
|
218
|
-
const locator = params.ref ? snapshot.refLocator(params.ref) : null;
|
|
219
|
-
if (locator)
|
|
220
|
-
code.push(`await page.${await generateLocator(locator)}.screenshot(${javascript.formatObject(options)});`);
|
|
221
|
-
else
|
|
222
|
-
code.push(`await page.screenshot(${javascript.formatObject(options)});`);
|
|
223
|
-
const includeBase64 = !context.config.noImageResponses;
|
|
224
|
-
const action = async () => {
|
|
225
|
-
const screenshot = locator ? await locator.screenshot(options) : await tab.page.screenshot(options);
|
|
226
|
-
return {
|
|
227
|
-
content: includeBase64 ? [{
|
|
228
|
-
type: 'image',
|
|
229
|
-
data: screenshot.toString('base64'),
|
|
230
|
-
mimeType: fileType === 'png' ? 'image/png' : 'image/jpeg',
|
|
231
|
-
}] : []
|
|
232
|
-
};
|
|
233
|
-
};
|
|
234
|
-
return {
|
|
235
|
-
code,
|
|
236
|
-
action,
|
|
237
|
-
captureSnapshot: true,
|
|
238
|
-
waitForNetwork: false,
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
});
|
|
242
|
-
export async function generateLocator(locator) {
|
|
243
|
-
return locator._generateLocatorString();
|
|
244
|
-
}
|
|
245
189
|
export default [
|
|
246
190
|
snapshot,
|
|
247
191
|
click,
|
|
@@ -249,5 +193,4 @@ export default [
|
|
|
249
193
|
hover,
|
|
250
194
|
type,
|
|
251
195
|
selectOption,
|
|
252
|
-
screenshot,
|
|
253
196
|
];
|
package/lib/tools/utils.js
CHANGED
|
@@ -0,0 +1,59 @@
|
|
|
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 { defineTool } from './tool.js';
|
|
18
|
+
const wait = captureSnapshot => defineTool({
|
|
19
|
+
capability: 'wait',
|
|
20
|
+
schema: {
|
|
21
|
+
name: 'browser_wait_for',
|
|
22
|
+
title: 'Wait for',
|
|
23
|
+
description: 'Wait for text to appear or disappear or a specified time to pass',
|
|
24
|
+
inputSchema: z.object({
|
|
25
|
+
time: z.number().optional().describe('The time to wait in seconds'),
|
|
26
|
+
text: z.string().optional().describe('The text to wait for'),
|
|
27
|
+
textGone: z.string().optional().describe('The text to wait for to disappear'),
|
|
28
|
+
}),
|
|
29
|
+
type: 'readOnly',
|
|
30
|
+
},
|
|
31
|
+
handle: async (context, params) => {
|
|
32
|
+
if (!params.text && !params.textGone && !params.time)
|
|
33
|
+
throw new Error('Either time, text or textGone must be provided');
|
|
34
|
+
const code = [];
|
|
35
|
+
if (params.time) {
|
|
36
|
+
code.push(`await new Promise(f => setTimeout(f, ${params.time} * 1000));`);
|
|
37
|
+
await new Promise(f => setTimeout(f, Math.min(10000, params.time * 1000)));
|
|
38
|
+
}
|
|
39
|
+
const tab = context.currentTabOrDie();
|
|
40
|
+
const locator = params.text ? tab.page.getByText(params.text).first() : undefined;
|
|
41
|
+
const goneLocator = params.textGone ? tab.page.getByText(params.textGone).first() : undefined;
|
|
42
|
+
if (goneLocator) {
|
|
43
|
+
code.push(`await page.getByText(${JSON.stringify(params.textGone)}).first().waitFor({ state: 'hidden' });`);
|
|
44
|
+
await goneLocator.waitFor({ state: 'hidden' });
|
|
45
|
+
}
|
|
46
|
+
if (locator) {
|
|
47
|
+
code.push(`await page.getByText(${JSON.stringify(params.text)}).first().waitFor({ state: 'visible' });`);
|
|
48
|
+
await locator.waitFor({ state: 'visible' });
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
code,
|
|
52
|
+
captureSnapshot,
|
|
53
|
+
waitForNetwork: false,
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
export default (captureSnapshot) => [
|
|
58
|
+
wait(captureSnapshot),
|
|
59
|
+
];
|
package/lib/tools.js
CHANGED
|
@@ -24,8 +24,10 @@ import network from './tools/network.js';
|
|
|
24
24
|
import pdf from './tools/pdf.js';
|
|
25
25
|
import snapshot from './tools/snapshot.js';
|
|
26
26
|
import tabs from './tools/tabs.js';
|
|
27
|
-
import
|
|
27
|
+
import screenshot from './tools/screenshot.js';
|
|
28
28
|
import testing from './tools/testing.js';
|
|
29
|
+
import vision from './tools/vision.js';
|
|
30
|
+
import wait from './tools/wait.js';
|
|
29
31
|
export const snapshotTools = [
|
|
30
32
|
...common(true),
|
|
31
33
|
...console,
|
|
@@ -36,11 +38,13 @@ export const snapshotTools = [
|
|
|
36
38
|
...navigate(true),
|
|
37
39
|
...network,
|
|
38
40
|
...pdf,
|
|
41
|
+
...screenshot,
|
|
39
42
|
...snapshot,
|
|
40
43
|
...tabs(true),
|
|
41
44
|
...testing,
|
|
45
|
+
...wait(true),
|
|
42
46
|
];
|
|
43
|
-
export const
|
|
47
|
+
export const visionTools = [
|
|
44
48
|
...common(false),
|
|
45
49
|
...console,
|
|
46
50
|
...dialogs(false),
|
|
@@ -50,7 +54,8 @@ export const screenshotTools = [
|
|
|
50
54
|
...navigate(false),
|
|
51
55
|
...network,
|
|
52
56
|
...pdf,
|
|
53
|
-
...screen,
|
|
54
57
|
...tabs(false),
|
|
55
58
|
...testing,
|
|
59
|
+
...vision,
|
|
60
|
+
...wait(false),
|
|
56
61
|
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@playwright/mcp",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.25",
|
|
4
4
|
"description": "Playwright Tools for MCP",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -37,14 +37,13 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@modelcontextprotocol/sdk": "^1.11.0",
|
|
39
39
|
"commander": "^13.1.0",
|
|
40
|
-
"playwright": "1.53.0-alpha-
|
|
41
|
-
"yaml": "^2.7.1",
|
|
40
|
+
"playwright": "1.53.0-alpha-1746832516000",
|
|
42
41
|
"zod-to-json-schema": "^3.24.4"
|
|
43
42
|
},
|
|
44
43
|
"devDependencies": {
|
|
45
44
|
"@eslint/eslintrc": "^3.2.0",
|
|
46
45
|
"@eslint/js": "^9.19.0",
|
|
47
|
-
"@playwright/test": "1.53.0-alpha-
|
|
46
|
+
"@playwright/test": "1.53.0-alpha-1746832516000",
|
|
48
47
|
"@stylistic/eslint-plugin": "^3.0.1",
|
|
49
48
|
"@types/node": "^22.13.10",
|
|
50
49
|
"@typescript-eslint/eslint-plugin": "^8.26.1",
|
|
File without changes
|