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