@szymonrybczak/playwright-mcp 0.0.2 → 0.0.4

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 (115) hide show
  1. package/index.d.ts +21 -8
  2. package/lib/cjs/_virtual/_commonjsHelpers.js +9 -0
  3. package/lib/cjs/_virtual/browser.js +11 -0
  4. package/lib/cjs/_virtual/browser2.js +7 -0
  5. package/lib/cjs/cloudflare/package.json.js +10 -0
  6. package/lib/cjs/index.js +28 -0
  7. package/lib/cjs/node_modules/debug/src/browser.js +290 -0
  8. package/lib/cjs/node_modules/debug/src/common.js +307 -0
  9. package/lib/cjs/node_modules/ms/index.js +176 -0
  10. package/lib/cjs/package.js +9 -0
  11. package/lib/cjs/src/browserContextFactory.js +240 -0
  12. package/lib/cjs/src/config.js +77 -0
  13. package/lib/cjs/src/connection.js +74 -0
  14. package/lib/cjs/src/context.js +281 -0
  15. package/lib/cjs/src/fileUtils.js +25 -0
  16. package/lib/cjs/src/index.js +15 -0
  17. package/lib/cjs/src/javascript.js +41 -0
  18. package/lib/cjs/src/manualPromise.js +39 -0
  19. package/lib/cjs/src/pageSnapshot.js +35 -0
  20. package/lib/cjs/src/tab.js +91 -0
  21. package/lib/cjs/src/tools/common.js +60 -0
  22. package/lib/cjs/src/tools/console.js +36 -0
  23. package/lib/cjs/src/tools/dialogs.js +44 -0
  24. package/lib/cjs/src/tools/files.js +43 -0
  25. package/lib/cjs/src/tools/install.js +49 -0
  26. package/lib/cjs/src/tools/keyboard.js +38 -0
  27. package/lib/cjs/src/tools/navigate.js +85 -0
  28. package/lib/cjs/src/tools/network.js +43 -0
  29. package/lib/cjs/src/tools/pdf.js +42 -0
  30. package/lib/cjs/src/tools/screenshot.js +69 -0
  31. package/lib/cjs/src/tools/snapshot.js +195 -0
  32. package/lib/cjs/src/tools/tabs.js +110 -0
  33. package/lib/cjs/src/tools/testing.js +52 -0
  34. package/lib/cjs/src/tools/tool.js +9 -0
  35. package/lib/cjs/src/tools/utils.js +75 -0
  36. package/lib/cjs/src/tools/vision.js +181 -0
  37. package/lib/cjs/src/tools/wait.js +51 -0
  38. package/lib/cjs/src/tools.js +54 -0
  39. package/lib/esm/_virtual/_commonjsHelpers.js +5 -0
  40. package/lib/esm/_virtual/browser.js +7 -0
  41. package/lib/esm/_virtual/browser2.js +3 -0
  42. package/lib/esm/cloudflare/package.json.js +5 -0
  43. package/lib/esm/index.js +24 -0
  44. package/lib/esm/node_modules/debug/src/browser.js +286 -0
  45. package/lib/esm/node_modules/debug/src/common.js +303 -0
  46. package/lib/esm/node_modules/ms/index.js +172 -0
  47. package/lib/esm/package.js +5 -0
  48. package/lib/esm/src/browserContextFactory.js +216 -0
  49. package/lib/esm/src/config.js +72 -0
  50. package/lib/esm/src/connection.js +69 -0
  51. package/lib/esm/src/context.js +277 -0
  52. package/lib/esm/src/fileUtils.js +20 -0
  53. package/lib/esm/src/index.js +11 -0
  54. package/lib/esm/src/javascript.js +35 -0
  55. package/lib/esm/src/manualPromise.js +35 -0
  56. package/lib/esm/src/pageSnapshot.js +31 -0
  57. package/lib/esm/src/tab.js +87 -0
  58. package/lib/esm/src/tools/common.js +56 -0
  59. package/lib/esm/src/tools/console.js +32 -0
  60. package/lib/esm/src/tools/dialogs.js +40 -0
  61. package/lib/esm/src/tools/files.js +39 -0
  62. package/lib/esm/src/tools/install.js +45 -0
  63. package/lib/esm/src/tools/keyboard.js +34 -0
  64. package/lib/esm/src/tools/navigate.js +81 -0
  65. package/lib/esm/src/tools/network.js +39 -0
  66. package/lib/esm/src/tools/pdf.js +38 -0
  67. package/lib/esm/src/tools/screenshot.js +65 -0
  68. package/lib/esm/src/tools/snapshot.js +191 -0
  69. package/lib/esm/src/tools/tabs.js +106 -0
  70. package/lib/esm/src/tools/testing.js +48 -0
  71. package/lib/esm/src/tools/tool.js +5 -0
  72. package/lib/esm/src/tools/utils.js +68 -0
  73. package/lib/esm/src/tools/vision.js +177 -0
  74. package/lib/esm/src/tools/wait.js +47 -0
  75. package/lib/esm/src/tools.js +49 -0
  76. package/package.json +15 -44
  77. package/LICENSE +0 -202
  78. package/README.md +0 -508
  79. package/cli.js +0 -18
  80. package/config.d.ts +0 -128
  81. package/index.js +0 -19
  82. package/lib/browserContextFactory.js +0 -227
  83. package/lib/browserServer.js +0 -151
  84. package/lib/config.js +0 -189
  85. package/lib/connection.js +0 -82
  86. package/lib/context.js +0 -291
  87. package/lib/fileUtils.js +0 -32
  88. package/lib/httpServer.js +0 -201
  89. package/lib/index.js +0 -36
  90. package/lib/javascript.js +0 -49
  91. package/lib/manualPromise.js +0 -111
  92. package/lib/package.js +0 -20
  93. package/lib/pageSnapshot.js +0 -43
  94. package/lib/program.js +0 -72
  95. package/lib/server.js +0 -48
  96. package/lib/tab.js +0 -101
  97. package/lib/tools/common.js +0 -68
  98. package/lib/tools/console.js +0 -44
  99. package/lib/tools/dialogs.js +0 -52
  100. package/lib/tools/files.js +0 -51
  101. package/lib/tools/install.js +0 -57
  102. package/lib/tools/keyboard.js +0 -46
  103. package/lib/tools/navigate.js +0 -93
  104. package/lib/tools/network.js +0 -51
  105. package/lib/tools/pdf.js +0 -49
  106. package/lib/tools/screenshot.js +0 -77
  107. package/lib/tools/snapshot.js +0 -204
  108. package/lib/tools/tabs.js +0 -118
  109. package/lib/tools/testing.js +0 -60
  110. package/lib/tools/tool.js +0 -18
  111. package/lib/tools/utils.js +0 -80
  112. package/lib/tools/vision.js +0 -189
  113. package/lib/tools/wait.js +0 -59
  114. package/lib/tools.js +0 -61
  115. package/lib/transport.js +0 -133
