@playwright/mcp 0.0.36-alpha-2025-09-03 → 0.0.36-alpha-2025-09-04

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 (68) hide show
  1. package/cli.js +1 -1
  2. package/index.d.ts +1 -1
  3. package/index.js +2 -2
  4. package/lib/{browserContextFactory.js → browser/browserContextFactory.js} +76 -36
  5. package/lib/{browserServerBackend.js → browser/browserServerBackend.js} +24 -22
  6. package/lib/{utils → browser}/codegen.js +8 -3
  7. package/lib/{config.js → browser/config.js} +43 -26
  8. package/lib/{context.js → browser/context.js} +27 -30
  9. package/lib/{response.js → browser/response.js} +14 -14
  10. package/lib/{sessionLog.js → browser/sessionLog.js} +23 -18
  11. package/lib/{tab.js → browser/tab.js} +29 -27
  12. package/lib/{tools → browser/tools}/common.js +11 -9
  13. package/lib/{tools → browser/tools}/console.js +7 -5
  14. package/lib/{tools → browser/tools}/dialogs.js +9 -7
  15. package/lib/browser/tools/evaluate.js +88 -0
  16. package/lib/{tools → browser/tools}/files.js +8 -6
  17. package/lib/browser/tools/form.js +92 -0
  18. package/lib/{tools → browser/tools}/install.js +18 -14
  19. package/lib/browser/tools/keyboard.js +113 -0
  20. package/lib/{tools → browser/tools}/mouse.js +18 -16
  21. package/lib/{tools → browser/tools}/navigate.js +10 -8
  22. package/lib/{tools → browser/tools}/network.js +7 -5
  23. package/lib/browser/tools/pdf.js +76 -0
  24. package/lib/browser/tools/screenshot.js +115 -0
  25. package/lib/browser/tools/snapshot.js +175 -0
  26. package/lib/{tools → browser/tools}/tabs.js +9 -7
  27. package/lib/{tools → browser/tools}/tool.js +6 -2
  28. package/lib/{tools → browser/tools}/utils.js +10 -5
  29. package/lib/{tools → browser/tools}/verify.js +59 -24
  30. package/lib/{tools → browser/tools}/wait.js +10 -8
  31. package/lib/browser/tools.js +61 -0
  32. package/lib/extension/cdpRelay.js +85 -48
  33. package/lib/extension/extensionContextFactory.js +48 -11
  34. package/lib/extension/protocol.js +4 -1
  35. package/lib/index.js +47 -12
  36. package/lib/{utils/log.js → log.js} +11 -4
  37. package/lib/{utils/package.js → package.js} +9 -5
  38. package/lib/program.js +68 -39
  39. package/lib/sdk/bundle.js +79 -0
  40. package/lib/{mcp → sdk}/http.js +57 -17
  41. package/lib/{mcp → sdk}/inProcessTransport.js +15 -20
  42. package/lib/{mcp → sdk}/manualPromise.js +11 -9
  43. package/lib/{mcp → sdk}/mdb.js +77 -38
  44. package/lib/{mcp → sdk}/proxyBackend.js +53 -16
  45. package/lib/sdk/server.js +164 -0
  46. package/lib/{mcp → sdk}/tool.js +8 -4
  47. package/lib/vscode/host.js +64 -35
  48. package/lib/vscode/main.js +48 -13
  49. package/package.json +6 -7
  50. package/lib/loop/loop.js +0 -69
  51. package/lib/loop/loopClaude.js +0 -152
  52. package/lib/loop/loopOpenAI.js +0 -141
  53. package/lib/loop/main.js +0 -60
  54. package/lib/loopTools/context.js +0 -67
  55. package/lib/loopTools/main.js +0 -54
  56. package/lib/loopTools/perform.js +0 -32
  57. package/lib/loopTools/snapshot.js +0 -29
  58. package/lib/loopTools/tool.js +0 -18
  59. package/lib/mcp/server.js +0 -123
  60. package/lib/tools/evaluate.js +0 -53
  61. package/lib/tools/form.js +0 -57
  62. package/lib/tools/keyboard.js +0 -78
  63. package/lib/tools/pdf.js +0 -40
  64. package/lib/tools/screenshot.js +0 -79
  65. package/lib/tools/snapshot.js +0 -139
  66. package/lib/tools.js +0 -54
  67. package/lib/utils/fileUtils.js +0 -36
  68. package/lib/utils/guid.js +0 -22
