@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/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 zod_to_json_schema_1 = require("zod-to-json-schema");
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: (0, zod_to_json_schema_1.zodToJsonSchema)(zod_1.z.object({})),
25
+ inputSchema: zod_1.z.object({}),
26
26
  },
27
27
  handle: async (context) => {
28
+ await context.ensureTab();
28
29
  return {
29
- content: [{
30
- type: 'text',
31
- text: await context.listTabs(),
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: (0, zod_to_json_schema_1.zodToJsonSchema)(selectTabSchema),
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
- const validatedParams = selectTabSchema.parse(params);
48
- await context.selectTab(validatedParams.index);
49
- const currentTab = await context.ensureTab();
50
- return await currentTab.run(async () => {
51
- const code = [
52
- `// <internal code to select tab ${validatedParams.index}>`,
53
- ];
54
- return { code };
55
- }, { captureSnapshot });
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 newTabSchema = zod_1.z.object({
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: (0, zod_to_json_schema_1.zodToJsonSchema)(newTabSchema),
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 (validatedParams.url)
72
- await context.currentTab().navigate(validatedParams.url);
73
- return await context.currentTab().run(async () => {
74
- const code = [
75
- `// <internal code to open a new tab>`,
76
- ];
77
- return { code };
78
- }, { captureSnapshot: true });
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: (0, zod_to_json_schema_1.zodToJsonSchema)(closeTabSchema),
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
- const validatedParams = closeTabSchema.parse(params);
93
- await context.closeTab(validatedParams.index);
94
- const currentTab = context.currentTab();
95
- if (currentTab) {
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
- content: [{
105
- type: 'text',
106
- text: await context.listTabs(),
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
@@ -15,3 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.defineTool = defineTool;
19
+ function defineTool(tool) {
20
+ return tool;
21
+ }
@@ -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 page.evaluate(() => new Promise(f => setTimeout(f, 1000)));
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.13",
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": "^1.52.0-alpha-1743163434000",
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": "^1.52.0-alpha-1743163434000",
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",