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