@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/tabs.js
CHANGED
|
@@ -16,101 +16,97 @@
|
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
const zod_1 = require("zod");
|
|
19
|
-
const
|
|
20
|
-
const listTabs = {
|
|
19
|
+
const tool_1 = require("./tool");
|
|
20
|
+
const listTabs = (0, tool_1.defineTool)({
|
|
21
21
|
capability: 'tabs',
|
|
22
22
|
schema: {
|
|
23
23
|
name: 'browser_tab_list',
|
|
24
24
|
description: 'List browser tabs',
|
|
25
|
-
inputSchema:
|
|
25
|
+
inputSchema: zod_1.z.object({}),
|
|
26
26
|
},
|
|
27
27
|
handle: async (context) => {
|
|
28
|
+
await context.ensureTab();
|
|
28
29
|
return {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
code: [`// <internal code to list tabs>`],
|
|
31
|
+
captureSnapshot: false,
|
|
32
|
+
waitForNetwork: false,
|
|
33
|
+
resultOverride: {
|
|
34
|
+
content: [{
|
|
35
|
+
type: 'text',
|
|
36
|
+
text: await context.listTabsMarkdown(),
|
|
37
|
+
}],
|
|
38
|
+
},
|
|
33
39
|
};
|
|
34
40
|
},
|
|
35
|
-
};
|
|
36
|
-
const selectTabSchema = zod_1.z.object({
|
|
37
|
-
index: zod_1.z.number().describe('The index of the tab to select'),
|
|
38
41
|
});
|
|
39
|
-
const selectTab = captureSnapshot => ({
|
|
42
|
+
const selectTab = captureSnapshot => (0, tool_1.defineTool)({
|
|
40
43
|
capability: 'tabs',
|
|
41
44
|
schema: {
|
|
42
45
|
name: 'browser_tab_select',
|
|
43
46
|
description: 'Select a tab by index',
|
|
44
|
-
inputSchema:
|
|
47
|
+
inputSchema: zod_1.z.object({
|
|
48
|
+
index: zod_1.z.number().describe('The index of the tab to select'),
|
|
49
|
+
}),
|
|
45
50
|
},
|
|
46
51
|
handle: async (context, params) => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
52
|
+
await context.selectTab(params.index);
|
|
53
|
+
const code = [
|
|
54
|
+
`// <internal code to select tab ${params.index}>`,
|
|
55
|
+
];
|
|
56
|
+
return {
|
|
57
|
+
code,
|
|
58
|
+
captureSnapshot,
|
|
59
|
+
waitForNetwork: false
|
|
60
|
+
};
|
|
56
61
|
},
|
|
57
62
|
});
|
|
58
|
-
const
|
|
59
|
-
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.'),
|
|
60
|
-
});
|
|
61
|
-
const newTab = {
|
|
63
|
+
const newTab = captureSnapshot => (0, tool_1.defineTool)({
|
|
62
64
|
capability: 'tabs',
|
|
63
65
|
schema: {
|
|
64
66
|
name: 'browser_tab_new',
|
|
65
67
|
description: 'Open a new tab',
|
|
66
|
-
inputSchema:
|
|
68
|
+
inputSchema: zod_1.z.object({
|
|
69
|
+
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.'),
|
|
70
|
+
}),
|
|
67
71
|
},
|
|
68
72
|
handle: async (context, params) => {
|
|
69
|
-
const validatedParams = newTabSchema.parse(params);
|
|
70
73
|
await context.newTab();
|
|
71
|
-
if (
|
|
72
|
-
await context.
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
74
|
+
if (params.url)
|
|
75
|
+
await context.currentTabOrDie().navigate(params.url);
|
|
76
|
+
const code = [
|
|
77
|
+
`// <internal code to open a new tab>`,
|
|
78
|
+
];
|
|
79
|
+
return {
|
|
80
|
+
code,
|
|
81
|
+
captureSnapshot,
|
|
82
|
+
waitForNetwork: false
|
|
83
|
+
};
|
|
79
84
|
},
|
|
80
|
-
};
|
|
81
|
-
const closeTabSchema = zod_1.z.object({
|
|
82
|
-
index: zod_1.z.number().optional().describe('The index of the tab to close. Closes current tab if not provided.'),
|
|
83
85
|
});
|
|
84
|
-
const closeTab = captureSnapshot => ({
|
|
86
|
+
const closeTab = captureSnapshot => (0, tool_1.defineTool)({
|
|
85
87
|
capability: 'tabs',
|
|
86
88
|
schema: {
|
|
87
89
|
name: 'browser_tab_close',
|
|
88
90
|
description: 'Close a tab',
|
|
89
|
-
inputSchema:
|
|
91
|
+
inputSchema: zod_1.z.object({
|
|
92
|
+
index: zod_1.z.number().optional().describe('The index of the tab to close. Closes current tab if not provided.'),
|
|
93
|
+
}),
|
|
90
94
|
},
|
|
91
95
|
handle: async (context, params) => {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return await currentTab.run(async () => {
|
|
97
|
-
const code = [
|
|
98
|
-
`// <internal code to close tab ${validatedParams.index}>`,
|
|
99
|
-
];
|
|
100
|
-
return { code };
|
|
101
|
-
}, { captureSnapshot });
|
|
102
|
-
}
|
|
96
|
+
await context.closeTab(params.index);
|
|
97
|
+
const code = [
|
|
98
|
+
`// <internal code to close tab ${params.index}>`,
|
|
99
|
+
];
|
|
103
100
|
return {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}],
|
|
101
|
+
code,
|
|
102
|
+
captureSnapshot,
|
|
103
|
+
waitForNetwork: false
|
|
108
104
|
};
|
|
109
105
|
},
|
|
110
106
|
});
|
|
111
107
|
exports.default = (captureSnapshot) => [
|
|
112
108
|
listTabs,
|
|
113
|
-
newTab,
|
|
109
|
+
newTab(captureSnapshot),
|
|
114
110
|
selectTab(captureSnapshot),
|
|
115
111
|
closeTab(captureSnapshot),
|
|
116
112
|
];
|
package/lib/tools/tool.js
CHANGED
package/lib/tools/utils.js
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.waitForCompletion = waitForCompletion;
|
|
19
19
|
exports.sanitizeForFilePath = sanitizeForFilePath;
|
|
20
|
-
async function waitForCompletion(page, callback) {
|
|
20
|
+
async function waitForCompletion(context, page, callback) {
|
|
21
21
|
const requests = new Set();
|
|
22
22
|
let frameNavigated = false;
|
|
23
23
|
let waitCallback = () => { };
|
|
@@ -57,7 +57,7 @@ async function waitForCompletion(page, callback) {
|
|
|
57
57
|
if (!requests.size && !frameNavigated)
|
|
58
58
|
waitCallback();
|
|
59
59
|
await waitBarrier;
|
|
60
|
-
await
|
|
60
|
+
await context.waitForTimeout(1000);
|
|
61
61
|
return result;
|
|
62
62
|
}
|
|
63
63
|
finally {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@playwright/mcp",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.15",
|
|
4
4
|
"description": "Playwright Tools for MCP",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -17,9 +17,12 @@
|
|
|
17
17
|
"scripts": {
|
|
18
18
|
"build": "tsc",
|
|
19
19
|
"lint": "eslint .",
|
|
20
|
+
"update-readme": "node utils/update-readme.js",
|
|
20
21
|
"watch": "tsc --watch",
|
|
21
22
|
"test": "playwright test",
|
|
22
23
|
"ctest": "playwright test --project=chrome",
|
|
24
|
+
"ftest": "playwright test --project=firefox",
|
|
25
|
+
"wtest": "playwright test --project=webkit",
|
|
23
26
|
"clean": "rm -rf lib",
|
|
24
27
|
"npm-publish": "npm run clean && npm run build && npm run test && npm publish"
|
|
25
28
|
},
|
|
@@ -33,14 +36,14 @@
|
|
|
33
36
|
"dependencies": {
|
|
34
37
|
"@modelcontextprotocol/sdk": "^1.6.1",
|
|
35
38
|
"commander": "^13.1.0",
|
|
36
|
-
"playwright": "
|
|
39
|
+
"playwright": "1.53.0-alpha-1745357020000",
|
|
37
40
|
"yaml": "^2.7.1",
|
|
38
41
|
"zod-to-json-schema": "^3.24.4"
|
|
39
42
|
},
|
|
40
43
|
"devDependencies": {
|
|
41
44
|
"@eslint/eslintrc": "^3.2.0",
|
|
42
45
|
"@eslint/js": "^9.19.0",
|
|
43
|
-
"@playwright/test": "
|
|
46
|
+
"@playwright/test": "1.53.0-alpha-1745357020000",
|
|
44
47
|
"@stylistic/eslint-plugin": "^3.0.1",
|
|
45
48
|
"@types/node": "^22.13.10",
|
|
46
49
|
"@typescript-eslint/eslint-plugin": "^8.26.1",
|