@playwright/mcp 0.0.30 → 0.0.32

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.
Files changed (54) hide show
  1. package/README.md +180 -320
  2. package/config.d.ts +5 -14
  3. package/index.d.ts +1 -6
  4. package/lib/browserContextFactory.js +3 -35
  5. package/lib/browserServerBackend.js +54 -0
  6. package/lib/config.js +64 -7
  7. package/lib/context.js +50 -163
  8. package/lib/extension/cdpRelay.js +370 -0
  9. package/lib/extension/main.js +33 -0
  10. package/lib/httpServer.js +20 -182
  11. package/lib/index.js +3 -2
  12. package/lib/log.js +21 -0
  13. package/lib/loop/loop.js +69 -0
  14. package/lib/loop/loopClaude.js +152 -0
  15. package/lib/loop/loopOpenAI.js +141 -0
  16. package/lib/loop/main.js +60 -0
  17. package/lib/loopTools/context.js +66 -0
  18. package/lib/loopTools/main.js +49 -0
  19. package/lib/loopTools/perform.js +32 -0
  20. package/lib/loopTools/snapshot.js +29 -0
  21. package/lib/loopTools/tool.js +18 -0
  22. package/lib/mcp/inProcessTransport.js +72 -0
  23. package/lib/mcp/server.js +88 -0
  24. package/lib/{transport.js → mcp/transport.js} +30 -42
  25. package/lib/package.js +3 -3
  26. package/lib/program.js +47 -17
  27. package/lib/response.js +98 -0
  28. package/lib/sessionLog.js +70 -0
  29. package/lib/tab.js +166 -21
  30. package/lib/tools/common.js +13 -25
  31. package/lib/tools/console.js +4 -15
  32. package/lib/tools/dialogs.js +14 -19
  33. package/lib/tools/evaluate.js +53 -0
  34. package/lib/tools/files.js +13 -19
  35. package/lib/tools/install.js +4 -8
  36. package/lib/tools/keyboard.js +51 -17
  37. package/lib/tools/mouse.js +99 -0
  38. package/lib/tools/navigate.js +22 -42
  39. package/lib/tools/network.js +5 -15
  40. package/lib/tools/pdf.js +8 -15
  41. package/lib/tools/screenshot.js +29 -30
  42. package/lib/tools/snapshot.js +49 -109
  43. package/lib/tools/tabs.js +21 -52
  44. package/lib/tools/tool.js +14 -0
  45. package/lib/tools/utils.js +7 -6
  46. package/lib/tools/wait.js +8 -11
  47. package/lib/tools.js +15 -26
  48. package/package.json +12 -5
  49. package/lib/browserServer.js +0 -151
  50. package/lib/connection.js +0 -82
  51. package/lib/pageSnapshot.js +0 -43
  52. package/lib/server.js +0 -48
  53. package/lib/tools/testing.js +0 -60
  54. package/lib/tools/vision.js +0 -189
