@cotestdev/mcp_playwright 0.0.35 → 0.0.36
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/mcp/browser/browserContextFactory.js +12 -12
- package/lib/mcp/browser/browserServerBackend.js +24 -12
- package/lib/mcp/browser/config.js +37 -7
- package/lib/mcp/browser/context.js +13 -61
- package/lib/mcp/browser/response.js +183 -251
- package/lib/mcp/browser/sessionLog.js +19 -104
- package/lib/mcp/browser/tab.js +49 -28
- package/lib/mcp/browser/tools/common.js +4 -4
- package/lib/mcp/browser/tools/console.js +20 -3
- package/lib/mcp/browser/tools/dialogs.js +0 -1
- package/lib/mcp/browser/tools/evaluate.js +6 -4
- package/lib/mcp/browser/tools/install.js +4 -1
- package/lib/mcp/browser/tools/keyboard.js +75 -8
- package/lib/mcp/browser/tools/mouse.js +59 -7
- package/lib/mcp/browser/tools/navigate.js +48 -5
- package/lib/mcp/browser/tools/network.js +21 -3
- package/lib/mcp/browser/tools/pdf.js +4 -3
- package/lib/mcp/browser/tools/runCode.js +6 -10
- package/lib/mcp/browser/tools/screenshot.js +8 -26
- package/lib/mcp/browser/tools/snapshot.js +38 -22
- package/lib/mcp/browser/tools/tabs.js +8 -8
- package/lib/mcp/browser/tools/tool.js +3 -6
- package/lib/mcp/browser/tools/tracing.js +3 -3
- package/lib/mcp/browser/tools/utils.js +2 -2
- package/lib/mcp/browser/tools/verify.js +4 -4
- package/lib/mcp/browser/tools/wait.js +1 -1
- package/lib/mcp/browser/tools.js +2 -2
- package/lib/mcp/extension/extensionContextFactory.js +2 -2
- package/lib/mcp/program.js +3 -2
- package/lib/mcp/terminal/cli.js +4 -216
- package/lib/mcp/terminal/command.js +56 -0
- package/lib/mcp/terminal/commands.js +528 -0
- package/lib/mcp/terminal/daemon.js +42 -25
- package/lib/mcp/terminal/helpGenerator.js +152 -0
- package/lib/mcp/terminal/program.js +434 -0
- package/lib/mcp/terminal/socketConnection.js +2 -4
- package/lib/mcpBundleImpl/index.js +44 -44
- package/lib/util.js +3 -6
- package/package.json +1 -1
|
@@ -35,6 +35,7 @@ var import_vm = __toESM(require("vm"));
|
|
|
35
35
|
var import_utils = require("playwright-core/lib/utils");
|
|
36
36
|
var import_test = require("playwright/test");
|
|
37
37
|
var import_mcpBundle = require("../../../mcpBundle");
|
|
38
|
+
var import_ai_runner = require("@cotestdev/ai-runner");
|
|
38
39
|
var import_tool = require("./tool");
|
|
39
40
|
var import_common = require("./common");
|
|
40
41
|
const codeSchema = import_common.baseSchema.extend({
|
|
@@ -50,7 +51,6 @@ const runCode = (0, import_tool.defineTabTool)({
|
|
|
50
51
|
type: "action"
|
|
51
52
|
},
|
|
52
53
|
handle: async (tab, params, response) => {
|
|
53
|
-
response.setIncludeSnapshot();
|
|
54
54
|
response.addCode(`await (${params.code})(page);`);
|
|
55
55
|
const __end__ = new import_utils.ManualPromise();
|
|
56
56
|
const context = {
|
|
@@ -70,13 +70,12 @@ const runCode = (0, import_tool.defineTabTool)({
|
|
|
70
70
|
await import_vm.default.runInContext(snippet, context);
|
|
71
71
|
const result = await __end__;
|
|
72
72
|
if (typeof result === "string")
|
|
73
|
-
response.
|
|
73
|
+
response.addTextResult(result);
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
76
|
});
|
|
77
|
-
const scriptSchema =
|
|
78
|
-
code: import_mcpBundle.z.string().describe(`A JavaScript function containing Playwright code to execute. It will be invoked with a single argument, page, which you can use for any page interaction. For example: \`async (page) => { await page.getByRole('button', { name: 'Submit' }).click(); return await page.title(); }\``)
|
|
79
|
-
params: import_mcpBundle.z.record(import_mcpBundle.z.any()).optional().describe("Parameters to pass to the script.")
|
|
77
|
+
const scriptSchema = import_mcpBundle.z.object({
|
|
78
|
+
code: import_mcpBundle.z.string().describe(`A JavaScript function containing Playwright code to execute. It will be invoked with a single argument, page, which you can use for any page interaction. For example: \`async (page) => { await page.getByRole('button', { name: 'Submit' }).click(); return await page.title(); }\``)
|
|
80
79
|
});
|
|
81
80
|
const runScript = (0, import_tool.defineTabTool)({
|
|
82
81
|
capability: "extra",
|
|
@@ -93,12 +92,9 @@ const runScript = (0, import_tool.defineTabTool)({
|
|
|
93
92
|
const context = {
|
|
94
93
|
page: tab.page,
|
|
95
94
|
expect: import_test.expect,
|
|
95
|
+
Runner: import_ai_runner.Runner,
|
|
96
96
|
__end__
|
|
97
97
|
};
|
|
98
|
-
if (params.params) {
|
|
99
|
-
for (const [key, value] of Object.entries(params.params))
|
|
100
|
-
context[key] = value;
|
|
101
|
-
}
|
|
102
98
|
import_vm.default.createContext(context);
|
|
103
99
|
await tab.waitForCompletion(async () => {
|
|
104
100
|
const snippet = `(async () => {
|
|
@@ -112,7 +108,7 @@ const runScript = (0, import_tool.defineTabTool)({
|
|
|
112
108
|
await import_vm.default.runInContext(snippet, context);
|
|
113
109
|
const result = await __end__;
|
|
114
110
|
if (typeof result === "string")
|
|
115
|
-
response.
|
|
111
|
+
response.addTextResult(result);
|
|
116
112
|
});
|
|
117
113
|
}
|
|
118
114
|
});
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
var screenshot_exports = {};
|
|
30
20
|
__export(screenshot_exports, {
|
|
@@ -32,7 +22,6 @@ __export(screenshot_exports, {
|
|
|
32
22
|
scaleImageToFitMessage: () => scaleImageToFitMessage
|
|
33
23
|
});
|
|
34
24
|
module.exports = __toCommonJS(screenshot_exports);
|
|
35
|
-
var import_fs = __toESM(require("fs"));
|
|
36
25
|
var import_utils = require("playwright-core/lib/utils");
|
|
37
26
|
var import_utilsBundle = require("playwright-core/lib/utilsBundle");
|
|
38
27
|
var import_utils2 = require("playwright-core/lib/utils");
|
|
@@ -57,8 +46,6 @@ const screenshot = (0, import_tool.defineTabTool)({
|
|
|
57
46
|
type: "readOnly"
|
|
58
47
|
},
|
|
59
48
|
handle: async (tab, params, response) => {
|
|
60
|
-
if (!!params.element !== !!params.ref)
|
|
61
|
-
throw new Error("Both element and ref must be provided or neither.");
|
|
62
49
|
if (params.fullPage && params.ref)
|
|
63
50
|
throw new Error("fullPage cannot be used with element screenshots.");
|
|
64
51
|
const fileType = params.type || "png";
|
|
@@ -68,22 +55,17 @@ const screenshot = (0, import_tool.defineTabTool)({
|
|
|
68
55
|
scale: "css",
|
|
69
56
|
...params.fullPage !== void 0 && { fullPage: params.fullPage }
|
|
70
57
|
};
|
|
71
|
-
const
|
|
72
|
-
const screenshotTarget = isElementScreenshot ? params.element : params.fullPage ? "full page" : "viewport";
|
|
73
|
-
const fileName = await response.addFile(params.filename || (0, import_utils3.dateAsFileName)(fileType), { origin: "llm", reason: `Screenshot of ${screenshotTarget}` });
|
|
74
|
-
response.addCode(`// Screenshot ${screenshotTarget} and save it as ${fileName}`);
|
|
58
|
+
const screenshotTarget = params.ref ? params.element || "element" : params.fullPage ? "full page" : "viewport";
|
|
75
59
|
const ref = params.ref ? await tab.refLocator({ element: params.element || "", ref: params.ref }) : null;
|
|
60
|
+
const data = ref ? await ref.locator.screenshot(options) : await tab.page.screenshot(options);
|
|
61
|
+
const suggestedFilename = params.filename || (0, import_utils3.dateAsFileName)(ref ? "element" : "page", fileType);
|
|
62
|
+
response.addCode(`// Screenshot ${screenshotTarget} and save it as ${suggestedFilename}`);
|
|
76
63
|
if (ref)
|
|
77
|
-
response.addCode(`await page.${ref.resolved}.screenshot(${(0, import_utils2.formatObject)(options)});`);
|
|
64
|
+
response.addCode(`await page.${ref.resolved}.screenshot(${(0, import_utils2.formatObject)({ ...options, path: suggestedFilename })});`);
|
|
78
65
|
else
|
|
79
|
-
response.addCode(`await page.screenshot(${(0, import_utils2.formatObject)(options)});`);
|
|
80
|
-
const
|
|
81
|
-
await (
|
|
82
|
-
await import_fs.default.promises.writeFile(fileName, buffer);
|
|
83
|
-
response.addImage({
|
|
84
|
-
contentType: fileType === "png" ? "image/png" : "image/jpeg",
|
|
85
|
-
data: scaleImageToFitMessage(buffer, fileType)
|
|
86
|
-
});
|
|
66
|
+
response.addCode(`await page.screenshot(${(0, import_utils2.formatObject)({ ...options, path: suggestedFilename })});`);
|
|
67
|
+
const contentType = fileType === "png" ? "image/png" : "image/jpeg";
|
|
68
|
+
await response.addResult(`Screenshot of ${screenshotTarget}`, data, { prefix: ref ? "element" : "page", ext: fileType, suggestedFilename, contentType });
|
|
87
69
|
}
|
|
88
70
|
});
|
|
89
71
|
function scaleImageToFitMessage(buffer, imageType) {
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
var snapshot_exports = {};
|
|
30
20
|
__export(snapshot_exports, {
|
|
@@ -32,7 +22,6 @@ __export(snapshot_exports, {
|
|
|
32
22
|
elementSchema: () => elementSchema
|
|
33
23
|
});
|
|
34
24
|
module.exports = __toCommonJS(snapshot_exports);
|
|
35
|
-
var import_fs = __toESM(require("fs"));
|
|
36
25
|
var import_mcpBundle = require("../../../mcpBundle");
|
|
37
26
|
var import_utils = require("playwright-core/lib/utils");
|
|
38
27
|
var import_tool = require("./tool");
|
|
@@ -50,14 +39,7 @@ const snapshot = (0, import_tool.defineTool)({
|
|
|
50
39
|
},
|
|
51
40
|
handle: async (context, params, response) => {
|
|
52
41
|
await context.ensureTab();
|
|
53
|
-
response.setIncludeFullSnapshot();
|
|
54
|
-
if (params.filename) {
|
|
55
|
-
await response.finish();
|
|
56
|
-
const renderedResponse = response.render();
|
|
57
|
-
const fileName = await response.addFile(params.filename, { origin: "llm", reason: "Saved snapshot" });
|
|
58
|
-
await import_fs.default.promises.writeFile(fileName, renderedResponse.asText());
|
|
59
|
-
response.setIncludeMetaOnly();
|
|
60
|
-
}
|
|
42
|
+
response.setIncludeFullSnapshot(params.filename);
|
|
61
43
|
}
|
|
62
44
|
});
|
|
63
45
|
const elementSchema = import_common.baseSchema.extend({
|
|
@@ -105,7 +87,7 @@ const drag = (0, import_tool.defineTabTool)({
|
|
|
105
87
|
name: "browser_drag",
|
|
106
88
|
title: "Drag mouse",
|
|
107
89
|
description: "Perform drag and drop between two elements",
|
|
108
|
-
inputSchema:
|
|
90
|
+
inputSchema: import_common.baseSchema.extend({
|
|
109
91
|
startElement: import_mcpBundle.z.string().describe("Human-readable source element description used to obtain the permission to interact with the element"),
|
|
110
92
|
startRef: import_mcpBundle.z.string().describe("Exact source element reference from the page snapshot"),
|
|
111
93
|
endElement: import_mcpBundle.z.string().describe("Human-readable target element description used to obtain the permission to interact with the element"),
|
|
@@ -175,7 +157,39 @@ const pickLocator = (0, import_tool.defineTabTool)({
|
|
|
175
157
|
},
|
|
176
158
|
handle: async (tab, params, response) => {
|
|
177
159
|
const { resolved } = await tab.refLocator(params);
|
|
178
|
-
response.
|
|
160
|
+
response.addTextResult(resolved);
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
const check = (0, import_tool.defineTabTool)({
|
|
164
|
+
capability: "core-input",
|
|
165
|
+
skillOnly: true,
|
|
166
|
+
schema: {
|
|
167
|
+
name: "browser_check",
|
|
168
|
+
title: "Check",
|
|
169
|
+
description: "Check a checkbox or radio button",
|
|
170
|
+
inputSchema: elementSchema,
|
|
171
|
+
type: "input"
|
|
172
|
+
},
|
|
173
|
+
handle: async (tab, params, response) => {
|
|
174
|
+
const { locator, resolved } = await tab.refLocator(params);
|
|
175
|
+
response.addCode(`await page.${resolved}.check();`);
|
|
176
|
+
await locator.check();
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
const uncheck = (0, import_tool.defineTabTool)({
|
|
180
|
+
capability: "core-input",
|
|
181
|
+
skillOnly: true,
|
|
182
|
+
schema: {
|
|
183
|
+
name: "browser_uncheck",
|
|
184
|
+
title: "Uncheck",
|
|
185
|
+
description: "Uncheck a checkbox or radio button",
|
|
186
|
+
inputSchema: elementSchema,
|
|
187
|
+
type: "input"
|
|
188
|
+
},
|
|
189
|
+
handle: async (tab, params, response) => {
|
|
190
|
+
const { locator, resolved } = await tab.refLocator(params);
|
|
191
|
+
response.addCode(`await page.${resolved}.uncheck();`);
|
|
192
|
+
await locator.uncheck();
|
|
179
193
|
}
|
|
180
194
|
});
|
|
181
195
|
var snapshot_default = [
|
|
@@ -184,7 +198,9 @@ var snapshot_default = [
|
|
|
184
198
|
drag,
|
|
185
199
|
hover,
|
|
186
200
|
selectOption,
|
|
187
|
-
pickLocator
|
|
201
|
+
pickLocator,
|
|
202
|
+
check,
|
|
203
|
+
uncheck
|
|
188
204
|
];
|
|
189
205
|
// Annotate the CommonJS export names for ESM import in node:
|
|
190
206
|
0 && (module.exports = {
|
|
@@ -23,6 +23,7 @@ __export(tabs_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(tabs_exports);
|
|
24
24
|
var import_mcpBundle = require("../../../mcpBundle");
|
|
25
25
|
var import_tool = require("./tool");
|
|
26
|
+
var import_response = require("../response");
|
|
26
27
|
var import_common = require("./common");
|
|
27
28
|
const browserTabs = (0, import_tool.defineTool)({
|
|
28
29
|
capability: "core-tabs",
|
|
@@ -40,27 +41,26 @@ const browserTabs = (0, import_tool.defineTool)({
|
|
|
40
41
|
switch (params.action) {
|
|
41
42
|
case "list": {
|
|
42
43
|
await context.ensureTab();
|
|
43
|
-
|
|
44
|
-
return;
|
|
44
|
+
break;
|
|
45
45
|
}
|
|
46
46
|
case "new": {
|
|
47
47
|
await context.newTab();
|
|
48
|
-
|
|
49
|
-
return;
|
|
48
|
+
break;
|
|
50
49
|
}
|
|
51
50
|
case "close": {
|
|
52
51
|
await context.closeTab(params.index);
|
|
53
|
-
|
|
54
|
-
return;
|
|
52
|
+
break;
|
|
55
53
|
}
|
|
56
54
|
case "select": {
|
|
57
55
|
if (params.index === void 0)
|
|
58
56
|
throw new Error("Tab index is required");
|
|
59
57
|
await context.selectTab(params.index);
|
|
60
|
-
|
|
61
|
-
return;
|
|
58
|
+
break;
|
|
62
59
|
}
|
|
63
60
|
}
|
|
61
|
+
const tabHeaders = await Promise.all(context.tabs().map((tab) => tab.headerSnapshot()));
|
|
62
|
+
const result = (0, import_response.renderTabsMarkdown)(tabHeaders);
|
|
63
|
+
response.addTextResult(result.join("\n"));
|
|
64
64
|
}
|
|
65
65
|
});
|
|
66
66
|
var tabs_default = [
|
|
@@ -31,15 +31,12 @@ function defineTabTool(tool) {
|
|
|
31
31
|
handle: async (context, params, response) => {
|
|
32
32
|
const tab = await context.ensureTab();
|
|
33
33
|
const modalStates = tab.modalStates().map((state) => state.type);
|
|
34
|
-
if (tool.clearsModalState && !modalStates.includes(tool.clearsModalState))
|
|
35
|
-
response.setIncludeModalStates(tab.modalStates());
|
|
34
|
+
if (tool.clearsModalState && !modalStates.includes(tool.clearsModalState))
|
|
36
35
|
response.addError(`Error: The tool "${tool.schema.name}" can only be used when there is related modal state present.`);
|
|
37
|
-
|
|
38
|
-
response.setIncludeModalStates(tab.modalStates());
|
|
36
|
+
else if (!tool.clearsModalState && modalStates.length)
|
|
39
37
|
response.addError(`Error: Tool "${tool.schema.name}" does not handle the modal state.`);
|
|
40
|
-
|
|
38
|
+
else
|
|
41
39
|
return tool.handle(tab, params, response);
|
|
42
|
-
}
|
|
43
40
|
}
|
|
44
41
|
};
|
|
45
42
|
}
|
|
@@ -34,7 +34,7 @@ const tracingStart = (0, import_tool.defineTool)({
|
|
|
34
34
|
},
|
|
35
35
|
handle: async (context, params, response) => {
|
|
36
36
|
const browserContext = await context.ensureBrowserContext();
|
|
37
|
-
const tracesDir = await context.outputFile(`traces`, { origin: "code",
|
|
37
|
+
const tracesDir = await context.outputFile(`traces`, { origin: "code", title: "Collecting trace" });
|
|
38
38
|
const name = "trace-" + Date.now();
|
|
39
39
|
await browserContext.tracing.start({
|
|
40
40
|
name,
|
|
@@ -45,7 +45,7 @@ const tracingStart = (0, import_tool.defineTool)({
|
|
|
45
45
|
const traceLegend = `- Action log: ${tracesDir}/${name}.trace
|
|
46
46
|
- Network log: ${tracesDir}/${name}.network
|
|
47
47
|
- Resources with content by sha1: ${tracesDir}/resources`;
|
|
48
|
-
response.
|
|
48
|
+
response.addTextResult(`Tracing started, saving to ${tracesDir}.
|
|
49
49
|
${traceLegend}`);
|
|
50
50
|
browserContext.tracing[traceLegendSymbol] = traceLegend;
|
|
51
51
|
}
|
|
@@ -63,7 +63,7 @@ const tracingStop = (0, import_tool.defineTool)({
|
|
|
63
63
|
const browserContext = await context.ensureBrowserContext();
|
|
64
64
|
await browserContext.tracing.stop();
|
|
65
65
|
const traceLegend = browserContext.tracing[traceLegendSymbol];
|
|
66
|
-
response.
|
|
66
|
+
response.addTextResult(`Tracing stopped.
|
|
67
67
|
${traceLegend}`);
|
|
68
68
|
}
|
|
69
69
|
});
|
|
@@ -62,9 +62,9 @@ async function waitForCompletion(tab, callback) {
|
|
|
62
62
|
async function callOnPageNoTrace(page, callback) {
|
|
63
63
|
return await page._wrapApiCall(() => callback(page), { internal: true });
|
|
64
64
|
}
|
|
65
|
-
function dateAsFileName(extension) {
|
|
65
|
+
function dateAsFileName(prefix, extension) {
|
|
66
66
|
const date = /* @__PURE__ */ new Date();
|
|
67
|
-
return
|
|
67
|
+
return `${prefix}-${date.toISOString().replace(/[:.]/g, "-")}.${extension}`;
|
|
68
68
|
}
|
|
69
69
|
function eventWaiter(page, event, timeout) {
|
|
70
70
|
const disposables = [];
|
|
@@ -44,7 +44,7 @@ const verifyElement = (0, import_tool.defineTabTool)({
|
|
|
44
44
|
return;
|
|
45
45
|
}
|
|
46
46
|
response.addCode(`await expect(page.getByRole(${(0, import_utils.escapeWithQuotes)(params.role)}, { name: ${(0, import_utils.escapeWithQuotes)(params.accessibleName)} })).toBeVisible();`);
|
|
47
|
-
response.
|
|
47
|
+
response.addTextResult("Done");
|
|
48
48
|
}
|
|
49
49
|
});
|
|
50
50
|
const verifyText = (0, import_tool.defineTabTool)({
|
|
@@ -65,7 +65,7 @@ const verifyText = (0, import_tool.defineTabTool)({
|
|
|
65
65
|
return;
|
|
66
66
|
}
|
|
67
67
|
response.addCode(`await expect(page.getByText(${(0, import_utils.escapeWithQuotes)(params.text)})).toBeVisible();`);
|
|
68
|
-
response.
|
|
68
|
+
response.addTextResult("Done");
|
|
69
69
|
}
|
|
70
70
|
});
|
|
71
71
|
const verifyList = (0, import_tool.defineTabTool)({
|
|
@@ -97,7 +97,7 @@ const verifyList = (0, import_tool.defineTabTool)({
|
|
|
97
97
|
${itemTexts.map((t) => ` - listitem: ${(0, import_utils.escapeWithQuotes)(t, '"')}`).join("\n")}
|
|
98
98
|
\``;
|
|
99
99
|
response.addCode(`await expect(page.locator('body')).toMatchAriaSnapshot(${ariaSnapshot});`);
|
|
100
|
-
response.
|
|
100
|
+
response.addTextResult("Done");
|
|
101
101
|
}
|
|
102
102
|
});
|
|
103
103
|
const verifyValue = (0, import_tool.defineTabTool)({
|
|
@@ -133,7 +133,7 @@ const verifyValue = (0, import_tool.defineTabTool)({
|
|
|
133
133
|
const matcher = value ? "toBeChecked" : "not.toBeChecked";
|
|
134
134
|
response.addCode(`await expect(${locatorSource}).${matcher}();`);
|
|
135
135
|
}
|
|
136
|
-
response.
|
|
136
|
+
response.addTextResult("Done");
|
|
137
137
|
}
|
|
138
138
|
});
|
|
139
139
|
var verify_default = [
|
|
@@ -55,7 +55,7 @@ const wait = (0, import_tool.defineTool)({
|
|
|
55
55
|
response.addCode(`await page.getByText(${JSON.stringify(params.text)}).first().waitFor({ state: 'visible' });`);
|
|
56
56
|
await locator.waitFor({ state: "visible" });
|
|
57
57
|
}
|
|
58
|
-
response.
|
|
58
|
+
response.addTextResult(`Waited for ${params.text || params.textGone || params.time}`);
|
|
59
59
|
response.setIncludeSnapshot();
|
|
60
60
|
}
|
|
61
61
|
});
|
package/lib/mcp/browser/tools.js
CHANGED
|
@@ -60,9 +60,9 @@ const browserTools = [
|
|
|
60
60
|
...import_form.default,
|
|
61
61
|
...import_install.default,
|
|
62
62
|
...import_keyboard.default,
|
|
63
|
+
...import_mouse.default,
|
|
63
64
|
...import_navigate.default,
|
|
64
65
|
...import_network.default,
|
|
65
|
-
...import_mouse.default,
|
|
66
66
|
...import_pdf.default,
|
|
67
67
|
...import_runCode.default,
|
|
68
68
|
...import_screenshot.default,
|
|
@@ -73,7 +73,7 @@ const browserTools = [
|
|
|
73
73
|
...import_verify.default
|
|
74
74
|
];
|
|
75
75
|
function filteredTools(config) {
|
|
76
|
-
return browserTools.filter((tool) => tool.capability.startsWith("core") || config.capabilities?.includes(tool.capability));
|
|
76
|
+
return browserTools.filter((tool) => tool.capability.startsWith("core") || config.capabilities?.includes(tool.capability)).filter((tool) => !tool.skillOnly);
|
|
77
77
|
}
|
|
78
78
|
// Annotate the CommonJS export names for ESM import in node:
|
|
79
79
|
0 && (module.exports = {
|
|
@@ -42,8 +42,8 @@ class ExtensionContextFactory {
|
|
|
42
42
|
this._userDataDir = userDataDir;
|
|
43
43
|
this._executablePath = executablePath;
|
|
44
44
|
}
|
|
45
|
-
async createContext(clientInfo, abortSignal,
|
|
46
|
-
const browser = await this._obtainBrowser(clientInfo, abortSignal, toolName);
|
|
45
|
+
async createContext(clientInfo, abortSignal, options) {
|
|
46
|
+
const browser = await this._obtainBrowser(clientInfo, abortSignal, options?.toolName);
|
|
47
47
|
return {
|
|
48
48
|
browserContext: browser.contexts()[0],
|
|
49
49
|
close: async () => {
|
package/lib/mcp/program.js
CHANGED
|
@@ -42,7 +42,8 @@ var import_browserContextFactory = require("./browser/browserContextFactory");
|
|
|
42
42
|
var import_browserServerBackend = require("./browser/browserServerBackend");
|
|
43
43
|
var import_extensionContextFactory = require("./extension/extensionContextFactory");
|
|
44
44
|
function decorateCommand(command, version) {
|
|
45
|
-
command.option("--allowed-hosts <hosts...>", "comma-separated list of hosts this server is allowed to serve from. Defaults to the host the server is bound to. Pass '*' to disable the host check.", import_config.commaSeparatedList).option("--allowed-origins <origins>", "semicolon-separated list of TRUSTED origins to allow the browser to request. Default is to allow all.\nImportant: *does not* serve as a security boundary and *does not* affect redirects. ", import_config.semicolonSeparatedList).option("--allow-unrestricted-file-access", "allow access to files outside of the workspace roots. Also allows unrestricted access to file:// URLs. By default access to file system is restricted to workspace root directories (or cwd if no roots are configured) only, and navigation to file:// URLs is blocked.").option("--blocked-origins <origins>", "semicolon-separated list of origins to block the browser from requesting. Blocklist is evaluated before allowlist. If used without the allowlist, requests not matching the blocklist are still allowed.\nImportant: *does not* serve as a security boundary and *does not* affect redirects.", import_config.semicolonSeparatedList).option("--block-service-workers", "block service workers").option("--browser <browser>", "browser or chrome channel to use, possible values: chrome, firefox, webkit, msedge.").option("--caps <caps>", "comma-separated list of additional capabilities to enable, possible values: vision, pdf.", import_config.commaSeparatedList).option("--cdp-endpoint <endpoint>", "CDP endpoint to connect to.").option("--cdp-header <headers...>", "CDP headers to send with the connect request, multiple can be specified.", import_config.headerParser).option("--config <path>", "path to the configuration file.").option("--console-level <level>", 'level of console messages to return: "error", "warning", "info", "debug". Each level includes the messages of more severe levels.', import_config.enumParser.bind(null, "--console-level", ["error", "warning", "info", "debug"])).option("--device <device>", 'device to emulate, for example: "iPhone 15"').option("--executable-path <path>", "path to the browser executable.").option("--extension", 'Connect to a running browser instance (Edge/Chrome only). Requires the "Playwright MCP Bridge" browser extension to be installed.').option("--grant-permissions <permissions...>", 'List of permissions to grant to the browser context, for example "geolocation", "clipboard-read", "clipboard-write".', import_config.commaSeparatedList).option("--headless", "run browser in headless mode, headed by default").option("--host <host>", "host to bind server to. Default is localhost. Use 0.0.0.0 to bind to all interfaces.").option("--ignore-https-errors", "ignore https errors").option("--init-page <path...>", "path to TypeScript file to evaluate on Playwright page object").option("--init-script <path...>", "path to JavaScript file to add as an initialization script. The script will be evaluated in every page before any of the page's scripts. Can be specified multiple times.").option("--isolated", "keep the browser profile in memory, do not save it to disk.").option("--image-responses <mode>", 'whether to send image responses to the client. Can be "allow" or "omit", Defaults to "allow".', import_config.enumParser.bind(null, "--image-responses", ["allow", "omit"])).option("--no-sandbox", "disable the sandbox for all process types that are normally sandboxed.").option("--output-dir <path>", "path to the directory for output files.").option("--port <port>", "port to listen on for SSE transport.").option("--proxy-bypass <bypass>", 'comma-separated domains to bypass proxy, for example ".com,chromium.org,.domain.com"').option("--proxy-server <proxy>", 'specify proxy server, for example "http://myproxy:3128" or "socks5://myproxy:8080"').option("--save-session", "Whether to save the Playwright MCP session into the output directory.").option("--save-trace", "Whether to save the Playwright Trace of the session into the output directory.").option("--save-video <size>", 'Whether to save the video of the session into the output directory. For example "--save-video=800x600"', import_config.resolutionParser.bind(null, "--save-video")).option("--secrets <path>", "path to a file containing secrets in the dotenv format", import_config.dotenvFileLoader).option("--shared-browser-context", "reuse the same browser context between all connected HTTP clients.").option("--snapshot-mode <mode>", 'when taking snapshots for responses, specifies the mode to use. Can be "incremental", "full", or "none". Default is incremental.').option("--storage-state <path>", "path to the storage state file for isolated sessions.").option("--test-id-attribute <attribute>", 'specify the attribute to use for test ids, defaults to "data-testid"').option("--timeout-action <timeout>", "specify action timeout in milliseconds, defaults to 5000ms", import_config.numberParser).option("--timeout-navigation <timeout>", "specify navigation timeout in milliseconds, defaults to 60000ms", import_config.numberParser).option("--user-agent <ua string>", "specify user agent string").option("--user-data-dir <path>", "path to the user data directory. If not specified, a temporary directory will be created.").option("--viewport-size <size>", 'specify browser viewport size in pixels, for example "1280x720"', import_config.resolutionParser.bind(null, "--viewport-size")).addOption(new import_utilsBundle.ProgramOption("--vision", "Legacy option, use --caps=vision instead").hideHelp()).addOption(new import_utilsBundle.ProgramOption("--daemon <socket>", "run as daemon").hideHelp()).action(async (options) => {
|
|
45
|
+
command.option("--allowed-hosts <hosts...>", "comma-separated list of hosts this server is allowed to serve from. Defaults to the host the server is bound to. Pass '*' to disable the host check.", import_config.commaSeparatedList).option("--allowed-origins <origins>", "semicolon-separated list of TRUSTED origins to allow the browser to request. Default is to allow all.\nImportant: *does not* serve as a security boundary and *does not* affect redirects. ", import_config.semicolonSeparatedList).option("--allow-unrestricted-file-access", "allow access to files outside of the workspace roots. Also allows unrestricted access to file:// URLs. By default access to file system is restricted to workspace root directories (or cwd if no roots are configured) only, and navigation to file:// URLs is blocked.").option("--blocked-origins <origins>", "semicolon-separated list of origins to block the browser from requesting. Blocklist is evaluated before allowlist. If used without the allowlist, requests not matching the blocklist are still allowed.\nImportant: *does not* serve as a security boundary and *does not* affect redirects.", import_config.semicolonSeparatedList).option("--block-service-workers", "block service workers").option("--browser <browser>", "browser or chrome channel to use, possible values: chrome, firefox, webkit, msedge.").option("--caps <caps>", "comma-separated list of additional capabilities to enable, possible values: vision, pdf.", import_config.commaSeparatedList).option("--cdp-endpoint <endpoint>", "CDP endpoint to connect to.").option("--cdp-header <headers...>", "CDP headers to send with the connect request, multiple can be specified.", import_config.headerParser).option("--codegen <lang>", 'specify the language to use for code generation, possible values: "typescript", "none". Default is "typescript".', import_config.enumParser.bind(null, "--codegen", ["none", "typescript"])).option("--config <path>", "path to the configuration file.").option("--console-level <level>", 'level of console messages to return: "error", "warning", "info", "debug". Each level includes the messages of more severe levels.', import_config.enumParser.bind(null, "--console-level", ["error", "warning", "info", "debug"])).option("--device <device>", 'device to emulate, for example: "iPhone 15"').option("--executable-path <path>", "path to the browser executable.").option("--extension", 'Connect to a running browser instance (Edge/Chrome only). Requires the "Playwright MCP Bridge" browser extension to be installed.').option("--grant-permissions <permissions...>", 'List of permissions to grant to the browser context, for example "geolocation", "clipboard-read", "clipboard-write".', import_config.commaSeparatedList).option("--headless", "run browser in headless mode, headed by default").option("--host <host>", "host to bind server to. Default is localhost. Use 0.0.0.0 to bind to all interfaces.").option("--ignore-https-errors", "ignore https errors").option("--init-page <path...>", "path to TypeScript file to evaluate on Playwright page object").option("--init-script <path...>", "path to JavaScript file to add as an initialization script. The script will be evaluated in every page before any of the page's scripts. Can be specified multiple times.").option("--isolated", "keep the browser profile in memory, do not save it to disk.").option("--image-responses <mode>", 'whether to send image responses to the client. Can be "allow" or "omit", Defaults to "allow".', import_config.enumParser.bind(null, "--image-responses", ["allow", "omit"])).option("--no-sandbox", "disable the sandbox for all process types that are normally sandboxed.").option("--output-dir <path>", "path to the directory for output files.").option("--output-mode <mode>", 'whether to save snapshots, console messages, network logs to a file or to the standard output. Can be "file" or "stdout". Default is "stdout".', import_config.enumParser.bind(null, "--output-mode", ["file", "stdout"])).option("--port <port>", "port to listen on for SSE transport.").option("--proxy-bypass <bypass>", 'comma-separated domains to bypass proxy, for example ".com,chromium.org,.domain.com"').option("--proxy-server <proxy>", 'specify proxy server, for example "http://myproxy:3128" or "socks5://myproxy:8080"').option("--sandbox", "enable the sandbox for all process types that are normally not sandboxed.").option("--save-session", "Whether to save the Playwright MCP session into the output directory.").option("--save-trace", "Whether to save the Playwright Trace of the session into the output directory.").option("--save-video <size>", 'Whether to save the video of the session into the output directory. For example "--save-video=800x600"', import_config.resolutionParser.bind(null, "--save-video")).option("--secrets <path>", "path to a file containing secrets in the dotenv format", import_config.dotenvFileLoader).option("--shared-browser-context", "reuse the same browser context between all connected HTTP clients.").option("--snapshot-mode <mode>", 'when taking snapshots for responses, specifies the mode to use. Can be "incremental", "full", or "none". Default is incremental.').option("--storage-state <path>", "path to the storage state file for isolated sessions.").option("--test-id-attribute <attribute>", 'specify the attribute to use for test ids, defaults to "data-testid"').option("--timeout-action <timeout>", "specify action timeout in milliseconds, defaults to 5000ms", import_config.numberParser).option("--timeout-navigation <timeout>", "specify navigation timeout in milliseconds, defaults to 60000ms", import_config.numberParser).option("--user-agent <ua string>", "specify user agent string").option("--user-data-dir <path>", "path to the user data directory. If not specified, a temporary directory will be created.").option("--viewport-size <size>", 'specify browser viewport size in pixels, for example "1280x720"', import_config.resolutionParser.bind(null, "--viewport-size")).addOption(new import_utilsBundle.ProgramOption("--vision", "Legacy option, use --caps=vision instead").hideHelp()).addOption(new import_utilsBundle.ProgramOption("--daemon <socket>", "run as daemon").hideHelp()).addOption(new import_utilsBundle.ProgramOption("--daemon-data-dir <path>", "path to the daemon data directory.").hideHelp()).addOption(new import_utilsBundle.ProgramOption("--daemon-headed", "run daemon in headed mode").hideHelp()).action(async (options) => {
|
|
46
|
+
options.sandbox = options.sandbox === true ? void 0 : false;
|
|
46
47
|
(0, import_watchdog.setupExitWatchdog)();
|
|
47
48
|
if (options.vision) {
|
|
48
49
|
console.error("The --vision option is deprecated, use --caps=vision instead");
|
|
@@ -76,7 +77,7 @@ Please run the command below. It will install a local copy of ffmpeg and will no
|
|
|
76
77
|
name: "Playwright",
|
|
77
78
|
nameInConfig: "playwright-daemon",
|
|
78
79
|
version,
|
|
79
|
-
create: () => new import_browserServerBackend.BrowserServerBackend(config, browserContextFactory)
|
|
80
|
+
create: () => new import_browserServerBackend.BrowserServerBackend(config, browserContextFactory, { allTools: true, structuredOutput: true })
|
|
80
81
|
};
|
|
81
82
|
const socketPath = await (0, import_daemon.startMcpDaemonServer)(options.daemon, serverBackendFactory);
|
|
82
83
|
console.error(`Daemon server listening on ${socketPath}`);
|