@@ -1,79 +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 { defineTabTool } from './tool.js';
18
- import * as javascript from '../utils/codegen.js';
19
- import { generateLocator } from './utils.js';
20
- const screenshotSchema = z.object({
21
- type: z.enum(['png', 'jpeg']).default('png').describe('Image format for the screenshot. Default is png.'),
22
- filename: z.string().optional().describe('File name to save the screenshot to. Defaults to `page-{timestamp}.{png|jpeg}` if not specified.'),
23
- 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.'),
24
- 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.'),
25
- fullPage: z.boolean().optional().describe('When true, takes a screenshot of the full scrollable page, instead of the currently visible viewport. Cannot be used with element screenshots.'),
26
- }).refine(data => {
27
- return !!data.element === !!data.ref;
28
- }, {
29
- message: 'Both element and ref must be provided or neither.',
30
- path: ['ref', 'element']
31
- }).refine(data => {
32
- return !(data.fullPage && (data.element || data.ref));
33
- }, {
34
- message: 'fullPage cannot be used with element screenshots.',
35
- path: ['fullPage']
36
- });
37
- const screenshot = defineTabTool({
38
- capability: 'core',
39
- schema: {
40
- name: 'browser_take_screenshot',
41
- title: 'Take a screenshot',
42
- description: `Take a screenshot of the current page. You can't perform actions based on the screenshot, use browser_snapshot for actions.`,
43
- inputSchema: screenshotSchema,
44
- type: 'readOnly',
45
- },
46
- handle: async (tab, params, response) => {
47
- const fileType = params.type || 'png';
48
- const fileName = await tab.context.outputFile(params.filename ?? `page-${new Date().toISOString()}.${fileType}`);
49
- const options = {
50
- type: fileType,
51
- quality: fileType === 'png' ? undefined : 90,
52
- scale: 'css',
53
- path: fileName,
54
- ...(params.fullPage !== undefined && { fullPage: params.fullPage })
55
- };
56
- const isElementScreenshot = params.element && params.ref;
57
- const screenshotTarget = isElementScreenshot ? params.element : (params.fullPage ? 'full page' : 'viewport');
58
- response.addCode(`// Screenshot ${screenshotTarget} and save it as ${fileName}`);
59
- // Only get snapshot when element screenshot is needed
60
- const locator = params.ref ? await tab.refLocator({ element: params.element || '', ref: params.ref }) : null;
61
- if (locator)
62
- response.addCode(`await page.${await generateLocator(locator)}.screenshot(${javascript.formatObject(options)});`);
63
- else
64
- response.addCode(`await page.screenshot(${javascript.formatObject(options)});`);
65
- const buffer = locator ? await locator.screenshot(options) : await tab.page.screenshot(options);
66
- response.addResult(`Took the ${screenshotTarget} screenshot and saved it as ${fileName}`);
67
- // https://github.com/microsoft/playwright-mcp/issues/817
68
- // Never return large images to LLM, saving them to the file system is enough.
69
- if (!params.fullPage) {
70
- response.addImage({
71
- contentType: fileType === 'png' ? 'image/png' : 'image/jpeg',
72
- data: buffer
73
- });
74
- }
75
- }
76
- });
77
- export default [
78
- screenshot,
79
- ];
@@ -1,139 +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 { defineTabTool, defineTool } from './tool.js';
18
- import * as javascript from '../utils/codegen.js';
19
- import { generateLocator } from './utils.js';
20
- const snapshot = defineTool({
21
- capability: 'core',
22
- schema: {
23
- name: 'browser_snapshot',
24
- title: 'Page snapshot',
25
- description: 'Capture accessibility snapshot of the current page, this is better than screenshot',
26
- inputSchema: z.object({}),
27
- type: 'readOnly',
28
- },
29
- handle: async (context, params, response) => {
30
- await context.ensureTab();
31
- response.setIncludeSnapshot();
32
- },
33
- });
34
- export const elementSchema = z.object({
35
- element: z.string().describe('Human-readable element description used to obtain permission to interact with the element'),
36
- ref: z.string().describe('Exact target element reference from the page snapshot'),
37
- });
38
- const clickSchema = elementSchema.extend({
39
- doubleClick: z.boolean().optional().describe('Whether to perform a double click instead of a single click'),
40
- button: z.enum(['left', 'right', 'middle']).optional().describe('Button to click, defaults to left'),
41
- });
42
- const click = defineTabTool({
43
- capability: 'core',
44
- schema: {
45
- name: 'browser_click',
46
- title: 'Click',
47
- description: 'Perform click on a web page',
48
- inputSchema: clickSchema,
49
- type: 'destructive',
50
- },
51
- handle: async (tab, params, response) => {
52
- response.setIncludeSnapshot();
53
- const locator = await tab.refLocator(params);
54
- const button = params.button;
55
- const buttonAttr = button ? `{ button: '${button}' }` : '';
56
- if (params.doubleClick)
57
- response.addCode(`await page.${await generateLocator(locator)}.dblclick(${buttonAttr});`);
58
- else
59
- response.addCode(`await page.${await generateLocator(locator)}.click(${buttonAttr});`);
60
- await tab.waitForCompletion(async () => {
61
- if (params.doubleClick)
62
- await locator.dblclick({ button });
63
- else
64
- await locator.click({ button });
65
- });
66
- },
67
- });
68
- const drag = defineTabTool({
69
- capability: 'core',
70
- schema: {
71
- name: 'browser_drag',
72
- title: 'Drag mouse',
73
- description: 'Perform drag and drop between two elements',
74
- inputSchema: z.object({
75
- startElement: z.string().describe('Human-readable source element description used to obtain the permission to interact with the element'),
76
- startRef: z.string().describe('Exact source element reference from the page snapshot'),
77
- endElement: z.string().describe('Human-readable target element description used to obtain the permission to interact with the element'),
78
- endRef: z.string().describe('Exact target element reference from the page snapshot'),
79
- }),
80
- type: 'destructive',
81
- },
82
- handle: async (tab, params, response) => {
83
- response.setIncludeSnapshot();
84
- const [startLocator, endLocator] = await tab.refLocators([
85
- { ref: params.startRef, element: params.startElement },
86
- { ref: params.endRef, element: params.endElement },
87
- ]);
88
- await tab.waitForCompletion(async () => {
89
- await startLocator.dragTo(endLocator);
90
- });
91
- response.addCode(`await page.${await generateLocator(startLocator)}.dragTo(page.${await generateLocator(endLocator)});`);
92
- },
93
- });
94
- const hover = defineTabTool({
95
- capability: 'core',
96
- schema: {
97
- name: 'browser_hover',
98
- title: 'Hover mouse',
99
- description: 'Hover over element on page',
100
- inputSchema: elementSchema,
101
- type: 'readOnly',
102
- },
103
- handle: async (tab, params, response) => {
104
- response.setIncludeSnapshot();
105
- const locator = await tab.refLocator(params);
106
- response.addCode(`await page.${await generateLocator(locator)}.hover();`);
107
- await tab.waitForCompletion(async () => {
108
- await locator.hover();
109
- });
110
- },
111
- });
112
- const selectOptionSchema = elementSchema.extend({
113
- values: z.array(z.string()).describe('Array of values to select in the dropdown. This can be a single value or multiple values.'),
114
- });
115
- const selectOption = defineTabTool({
116
- capability: 'core',
117
- schema: {
118
- name: 'browser_select_option',
119
- title: 'Select option',
120
- description: 'Select an option in a dropdown',
121
- inputSchema: selectOptionSchema,
122
- type: 'destructive',
123
- },
124
- handle: async (tab, params, response) => {
125
- response.setIncludeSnapshot();
126
- const locator = await tab.refLocator(params);
127
- response.addCode(`await page.${await generateLocator(locator)}.selectOption(${javascript.formatObject(params.values)});`);
128
- await tab.waitForCompletion(async () => {
129
- await locator.selectOption(params.values);
130
- });
131
- },
132
- });
133
- export default [
134
- snapshot,
135
- click,
136
- drag,
137
- hover,
138
- selectOption,
139
- ];
package/lib/tools.js DELETED
@@ -1,54 +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 common from './tools/common.js';
17
- import console from './tools/console.js';
18
- import dialogs from './tools/dialogs.js';
19
- import evaluate from './tools/evaluate.js';
20
- import files from './tools/files.js';
21
- import form from './tools/form.js';
22
- import install from './tools/install.js';
23
- import keyboard from './tools/keyboard.js';
24
- import mouse from './tools/mouse.js';
25
- import navigate from './tools/navigate.js';
26
- import network from './tools/network.js';
27
- import pdf from './tools/pdf.js';
28
- import snapshot from './tools/snapshot.js';
29
- import tabs from './tools/tabs.js';
30
- import screenshot from './tools/screenshot.js';
31
- import wait from './tools/wait.js';
32
- import verify from './tools/verify.js';
33
- export const allTools = [
34
- ...common,
35
- ...console,
36
- ...dialogs,
37
- ...evaluate,
38
- ...files,
39
- ...form,
40
- ...install,
41
- ...keyboard,
42
- ...navigate,
43
- ...network,
44
- ...mouse,
45
- ...pdf,
46
- ...screenshot,
47
- ...snapshot,
48
- ...tabs,
49
- ...wait,
50
- ...verify,
51
- ];
52
- export function filteredTools(config) {
53
- return allTools.filter(tool => tool.capability.startsWith('core') || config.capabilities?.includes(tool.capability));
54
- }
@@ -1,36 +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 os from 'node:os';
17
- import path from 'node:path';
18
- export function cacheDir() {
19
- let cacheDirectory;
20
- if (process.platform === 'linux')
21
- cacheDirectory = process.env.XDG_CACHE_HOME || path.join(os.homedir(), '.cache');
22
- else if (process.platform === 'darwin')
23
- cacheDirectory = path.join(os.homedir(), 'Library', 'Caches');
24
- else if (process.platform === 'win32')
25
- cacheDirectory = process.env.LOCALAPPDATA || path.join(os.homedir(), 'AppData', 'Local');
26
- else
27
- throw new Error('Unsupported platform: ' + process.platform);
28
- return path.join(cacheDirectory, 'ms-playwright');
29
- }
30
- export function sanitizeForFilePath(s) {
31
- const sanitize = (s) => s.replace(/[\x00-\x2C\x2E-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+/g, '-');
32
- const separator = s.lastIndexOf('.');
33
- if (separator === -1)
34
- return sanitize(s);
35
- return sanitize(s.substring(0, separator)) + '.' + sanitize(s.substring(separator + 1));
36
- }
package/lib/utils/guid.js DELETED
@@ -1,22 +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 crypto from 'crypto';
17
- export function createGuid() {
18
- return crypto.randomBytes(16).toString('hex');
19
- }
20
- export function createHash(data) {
21
- return crypto.createHash('sha256').update(data).digest('hex').slice(0, 7);
22
- }