@playwright/mcp 0.0.36-alpha-2025-09-04 → 0.0.37-alpha-2025-09-08
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 +81 -46
- package/cli.js +7 -1
- package/config.d.ts +24 -0
- package/index.js +1 -1
- package/package.json +14 -39
- package/lib/browser/browserContextFactory.js +0 -251
- package/lib/browser/browserServerBackend.js +0 -79
- package/lib/browser/codegen.js +0 -54
- package/lib/browser/config.js +0 -263
- package/lib/browser/context.js +0 -223
- package/lib/browser/response.js +0 -165
- package/lib/browser/sessionLog.js +0 -126
- package/lib/browser/tab.js +0 -251
- package/lib/browser/tools/common.js +0 -57
- package/lib/browser/tools/console.js +0 -35
- package/lib/browser/tools/dialogs.js +0 -49
- package/lib/browser/tools/evaluate.js +0 -88
- package/lib/browser/tools/files.js +0 -46
- package/lib/browser/tools/form.js +0 -92
- package/lib/browser/tools/install.js +0 -57
- package/lib/browser/tools/keyboard.js +0 -113
- package/lib/browser/tools/mouse.js +0 -101
- package/lib/browser/tools/navigate.js +0 -56
- package/lib/browser/tools/network.js +0 -43
- package/lib/browser/tools/pdf.js +0 -76
- package/lib/browser/tools/screenshot.js +0 -115
- package/lib/browser/tools/snapshot.js +0 -175
- package/lib/browser/tools/tabs.js +0 -61
- package/lib/browser/tools/tool.js +0 -37
- package/lib/browser/tools/utils.js +0 -79
- package/lib/browser/tools/verify.js +0 -172
- package/lib/browser/tools/wait.js +0 -57
- package/lib/browser/tools.js +0 -61
- package/lib/extension/cdpRelay.js +0 -395
- package/lib/extension/extensionContextFactory.js +0 -93
- package/lib/extension/protocol.js +0 -21
- package/lib/index.js +0 -75
- package/lib/log.js +0 -28
- package/lib/package.js +0 -24
- package/lib/program.js +0 -161
- package/lib/sdk/bundle.js +0 -79
- package/lib/sdk/http.js +0 -175
- package/lib/sdk/inProcessTransport.js +0 -67
- package/lib/sdk/manualPromise.js +0 -113
- package/lib/sdk/mdb.js +0 -237
- package/lib/sdk/proxyBackend.js +0 -141
- package/lib/sdk/server.js +0 -164
- package/lib/sdk/tool.js +0 -36
- package/lib/vscode/host.js +0 -199
- package/lib/vscode/main.js +0 -97
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) Microsoft Corporation.
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
* you may not use this file except in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
* See the License for the specific language governing permissions and
|
|
15
|
-
* limitations under the License.
|
|
16
|
-
*/
|
|
17
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
-
if (k2 === undefined) k2 = k;
|
|
19
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
20
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
21
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
22
|
-
}
|
|
23
|
-
Object.defineProperty(o, k2, desc);
|
|
24
|
-
}) : (function(o, m, k, k2) {
|
|
25
|
-
if (k2 === undefined) k2 = k;
|
|
26
|
-
o[k2] = m[k];
|
|
27
|
-
}));
|
|
28
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
29
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
-
}) : function(o, v) {
|
|
31
|
-
o["default"] = v;
|
|
32
|
-
});
|
|
33
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
34
|
-
var ownKeys = function(o) {
|
|
35
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
36
|
-
var ar = [];
|
|
37
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
38
|
-
return ar;
|
|
39
|
-
};
|
|
40
|
-
return ownKeys(o);
|
|
41
|
-
};
|
|
42
|
-
return function (mod) {
|
|
43
|
-
if (mod && mod.__esModule) return mod;
|
|
44
|
-
var result = {};
|
|
45
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
46
|
-
__setModuleDefault(result, mod);
|
|
47
|
-
return result;
|
|
48
|
-
};
|
|
49
|
-
})();
|
|
50
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
|
-
const bundle_1 = require("../../sdk/bundle");
|
|
52
|
-
const tool_1 = require("./tool");
|
|
53
|
-
const javascript = __importStar(require("../codegen"));
|
|
54
|
-
const utils_1 = require("./utils");
|
|
55
|
-
const screenshotSchema = bundle_1.z.object({
|
|
56
|
-
type: bundle_1.z.enum(['png', 'jpeg']).default('png').describe('Image format for the screenshot. Default is png.'),
|
|
57
|
-
filename: bundle_1.z.string().optional().describe('File name to save the screenshot to. Defaults to `page-{timestamp}.{png|jpeg}` if not specified.'),
|
|
58
|
-
element: bundle_1.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.'),
|
|
59
|
-
ref: bundle_1.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.'),
|
|
60
|
-
fullPage: bundle_1.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.'),
|
|
61
|
-
}).refine(data => {
|
|
62
|
-
return !!data.element === !!data.ref;
|
|
63
|
-
}, {
|
|
64
|
-
message: 'Both element and ref must be provided or neither.',
|
|
65
|
-
path: ['ref', 'element']
|
|
66
|
-
}).refine(data => {
|
|
67
|
-
return !(data.fullPage && (data.element || data.ref));
|
|
68
|
-
}, {
|
|
69
|
-
message: 'fullPage cannot be used with element screenshots.',
|
|
70
|
-
path: ['fullPage']
|
|
71
|
-
});
|
|
72
|
-
const screenshot = (0, tool_1.defineTabTool)({
|
|
73
|
-
capability: 'core',
|
|
74
|
-
schema: {
|
|
75
|
-
name: 'browser_take_screenshot',
|
|
76
|
-
title: 'Take a screenshot',
|
|
77
|
-
description: `Take a screenshot of the current page. You can't perform actions based on the screenshot, use browser_snapshot for actions.`,
|
|
78
|
-
inputSchema: screenshotSchema,
|
|
79
|
-
type: 'readOnly',
|
|
80
|
-
},
|
|
81
|
-
handle: async (tab, params, response) => {
|
|
82
|
-
var _a;
|
|
83
|
-
const fileType = params.type || 'png';
|
|
84
|
-
const fileName = await tab.context.outputFile((_a = params.filename) !== null && _a !== void 0 ? _a : `page-${new Date().toISOString()}.${fileType}`);
|
|
85
|
-
const options = {
|
|
86
|
-
type: fileType,
|
|
87
|
-
quality: fileType === 'png' ? undefined : 90,
|
|
88
|
-
scale: 'css',
|
|
89
|
-
path: fileName,
|
|
90
|
-
...(params.fullPage !== undefined && { fullPage: params.fullPage })
|
|
91
|
-
};
|
|
92
|
-
const isElementScreenshot = params.element && params.ref;
|
|
93
|
-
const screenshotTarget = isElementScreenshot ? params.element : (params.fullPage ? 'full page' : 'viewport');
|
|
94
|
-
response.addCode(`// Screenshot ${screenshotTarget} and save it as ${fileName}`);
|
|
95
|
-
// Only get snapshot when element screenshot is needed
|
|
96
|
-
const locator = params.ref ? await tab.refLocator({ element: params.element || '', ref: params.ref }) : null;
|
|
97
|
-
if (locator)
|
|
98
|
-
response.addCode(`await page.${await (0, utils_1.generateLocator)(locator)}.screenshot(${javascript.formatObject(options)});`);
|
|
99
|
-
else
|
|
100
|
-
response.addCode(`await page.screenshot(${javascript.formatObject(options)});`);
|
|
101
|
-
const buffer = locator ? await locator.screenshot(options) : await tab.page.screenshot(options);
|
|
102
|
-
response.addResult(`Took the ${screenshotTarget} screenshot and saved it as ${fileName}`);
|
|
103
|
-
// https://github.com/microsoft/playwright-mcp/issues/817
|
|
104
|
-
// Never return large images to LLM, saving them to the file system is enough.
|
|
105
|
-
if (!params.fullPage) {
|
|
106
|
-
response.addImage({
|
|
107
|
-
contentType: fileType === 'png' ? 'image/png' : 'image/jpeg',
|
|
108
|
-
data: buffer
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
exports.default = [
|
|
114
|
-
screenshot,
|
|
115
|
-
];
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) Microsoft Corporation.
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
* you may not use this file except in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
* See the License for the specific language governing permissions and
|
|
15
|
-
* limitations under the License.
|
|
16
|
-
*/
|
|
17
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
-
if (k2 === undefined) k2 = k;
|
|
19
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
20
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
21
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
22
|
-
}
|
|
23
|
-
Object.defineProperty(o, k2, desc);
|
|
24
|
-
}) : (function(o, m, k, k2) {
|
|
25
|
-
if (k2 === undefined) k2 = k;
|
|
26
|
-
o[k2] = m[k];
|
|
27
|
-
}));
|
|
28
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
29
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
-
}) : function(o, v) {
|
|
31
|
-
o["default"] = v;
|
|
32
|
-
});
|
|
33
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
34
|
-
var ownKeys = function(o) {
|
|
35
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
36
|
-
var ar = [];
|
|
37
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
38
|
-
return ar;
|
|
39
|
-
};
|
|
40
|
-
return ownKeys(o);
|
|
41
|
-
};
|
|
42
|
-
return function (mod) {
|
|
43
|
-
if (mod && mod.__esModule) return mod;
|
|
44
|
-
var result = {};
|
|
45
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
46
|
-
__setModuleDefault(result, mod);
|
|
47
|
-
return result;
|
|
48
|
-
};
|
|
49
|
-
})();
|
|
50
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
|
-
exports.elementSchema = void 0;
|
|
52
|
-
const bundle_1 = require("../../sdk/bundle");
|
|
53
|
-
const tool_1 = require("./tool");
|
|
54
|
-
const javascript = __importStar(require("../codegen"));
|
|
55
|
-
const utils_1 = require("./utils");
|
|
56
|
-
const snapshot = (0, tool_1.defineTool)({
|
|
57
|
-
capability: 'core',
|
|
58
|
-
schema: {
|
|
59
|
-
name: 'browser_snapshot',
|
|
60
|
-
title: 'Page snapshot',
|
|
61
|
-
description: 'Capture accessibility snapshot of the current page, this is better than screenshot',
|
|
62
|
-
inputSchema: bundle_1.z.object({}),
|
|
63
|
-
type: 'readOnly',
|
|
64
|
-
},
|
|
65
|
-
handle: async (context, params, response) => {
|
|
66
|
-
await context.ensureTab();
|
|
67
|
-
response.setIncludeSnapshot();
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
|
-
exports.elementSchema = bundle_1.z.object({
|
|
71
|
-
element: bundle_1.z.string().describe('Human-readable element description used to obtain permission to interact with the element'),
|
|
72
|
-
ref: bundle_1.z.string().describe('Exact target element reference from the page snapshot'),
|
|
73
|
-
});
|
|
74
|
-
const clickSchema = exports.elementSchema.extend({
|
|
75
|
-
doubleClick: bundle_1.z.boolean().optional().describe('Whether to perform a double click instead of a single click'),
|
|
76
|
-
button: bundle_1.z.enum(['left', 'right', 'middle']).optional().describe('Button to click, defaults to left'),
|
|
77
|
-
});
|
|
78
|
-
const click = (0, tool_1.defineTabTool)({
|
|
79
|
-
capability: 'core',
|
|
80
|
-
schema: {
|
|
81
|
-
name: 'browser_click',
|
|
82
|
-
title: 'Click',
|
|
83
|
-
description: 'Perform click on a web page',
|
|
84
|
-
inputSchema: clickSchema,
|
|
85
|
-
type: 'destructive',
|
|
86
|
-
},
|
|
87
|
-
handle: async (tab, params, response) => {
|
|
88
|
-
response.setIncludeSnapshot();
|
|
89
|
-
const locator = await tab.refLocator(params);
|
|
90
|
-
const button = params.button;
|
|
91
|
-
const buttonAttr = button ? `{ button: '${button}' }` : '';
|
|
92
|
-
if (params.doubleClick)
|
|
93
|
-
response.addCode(`await page.${await (0, utils_1.generateLocator)(locator)}.dblclick(${buttonAttr});`);
|
|
94
|
-
else
|
|
95
|
-
response.addCode(`await page.${await (0, utils_1.generateLocator)(locator)}.click(${buttonAttr});`);
|
|
96
|
-
await tab.waitForCompletion(async () => {
|
|
97
|
-
if (params.doubleClick)
|
|
98
|
-
await locator.dblclick({ button });
|
|
99
|
-
else
|
|
100
|
-
await locator.click({ button });
|
|
101
|
-
});
|
|
102
|
-
},
|
|
103
|
-
});
|
|
104
|
-
const drag = (0, tool_1.defineTabTool)({
|
|
105
|
-
capability: 'core',
|
|
106
|
-
schema: {
|
|
107
|
-
name: 'browser_drag',
|
|
108
|
-
title: 'Drag mouse',
|
|
109
|
-
description: 'Perform drag and drop between two elements',
|
|
110
|
-
inputSchema: bundle_1.z.object({
|
|
111
|
-
startElement: bundle_1.z.string().describe('Human-readable source element description used to obtain the permission to interact with the element'),
|
|
112
|
-
startRef: bundle_1.z.string().describe('Exact source element reference from the page snapshot'),
|
|
113
|
-
endElement: bundle_1.z.string().describe('Human-readable target element description used to obtain the permission to interact with the element'),
|
|
114
|
-
endRef: bundle_1.z.string().describe('Exact target element reference from the page snapshot'),
|
|
115
|
-
}),
|
|
116
|
-
type: 'destructive',
|
|
117
|
-
},
|
|
118
|
-
handle: async (tab, params, response) => {
|
|
119
|
-
response.setIncludeSnapshot();
|
|
120
|
-
const [startLocator, endLocator] = await tab.refLocators([
|
|
121
|
-
{ ref: params.startRef, element: params.startElement },
|
|
122
|
-
{ ref: params.endRef, element: params.endElement },
|
|
123
|
-
]);
|
|
124
|
-
await tab.waitForCompletion(async () => {
|
|
125
|
-
await startLocator.dragTo(endLocator);
|
|
126
|
-
});
|
|
127
|
-
response.addCode(`await page.${await (0, utils_1.generateLocator)(startLocator)}.dragTo(page.${await (0, utils_1.generateLocator)(endLocator)});`);
|
|
128
|
-
},
|
|
129
|
-
});
|
|
130
|
-
const hover = (0, tool_1.defineTabTool)({
|
|
131
|
-
capability: 'core',
|
|
132
|
-
schema: {
|
|
133
|
-
name: 'browser_hover',
|
|
134
|
-
title: 'Hover mouse',
|
|
135
|
-
description: 'Hover over element on page',
|
|
136
|
-
inputSchema: exports.elementSchema,
|
|
137
|
-
type: 'readOnly',
|
|
138
|
-
},
|
|
139
|
-
handle: async (tab, params, response) => {
|
|
140
|
-
response.setIncludeSnapshot();
|
|
141
|
-
const locator = await tab.refLocator(params);
|
|
142
|
-
response.addCode(`await page.${await (0, utils_1.generateLocator)(locator)}.hover();`);
|
|
143
|
-
await tab.waitForCompletion(async () => {
|
|
144
|
-
await locator.hover();
|
|
145
|
-
});
|
|
146
|
-
},
|
|
147
|
-
});
|
|
148
|
-
const selectOptionSchema = exports.elementSchema.extend({
|
|
149
|
-
values: bundle_1.z.array(bundle_1.z.string()).describe('Array of values to select in the dropdown. This can be a single value or multiple values.'),
|
|
150
|
-
});
|
|
151
|
-
const selectOption = (0, tool_1.defineTabTool)({
|
|
152
|
-
capability: 'core',
|
|
153
|
-
schema: {
|
|
154
|
-
name: 'browser_select_option',
|
|
155
|
-
title: 'Select option',
|
|
156
|
-
description: 'Select an option in a dropdown',
|
|
157
|
-
inputSchema: selectOptionSchema,
|
|
158
|
-
type: 'destructive',
|
|
159
|
-
},
|
|
160
|
-
handle: async (tab, params, response) => {
|
|
161
|
-
response.setIncludeSnapshot();
|
|
162
|
-
const locator = await tab.refLocator(params);
|
|
163
|
-
response.addCode(`await page.${await (0, utils_1.generateLocator)(locator)}.selectOption(${javascript.formatObject(params.values)});`);
|
|
164
|
-
await tab.waitForCompletion(async () => {
|
|
165
|
-
await locator.selectOption(params.values);
|
|
166
|
-
});
|
|
167
|
-
},
|
|
168
|
-
});
|
|
169
|
-
exports.default = [
|
|
170
|
-
snapshot,
|
|
171
|
-
click,
|
|
172
|
-
drag,
|
|
173
|
-
hover,
|
|
174
|
-
selectOption,
|
|
175
|
-
];
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) Microsoft Corporation.
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
* you may not use this file except in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
* See the License for the specific language governing permissions and
|
|
15
|
-
* limitations under the License.
|
|
16
|
-
*/
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
const bundle_1 = require("../../sdk/bundle");
|
|
19
|
-
const tool_1 = require("./tool");
|
|
20
|
-
const browserTabs = (0, tool_1.defineTool)({
|
|
21
|
-
capability: 'core-tabs',
|
|
22
|
-
schema: {
|
|
23
|
-
name: 'browser_tabs',
|
|
24
|
-
title: 'Manage tabs',
|
|
25
|
-
description: 'List, create, close, or select a browser tab.',
|
|
26
|
-
inputSchema: bundle_1.z.object({
|
|
27
|
-
action: bundle_1.z.enum(['list', 'new', 'close', 'select']).describe('Operation to perform'),
|
|
28
|
-
index: bundle_1.z.number().optional().describe('Tab index, used for close/select. If omitted for close, current tab is closed.'),
|
|
29
|
-
}),
|
|
30
|
-
type: 'destructive',
|
|
31
|
-
},
|
|
32
|
-
handle: async (context, params, response) => {
|
|
33
|
-
switch (params.action) {
|
|
34
|
-
case 'list': {
|
|
35
|
-
await context.ensureTab();
|
|
36
|
-
response.setIncludeTabs();
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
case 'new': {
|
|
40
|
-
await context.newTab();
|
|
41
|
-
response.setIncludeTabs();
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
case 'close': {
|
|
45
|
-
await context.closeTab(params.index);
|
|
46
|
-
response.setIncludeSnapshot();
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
case 'select': {
|
|
50
|
-
if (params.index === undefined)
|
|
51
|
-
throw new Error('Tab index is required');
|
|
52
|
-
await context.selectTab(params.index);
|
|
53
|
-
response.setIncludeSnapshot();
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
exports.default = [
|
|
60
|
-
browserTabs,
|
|
61
|
-
];
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) Microsoft Corporation.
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
* you may not use this file except in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
* See the License for the specific language governing permissions and
|
|
15
|
-
* limitations under the License.
|
|
16
|
-
*/
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.defineTool = defineTool;
|
|
19
|
-
exports.defineTabTool = defineTabTool;
|
|
20
|
-
function defineTool(tool) {
|
|
21
|
-
return tool;
|
|
22
|
-
}
|
|
23
|
-
function defineTabTool(tool) {
|
|
24
|
-
return {
|
|
25
|
-
...tool,
|
|
26
|
-
handle: async (context, params, response) => {
|
|
27
|
-
const tab = context.currentTabOrDie();
|
|
28
|
-
const modalStates = tab.modalStates().map(state => state.type);
|
|
29
|
-
if (tool.clearsModalState && !modalStates.includes(tool.clearsModalState))
|
|
30
|
-
response.addError(`Error: The tool "${tool.schema.name}" can only be used when there is related modal state present.\n` + tab.modalStatesMarkdown().join('\n'));
|
|
31
|
-
else if (!tool.clearsModalState && modalStates.length)
|
|
32
|
-
response.addError(`Error: Tool "${tool.schema.name}" does not handle the modal state.\n` + tab.modalStatesMarkdown().join('\n'));
|
|
33
|
-
else
|
|
34
|
-
return tool.handle(tab, params, response);
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) Microsoft Corporation.
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
* you may not use this file except in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
* See the License for the specific language governing permissions and
|
|
15
|
-
* limitations under the License.
|
|
16
|
-
*/
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.waitForCompletion = waitForCompletion;
|
|
19
|
-
exports.generateLocator = generateLocator;
|
|
20
|
-
exports.callOnPageNoTrace = callOnPageNoTrace;
|
|
21
|
-
// @ts-ignore
|
|
22
|
-
const utils_1 = require("playwright-core/lib/utils");
|
|
23
|
-
async function waitForCompletion(tab, callback) {
|
|
24
|
-
const requests = new Set();
|
|
25
|
-
let frameNavigated = false;
|
|
26
|
-
let waitCallback = () => { };
|
|
27
|
-
const waitBarrier = new Promise(f => { waitCallback = f; });
|
|
28
|
-
const requestListener = (request) => requests.add(request);
|
|
29
|
-
const requestFinishedListener = (request) => {
|
|
30
|
-
requests.delete(request);
|
|
31
|
-
if (!requests.size)
|
|
32
|
-
waitCallback();
|
|
33
|
-
};
|
|
34
|
-
const frameNavigateListener = (frame) => {
|
|
35
|
-
if (frame.parentFrame())
|
|
36
|
-
return;
|
|
37
|
-
frameNavigated = true;
|
|
38
|
-
dispose();
|
|
39
|
-
clearTimeout(timeout);
|
|
40
|
-
void tab.waitForLoadState('load').then(waitCallback);
|
|
41
|
-
};
|
|
42
|
-
const onTimeout = () => {
|
|
43
|
-
dispose();
|
|
44
|
-
waitCallback();
|
|
45
|
-
};
|
|
46
|
-
tab.page.on('request', requestListener);
|
|
47
|
-
tab.page.on('requestfinished', requestFinishedListener);
|
|
48
|
-
tab.page.on('framenavigated', frameNavigateListener);
|
|
49
|
-
const timeout = setTimeout(onTimeout, 10000);
|
|
50
|
-
const dispose = () => {
|
|
51
|
-
tab.page.off('request', requestListener);
|
|
52
|
-
tab.page.off('requestfinished', requestFinishedListener);
|
|
53
|
-
tab.page.off('framenavigated', frameNavigateListener);
|
|
54
|
-
clearTimeout(timeout);
|
|
55
|
-
};
|
|
56
|
-
try {
|
|
57
|
-
const result = await callback();
|
|
58
|
-
if (!requests.size && !frameNavigated)
|
|
59
|
-
waitCallback();
|
|
60
|
-
await waitBarrier;
|
|
61
|
-
await tab.waitForTimeout(1000);
|
|
62
|
-
return result;
|
|
63
|
-
}
|
|
64
|
-
finally {
|
|
65
|
-
dispose();
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
async function generateLocator(locator) {
|
|
69
|
-
try {
|
|
70
|
-
const { resolvedSelector } = await locator._resolveSelector();
|
|
71
|
-
return (0, utils_1.asLocator)('javascript', resolvedSelector);
|
|
72
|
-
}
|
|
73
|
-
catch (e) {
|
|
74
|
-
throw new Error('Ref not found, likely because element was removed. Use browser_snapshot to see what elements are currently on the page.');
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
async function callOnPageNoTrace(page, callback) {
|
|
78
|
-
return await page._wrapApiCall(() => callback(page), { internal: true });
|
|
79
|
-
}
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) Microsoft Corporation.
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
* you may not use this file except in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
* See the License for the specific language governing permissions and
|
|
15
|
-
* limitations under the License.
|
|
16
|
-
*/
|
|
17
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
-
if (k2 === undefined) k2 = k;
|
|
19
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
20
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
21
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
22
|
-
}
|
|
23
|
-
Object.defineProperty(o, k2, desc);
|
|
24
|
-
}) : (function(o, m, k, k2) {
|
|
25
|
-
if (k2 === undefined) k2 = k;
|
|
26
|
-
o[k2] = m[k];
|
|
27
|
-
}));
|
|
28
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
29
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
-
}) : function(o, v) {
|
|
31
|
-
o["default"] = v;
|
|
32
|
-
});
|
|
33
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
34
|
-
var ownKeys = function(o) {
|
|
35
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
36
|
-
var ar = [];
|
|
37
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
38
|
-
return ar;
|
|
39
|
-
};
|
|
40
|
-
return ownKeys(o);
|
|
41
|
-
};
|
|
42
|
-
return function (mod) {
|
|
43
|
-
if (mod && mod.__esModule) return mod;
|
|
44
|
-
var result = {};
|
|
45
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
46
|
-
__setModuleDefault(result, mod);
|
|
47
|
-
return result;
|
|
48
|
-
};
|
|
49
|
-
})();
|
|
50
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
|
-
const bundle_1 = require("../../sdk/bundle");
|
|
52
|
-
const tool_1 = require("./tool");
|
|
53
|
-
const javascript = __importStar(require("../codegen"));
|
|
54
|
-
const utils_1 = require("./utils");
|
|
55
|
-
const verifyElement = (0, tool_1.defineTabTool)({
|
|
56
|
-
capability: 'verify',
|
|
57
|
-
schema: {
|
|
58
|
-
name: 'browser_verify_element_visible',
|
|
59
|
-
title: 'Verify element visible',
|
|
60
|
-
description: 'Verify element is visible on the page',
|
|
61
|
-
inputSchema: bundle_1.z.object({
|
|
62
|
-
role: bundle_1.z.string().describe('ROLE of the element. Can be found in the snapshot like this: \`- {ROLE} "Accessible Name":\`'),
|
|
63
|
-
accessibleName: bundle_1.z.string().describe('ACCESSIBLE_NAME of the element. Can be found in the snapshot like this: \`- role "{ACCESSIBLE_NAME}"\`'),
|
|
64
|
-
}),
|
|
65
|
-
type: 'readOnly',
|
|
66
|
-
},
|
|
67
|
-
handle: async (tab, params, response) => {
|
|
68
|
-
const locator = tab.page.getByRole(params.role, { name: params.accessibleName });
|
|
69
|
-
if (await locator.count() === 0) {
|
|
70
|
-
response.addError(`Element with role "${params.role}" and accessible name "${params.accessibleName}" not found`);
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
response.addCode(`await expect(page.getByRole(${javascript.escapeWithQuotes(params.role)}, { name: ${javascript.escapeWithQuotes(params.accessibleName)} })).toBeVisible();`);
|
|
74
|
-
response.addResult('Done');
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
const verifyText = (0, tool_1.defineTabTool)({
|
|
78
|
-
capability: 'verify',
|
|
79
|
-
schema: {
|
|
80
|
-
name: 'browser_verify_text_visible',
|
|
81
|
-
title: 'Verify text visible',
|
|
82
|
-
description: `Verify text is visible on the page. Prefer ${verifyElement.schema.name} if possible.`,
|
|
83
|
-
inputSchema: bundle_1.z.object({
|
|
84
|
-
text: bundle_1.z.string().describe('TEXT to verify. Can be found in the snapshot like this: \`- role "Accessible Name": {TEXT}\` or like this: \`- text: {TEXT}\`'),
|
|
85
|
-
}),
|
|
86
|
-
type: 'readOnly',
|
|
87
|
-
},
|
|
88
|
-
handle: async (tab, params, response) => {
|
|
89
|
-
const locator = tab.page.getByText(params.text).filter({ visible: true });
|
|
90
|
-
if (await locator.count() === 0) {
|
|
91
|
-
response.addError('Text not found');
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
response.addCode(`await expect(page.getByText(${javascript.escapeWithQuotes(params.text)})).toBeVisible();`);
|
|
95
|
-
response.addResult('Done');
|
|
96
|
-
},
|
|
97
|
-
});
|
|
98
|
-
const verifyList = (0, tool_1.defineTabTool)({
|
|
99
|
-
capability: 'verify',
|
|
100
|
-
schema: {
|
|
101
|
-
name: 'browser_verify_list_visible',
|
|
102
|
-
title: 'Verify list visible',
|
|
103
|
-
description: 'Verify list is visible on the page',
|
|
104
|
-
inputSchema: bundle_1.z.object({
|
|
105
|
-
element: bundle_1.z.string().describe('Human-readable list description'),
|
|
106
|
-
ref: bundle_1.z.string().describe('Exact target element reference that points to the list'),
|
|
107
|
-
items: bundle_1.z.array(bundle_1.z.string()).describe('Items to verify'),
|
|
108
|
-
}),
|
|
109
|
-
type: 'readOnly',
|
|
110
|
-
},
|
|
111
|
-
handle: async (tab, params, response) => {
|
|
112
|
-
const locator = await tab.refLocator({ ref: params.ref, element: params.element });
|
|
113
|
-
const itemTexts = [];
|
|
114
|
-
for (const item of params.items) {
|
|
115
|
-
const itemLocator = locator.getByText(item);
|
|
116
|
-
if (await itemLocator.count() === 0) {
|
|
117
|
-
response.addError(`Item "${item}" not found`);
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
itemTexts.push((await itemLocator.textContent()));
|
|
121
|
-
}
|
|
122
|
-
const ariaSnapshot = `\`
|
|
123
|
-
- list:
|
|
124
|
-
${itemTexts.map(t => ` - listitem: ${javascript.escapeWithQuotes(t, '"')}`).join('\n')}
|
|
125
|
-
\``;
|
|
126
|
-
response.addCode(`await expect(page.locator('body')).toMatchAriaSnapshot(${ariaSnapshot});`);
|
|
127
|
-
response.addResult('Done');
|
|
128
|
-
},
|
|
129
|
-
});
|
|
130
|
-
const verifyValue = (0, tool_1.defineTabTool)({
|
|
131
|
-
capability: 'verify',
|
|
132
|
-
schema: {
|
|
133
|
-
name: 'browser_verify_value',
|
|
134
|
-
title: 'Verify value',
|
|
135
|
-
description: 'Verify element value',
|
|
136
|
-
inputSchema: bundle_1.z.object({
|
|
137
|
-
type: bundle_1.z.enum(['textbox', 'checkbox', 'radio', 'combobox', 'slider']).describe('Type of the element'),
|
|
138
|
-
element: bundle_1.z.string().describe('Human-readable element description'),
|
|
139
|
-
ref: bundle_1.z.string().describe('Exact target element reference that points to the element'),
|
|
140
|
-
value: bundle_1.z.string().describe('Value to verify. For checkbox, use "true" or "false".'),
|
|
141
|
-
}),
|
|
142
|
-
type: 'readOnly',
|
|
143
|
-
},
|
|
144
|
-
handle: async (tab, params, response) => {
|
|
145
|
-
const locator = await tab.refLocator({ ref: params.ref, element: params.element });
|
|
146
|
-
const locatorSource = `page.${await (0, utils_1.generateLocator)(locator)}`;
|
|
147
|
-
if (params.type === 'textbox' || params.type === 'slider' || params.type === 'combobox') {
|
|
148
|
-
const value = await locator.inputValue();
|
|
149
|
-
if (value !== params.value) {
|
|
150
|
-
response.addError(`Expected value "${params.value}", but got "${value}"`);
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
response.addCode(`await expect(${locatorSource}).toHaveValue(${javascript.quote(params.value)});`);
|
|
154
|
-
}
|
|
155
|
-
else if (params.type === 'checkbox' || params.type === 'radio') {
|
|
156
|
-
const value = await locator.isChecked();
|
|
157
|
-
if (value !== (params.value === 'true')) {
|
|
158
|
-
response.addError(`Expected value "${params.value}", but got "${value}"`);
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
const matcher = value ? 'toBeChecked' : 'not.toBeChecked';
|
|
162
|
-
response.addCode(`await expect(${locatorSource}).${matcher}();`);
|
|
163
|
-
}
|
|
164
|
-
response.addResult('Done');
|
|
165
|
-
},
|
|
166
|
-
});
|
|
167
|
-
exports.default = [
|
|
168
|
-
verifyElement,
|
|
169
|
-
verifyText,
|
|
170
|
-
verifyList,
|
|
171
|
-
verifyValue,
|
|
172
|
-
];
|