@@ -1,46 +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 pressKey = captureSnapshot => defineTool({
19
- capability: 'core',
20
- schema: {
21
- name: 'browser_press_key',
22
- title: 'Press a key',
23
- description: 'Press a key on the keyboard',
24
- inputSchema: z.object({
25
- key: z.string().describe('Name of the key to press or a character to generate, such as `ArrowLeft` or `a`'),
26
- }),
27
- type: 'destructive',
28
- },
29
- handle: async (context, params) => {
30
- const tab = context.currentTabOrDie();
31
- const code = [
32
- `// Press ${params.key}`,
33
- `await page.keyboard.press('${params.key}');`,
34
- ];
35
- const action = () => tab.page.keyboard.press(params.key);
36
- return {
37
- code,
38
- action,
39
- captureSnapshot,
40
- waitForNetwork: true
41
- };
42
- },
43
- });
44
- export default (captureSnapshot) => [
45
- pressKey(captureSnapshot),
46
- ];
@@ -1,93 +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 navigate = captureSnapshot => defineTool({
19
- capability: 'core',
20
- schema: {
21
- name: 'browser_navigate',
22
- title: 'Navigate to a URL',
23
- description: 'Navigate to a URL',
24
- inputSchema: z.object({
25
- url: z.string().describe('The URL to navigate to'),
26
- }),
27
- type: 'destructive',
28
- },
29
- handle: async (context, params) => {
30
- const tab = await context.ensureTab();
31
- await tab.navigate(params.url);
32
- const code = [
33
- `// Navigate to ${params.url}`,
34
- `await page.goto('${params.url}');`,
35
- ];
36
- return {
37
- code,
38
- captureSnapshot,
39
- waitForNetwork: false,
40
- };
41
- },
42
- });
43
- const goBack = captureSnapshot => defineTool({
44
- capability: 'history',
45
- schema: {
46
- name: 'browser_navigate_back',
47
- title: 'Go back',
48
- description: 'Go back to the previous page',
49
- inputSchema: z.object({}),
50
- type: 'readOnly',
51
- },
52
- handle: async (context) => {
53
- const tab = await context.ensureTab();
54
- await tab.page.goBack();
55
- const code = [
56
- `// Navigate back`,
57
- `await page.goBack();`,
58
- ];
59
- return {
60
- code,
61
- captureSnapshot,
62
- waitForNetwork: false,
63
- };
64
- },
65
- });
66
- const goForward = captureSnapshot => defineTool({
67
- capability: 'history',
68
- schema: {
69
- name: 'browser_navigate_forward',
70
- title: 'Go forward',
71
- description: 'Go forward to the next page',
72
- inputSchema: z.object({}),
73
- type: 'readOnly',
74
- },
75
- handle: async (context) => {
76
- const tab = context.currentTabOrDie();
77
- await tab.page.goForward();
78
- const code = [
79
- `// Navigate forward`,
80
- `await page.goForward();`,
81
- ];
82
- return {
83
- code,
84
- captureSnapshot,
85
- waitForNetwork: false,
86
- };
87
- },
88
- });
89
- export default (captureSnapshot) => [
90
- navigate(captureSnapshot),
91
- goBack(captureSnapshot),
92
- goForward(captureSnapshot),
93
- ];
@@ -1,51 +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 requests = defineTool({
19
- capability: 'core',
20
- schema: {
21
- name: 'browser_network_requests',
22
- title: 'List network requests',
23
- description: 'Returns all network requests since loading the page',
24
- inputSchema: z.object({}),
25
- type: 'readOnly',
26
- },
27
- handle: async (context) => {
28
- const requests = context.currentTabOrDie().requests();
29
- const log = [...requests.entries()].map(([request, response]) => renderRequest(request, response)).join('\n');
30
- return {
31
- code: [`// <internal code to list network requests>`],
32
- action: async () => {
33
- return {
34
- content: [{ type: 'text', text: log }]
35
- };
36
- },
37
- captureSnapshot: false,
38
- waitForNetwork: false,
39
- };
40
- },
41
- });
42
- function renderRequest(request, response) {
43
- const result = [];
44
- result.push(`[${request.method().toUpperCase()}] ${request.url()}`);
45
- if (response)
46
- result.push(`=> [${response.status()}] ${response.statusText()}`);
47
- return result.join(' ');
48
- }
49
- export default [
50
- requests,
51
- ];
package/lib/tools/pdf.js DELETED
@@ -1,49 +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
- import { outputFile } from '../config.js';
20
- const pdfSchema = z.object({
21
- filename: z.string().optional().describe('File name to save the pdf to. Defaults to `page-{timestamp}.pdf` if not specified.'),
22
- });
23
- const pdf = defineTool({
24
- capability: 'pdf',
25
- schema: {
26
- name: 'browser_pdf_save',
27
- title: 'Save as PDF',
28
- description: 'Save page as PDF',
29
- inputSchema: pdfSchema,
30
- type: 'readOnly',
31
- },
32
- handle: async (context, params) => {
33
- const tab = context.currentTabOrDie();
34
- const fileName = await outputFile(context.config, params.filename ?? `page-${new Date().toISOString()}.pdf`);
35
- const code = [
36
- `// Save page as ${fileName}`,
37
- `await page.pdf(${javascript.formatObject({ path: fileName })});`,
38
- ];
39
- return {
40
- code,
41
- action: async () => tab.page.pdf({ path: fileName }).then(() => { }),
42
- captureSnapshot: false,
43
- waitForNetwork: false,
44
- };
45
- },
46
- });
47
- export default [
48
- pdf,
49
- ];
@@ -1,77 +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
- import { outputFile } from '../config.js';
20
- import { generateLocator } from './utils.js';
21
- const screenshotSchema = z.object({
22
- raw: z.coerce.boolean().optional().describe('Whether to return without compression (in PNG format). Default is false, which returns a JPEG image.'),
23
- filename: z.string().optional().describe('File name to save the screenshot to. Defaults to `page-{timestamp}.{png|jpeg}` if not specified.'),
24
- 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.'),
25
- 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.'),
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
- });
32
- const screenshot = defineTool({
33
- capability: 'core',
34
- schema: {
35
- name: 'browser_take_screenshot',
36
- title: 'Take a screenshot',
37
- description: `Take a screenshot of the current page. You can't perform actions based on the screenshot, use browser_snapshot for actions.`,
38
- inputSchema: screenshotSchema,
39
- type: 'readOnly',
40
- },
41
- handle: async (context, params) => {
42
- const tab = context.currentTabOrDie();
43
- const snapshot = tab.snapshotOrDie();
44
- const fileType = params.raw ? 'png' : 'jpeg';
45
- const fileName = await outputFile(context.config, params.filename ?? `page-${new Date().toISOString()}.${fileType}`);
46
- const options = { type: fileType, quality: fileType === 'png' ? undefined : 50, scale: 'css', path: fileName };
47
- const isElementScreenshot = params.element && params.ref;
48
- const code = [
49
- `// Screenshot ${isElementScreenshot ? params.element : 'viewport'} and save it as ${fileName}`,
50
- ];
51
- const locator = params.ref ? snapshot.refLocator({ element: params.element || '', ref: params.ref }) : null;
52
- if (locator)
53
- code.push(`await page.${await generateLocator(locator)}.screenshot(${javascript.formatObject(options)});`);
54
- else
55
- code.push(`await page.screenshot(${javascript.formatObject(options)});`);
56
- const includeBase64 = context.clientSupportsImages();
57
- const action = async () => {
58
- const screenshot = locator ? await locator.screenshot(options) : await tab.page.screenshot(options);
59
- return {
60
- content: includeBase64 ? [{
61
- type: 'image',
62
- data: screenshot.toString('base64'),
63
- mimeType: fileType === 'png' ? 'image/png' : 'image/jpeg',
64
- }] : []
65
- };
66
- };
67
- return {
68
- code,
69
- action,
70
- captureSnapshot: true,
71
- waitForNetwork: false,
72
- };
73
- }
74
- });
75
- export default [
76
- screenshot,
77
- ];
@@ -1,204 +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
- 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) => {
30
- await context.ensureTab();
31
- return {
32
- code: [`// <internal code to capture accessibility snapshot>`],
33
- captureSnapshot: true,
34
- waitForNetwork: false,
35
- };
36
- },
37
- });
38
- const elementSchema = z.object({
39
- element: z.string().describe('Human-readable element description used to obtain permission to interact with the element'),
40
- ref: z.string().describe('Exact target element reference from the page snapshot'),
41
- });
42
- const clickSchema = elementSchema.extend({
43
- doubleClick: z.coerce.boolean().optional().describe('Whether to perform a double click instead of a single click'),
44
- });
45
- const click = defineTool({
46
- capability: 'core',
47
- schema: {
48
- name: 'browser_click',
49
- title: 'Click',
50
- description: 'Perform click on a web page',
51
- inputSchema: clickSchema,
52
- type: 'destructive',
53
- },
54
- handle: async (context, params) => {
55
- const tab = context.currentTabOrDie();
56
- const locator = tab.snapshotOrDie().refLocator(params);
57
- const code = [];
58
- if (params.doubleClick) {
59
- code.push(`// Double click ${params.element}`);
60
- code.push(`await page.${await generateLocator(locator)}.dblclick();`);
61
- }
62
- else {
63
- code.push(`// Click ${params.element}`);
64
- code.push(`await page.${await generateLocator(locator)}.click();`);
65
- }
66
- return {
67
- code,
68
- action: () => params.doubleClick ? locator.dblclick() : locator.click(),
69
- captureSnapshot: true,
70
- waitForNetwork: true,
71
- };
72
- },
73
- });
74
- const drag = defineTool({
75
- capability: 'core',
76
- schema: {
77
- name: 'browser_drag',
78
- title: 'Drag mouse',
79
- description: 'Perform drag and drop between two elements',
80
- inputSchema: z.object({
81
- startElement: z.string().describe('Human-readable source element description used to obtain the permission to interact with the element'),
82
- startRef: z.string().describe('Exact source element reference from the page snapshot'),
83
- endElement: z.string().describe('Human-readable target element description used to obtain the permission to interact with the element'),
84
- endRef: z.string().describe('Exact target element reference from the page snapshot'),
85
- }),
86
- type: 'destructive',
87
- },
88
- handle: async (context, params) => {
89
- const snapshot = context.currentTabOrDie().snapshotOrDie();
90
- const startLocator = snapshot.refLocator({ ref: params.startRef, element: params.startElement });
91
- const endLocator = snapshot.refLocator({ ref: params.endRef, element: params.endElement });
92
- const code = [
93
- `// Drag ${params.startElement} to ${params.endElement}`,
94
- `await page.${await generateLocator(startLocator)}.dragTo(page.${await generateLocator(endLocator)});`
95
- ];
96
- return {
97
- code,
98
- action: () => startLocator.dragTo(endLocator),
99
- captureSnapshot: true,
100
- waitForNetwork: true,
101
- };
102
- },
103
- });
104
- const hover = defineTool({
105
- capability: 'core',
106
- schema: {
107
- name: 'browser_hover',
108
- title: 'Hover mouse',
109
- description: 'Hover over element on page',
110
- inputSchema: elementSchema,
111
- type: 'readOnly',
112
- },
113
- handle: async (context, params) => {
114
- const snapshot = context.currentTabOrDie().snapshotOrDie();
115
- const locator = snapshot.refLocator(params);
116
- const code = [
117
- `// Hover over ${params.element}`,
118
- `await page.${await generateLocator(locator)}.hover();`
119
- ];
120
- return {
121
- code,
122
- action: () => locator.hover(),
123
- captureSnapshot: true,
124
- waitForNetwork: true,
125
- };
126
- },
127
- });
128
- const typeSchema = elementSchema.extend({
129
- text: z.string().describe('Text to type into the element'),
130
- submit: z.coerce.boolean().optional().describe('Whether to submit entered text (press Enter after)'),
131
- slowly: z.coerce.boolean().optional().describe('Whether to type one character at a time. Useful for triggering key handlers in the page. By default entire text is filled in at once.'),
132
- });
133
- const type = defineTool({
134
- capability: 'core',
135
- schema: {
136
- name: 'browser_type',
137
- title: 'Type text',
138
- description: 'Type text into editable element',
139
- inputSchema: typeSchema,
140
- type: 'destructive',
141
- },
142
- handle: async (context, params) => {
143
- const snapshot = context.currentTabOrDie().snapshotOrDie();
144
- const locator = snapshot.refLocator(params);
145
- const code = [];
146
- const steps = [];
147
- if (params.slowly) {
148
- code.push(`// Press "${params.text}" sequentially into "${params.element}"`);
149
- code.push(`await page.${await generateLocator(locator)}.pressSequentially(${javascript.quote(params.text)});`);
150
- steps.push(() => locator.pressSequentially(params.text));
151
- }
152
- else {
153
- code.push(`// Fill "${params.text}" into "${params.element}"`);
154
- code.push(`await page.${await generateLocator(locator)}.fill(${javascript.quote(params.text)});`);
155
- steps.push(() => locator.fill(params.text));
156
- }
157
- if (params.submit) {
158
- code.push(`// Submit text`);
159
- code.push(`await page.${await generateLocator(locator)}.press('Enter');`);
160
- steps.push(() => locator.press('Enter'));
161
- }
162
- return {
163
- code,
164
- action: () => steps.reduce((acc, step) => acc.then(step), Promise.resolve()),
165
- captureSnapshot: true,
166
- waitForNetwork: true,
167
- };
168
- },
169
- });
170
- const selectOptionSchema = elementSchema.extend({
171
- values: z.array(z.string()).describe('Array of values to select in the dropdown. This can be a single value or multiple values.'),
172
- });
173
- const selectOption = defineTool({
174
- capability: 'core',
175
- schema: {
176
- name: 'browser_select_option',
177
- title: 'Select option',
178
- description: 'Select an option in a dropdown',
179
- inputSchema: selectOptionSchema,
180
- type: 'destructive',
181
- },
182
- handle: async (context, params) => {
183
- const snapshot = context.currentTabOrDie().snapshotOrDie();
184
- const locator = snapshot.refLocator(params);
185
- const code = [
186
- `// Select options [${params.values.join(', ')}] in ${params.element}`,
187
- `await page.${await generateLocator(locator)}.selectOption(${javascript.formatObject(params.values)});`
188
- ];
189
- return {
190
- code,
191
- action: () => locator.selectOption(params.values).then(() => { }),
192
- captureSnapshot: true,
193
- waitForNetwork: true,
194
- };
195
- },
196
- });
197
- export default [
198
- snapshot,
199
- click,
200
- drag,
201
- hover,
202
- type,
203
- selectOption,
204
- ];
package/lib/tools/tabs.js DELETED
@@ -1,118 +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 listTabs = defineTool({
19
- capability: 'tabs',
20
- schema: {
21
- name: 'browser_tab_list',
22
- title: 'List tabs',
23
- description: 'List browser tabs',
24
- inputSchema: z.object({}),
25
- type: 'readOnly',
26
- },
27
- handle: async (context) => {
28
- await context.ensureTab();
29
- return {
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
- },
39
- };
40
- },
41
- });
42
- const selectTab = captureSnapshot => defineTool({
43
- capability: 'tabs',
44
- schema: {
45
- name: 'browser_tab_select',
46
- title: 'Select a tab',
47
- description: 'Select a tab by index',
48
- inputSchema: z.object({
49
- index: z.coerce.number().describe('The index of the tab to select'),
50
- }),
51
- type: 'readOnly',
52
- },
53
- handle: async (context, params) => {
54
- await context.selectTab(params.index);
55
- const code = [
56
- `// <internal code to select tab ${params.index}>`,
57
- ];
58
- return {
59
- code,
60
- captureSnapshot,
61
- waitForNetwork: false
62
- };
63
- },
64
- });
65
- const newTab = captureSnapshot => defineTool({
66
- capability: 'tabs',
67
- schema: {
68
- name: 'browser_tab_new',
69
- title: 'Open a new tab',
70
- description: 'Open a new tab',
71
- inputSchema: z.object({
72
- url: z.string().optional().describe('The URL to navigate to in the new tab. If not provided, the new tab will be blank.'),
73
- }),
74
- type: 'readOnly',
75
- },
76
- handle: async (context, params) => {
77
- await context.newTab();
78
- if (params.url)
79
- await context.currentTabOrDie().navigate(params.url);
80
- const code = [
81
- `// <internal code to open a new tab>`,
82
- ];
83
- return {
84
- code,
85
- captureSnapshot,
86
- waitForNetwork: false
87
- };
88
- },
89
- });
90
- const closeTab = captureSnapshot => defineTool({
91
- capability: 'tabs',
92
- schema: {
93
- name: 'browser_tab_close',
94
- title: 'Close a tab',
95
- description: 'Close a tab',
96
- inputSchema: z.object({
97
- index: z.coerce.number().optional().describe('The index of the tab to close. Closes current tab if not provided.'),
98
- }),
99
- type: 'destructive',
100
- },
101
- handle: async (context, params) => {
102
- await context.closeTab(params.index);
103
- const code = [
104
- `// <internal code to close tab ${params.index}>`,
105
- ];
106
- return {
107
- code,
108
- captureSnapshot,
109
- waitForNetwork: false
110
- };
111
- },
112
- });
113
- export default (captureSnapshot) => [
114
- listTabs,
115
- newTab(captureSnapshot),
116
- selectTab(captureSnapshot),
117
- closeTab(captureSnapshot),
118
- ];