@@ -1,60 +0,0 @@
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 generateTestSchema = z.object({
19
- name: z.string().describe('The name of the test'),
20
- description: z.string().describe('The description of the test'),
21
- steps: z.array(z.string()).describe('The steps of the test'),
22
- });
23
- const generateTest = defineTool({
24
- capability: 'testing',
25
- schema: {
26
- name: 'browser_generate_playwright_test',
27
- title: 'Generate a Playwright test',
28
- description: 'Generate a Playwright test for given scenario',
29
- inputSchema: generateTestSchema,
30
- type: 'readOnly',
31
- },
32
- handle: async (context, params) => {
33
- return {
34
- resultOverride: {
35
- content: [{
36
- type: 'text',
37
- text: instructions(params),
38
- }],
39
- },
40
- code: [],
41
- captureSnapshot: false,
42
- waitForNetwork: false,
43
- };
44
- },
45
- });
46
- const instructions = (params) => [
47
- `## Instructions`,
48
- `- You are a playwright test generator.`,
49
- `- You are given a scenario and you need to generate a playwright test for it.`,
50
- '- DO NOT generate test code based on the scenario alone. DO run steps one by one using the tools provided instead.',
51
- '- Only after all steps are completed, emit a Playwright TypeScript test that uses @playwright/test based on message history',
52
- '- Save generated test file in the tests directory',
53
- `Test name: ${params.name}`,
54
- `Description: ${params.description}`,
55
- `Steps:`,
56
- ...params.steps.map((step, index) => `- ${index + 1}. ${step}`),
57
- ].join('\n');
58
- export default [
59
- generateTest,
60
- ];
@@ -1,189 +0,0 @@
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
- import * as javascript from '../javascript.js';
19
- const elementSchema = z.object({
20
- element: z.string().describe('Human-readable element description used to obtain permission to interact with the element'),
21
- });
22
- const screenshot = defineTool({
23
- capability: 'core',
24
- schema: {
25
- name: 'browser_screen_capture',
26
- title: 'Take a screenshot',
27
- description: 'Take a screenshot of the current page',
28
- inputSchema: z.object({}),
29
- type: 'readOnly',
30
- },
31
- handle: async (context) => {
32
- const tab = await context.ensureTab();
33
- const options = { type: 'jpeg', quality: 50, scale: 'css' };
34
- const code = [
35
- `// Take a screenshot of the current page`,
36
- `await page.screenshot(${javascript.formatObject(options)});`,
37
- ];
38
- const action = () => tab.page.screenshot(options).then(buffer => {
39
- return {
40
- content: [{ type: 'image', data: buffer.toString('base64'), mimeType: 'image/jpeg' }],
41
- };
42
- });
43
- return {
44
- code,
45
- action,
46
- captureSnapshot: false,
47
- waitForNetwork: false
48
- };
49
- },
50
- });
51
- const moveMouse = defineTool({
52
- capability: 'core',
53
- schema: {
54
- name: 'browser_screen_move_mouse',
55
- title: 'Move mouse',
56
- description: 'Move mouse to a given position',
57
- inputSchema: elementSchema.extend({
58
- x: z.number().describe('X coordinate'),
59
- y: z.number().describe('Y coordinate'),
60
- }),
61
- type: 'readOnly',
62
- },
63
- handle: async (context, params) => {
64
- const tab = context.currentTabOrDie();
65
- const code = [
66
- `// Move mouse to (${params.x}, ${params.y})`,
67
- `await page.mouse.move(${params.x}, ${params.y});`,
68
- ];
69
- const action = () => tab.page.mouse.move(params.x, params.y);
70
- return {
71
- code,
72
- action,
73
- captureSnapshot: false,
74
- waitForNetwork: false
75
- };
76
- },
77
- });
78
- const click = defineTool({
79
- capability: 'core',
80
- schema: {
81
- name: 'browser_screen_click',
82
- title: 'Click',
83
- description: 'Click left mouse button',
84
- inputSchema: elementSchema.extend({
85
- x: z.number().describe('X coordinate'),
86
- y: z.number().describe('Y coordinate'),
87
- }),
88
- type: 'destructive',
89
- },
90
- handle: async (context, params) => {
91
- const tab = context.currentTabOrDie();
92
- const code = [
93
- `// Click mouse at coordinates (${params.x}, ${params.y})`,
94
- `await page.mouse.move(${params.x}, ${params.y});`,
95
- `await page.mouse.down();`,
96
- `await page.mouse.up();`,
97
- ];
98
- const action = async () => {
99
- await tab.page.mouse.move(params.x, params.y);
100
- await tab.page.mouse.down();
101
- await tab.page.mouse.up();
102
- };
103
- return {
104
- code,
105
- action,
106
- captureSnapshot: false,
107
- waitForNetwork: true,
108
- };
109
- },
110
- });
111
- const drag = defineTool({
112
- capability: 'core',
113
- schema: {
114
- name: 'browser_screen_drag',
115
- title: 'Drag mouse',
116
- description: 'Drag left mouse button',
117
- inputSchema: elementSchema.extend({
118
- startX: z.number().describe('Start X coordinate'),
119
- startY: z.number().describe('Start Y coordinate'),
120
- endX: z.number().describe('End X coordinate'),
121
- endY: z.number().describe('End Y coordinate'),
122
- }),
123
- type: 'destructive',
124
- },
125
- handle: async (context, params) => {
126
- const tab = context.currentTabOrDie();
127
- const code = [
128
- `// Drag mouse from (${params.startX}, ${params.startY}) to (${params.endX}, ${params.endY})`,
129
- `await page.mouse.move(${params.startX}, ${params.startY});`,
130
- `await page.mouse.down();`,
131
- `await page.mouse.move(${params.endX}, ${params.endY});`,
132
- `await page.mouse.up();`,
133
- ];
134
- const action = async () => {
135
- await tab.page.mouse.move(params.startX, params.startY);
136
- await tab.page.mouse.down();
137
- await tab.page.mouse.move(params.endX, params.endY);
138
- await tab.page.mouse.up();
139
- };
140
- return {
141
- code,
142
- action,
143
- captureSnapshot: false,
144
- waitForNetwork: true,
145
- };
146
- },
147
- });
148
- const type = defineTool({
149
- capability: 'core',
150
- schema: {
151
- name: 'browser_screen_type',
152
- title: 'Type text',
153
- description: 'Type text',
154
- inputSchema: z.object({
155
- text: z.string().describe('Text to type into the element'),
156
- submit: z.boolean().optional().describe('Whether to submit entered text (press Enter after)'),
157
- }),
158
- type: 'destructive',
159
- },
160
- handle: async (context, params) => {
161
- const tab = context.currentTabOrDie();
162
- const code = [
163
- `// Type ${params.text}`,
164
- `await page.keyboard.type('${params.text}');`,
165
- ];
166
- const action = async () => {
167
- await tab.page.keyboard.type(params.text);
168
- if (params.submit)
169
- await tab.page.keyboard.press('Enter');
170
- };
171
- if (params.submit) {
172
- code.push(`// Submit text`);
173
- code.push(`await page.keyboard.press('Enter');`);
174
- }
175
- return {
176
- code,
177
- action,
178
- captureSnapshot: false,
179
- waitForNetwork: true,
180
- };
181
- },
182
- });
183
- export default [
184
- screenshot,
185
- moveMouse,
186
- click,
187
- drag,
188
- type,
189
- ];