@playwright/mcp 0.0.13 → 0.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +134 -30
- package/index.d.ts +37 -24
- package/lib/context.js +169 -85
- package/lib/index.js +64 -9
- package/lib/manualPromise.js +116 -0
- package/lib/program.js +4 -53
- package/lib/server.js +23 -5
- package/lib/tools/common.js +34 -38
- package/lib/{resources → tools}/console.js +23 -13
- package/lib/tools/dialogs.js +52 -0
- package/lib/tools/files.js +21 -17
- package/lib/tools/install.js +7 -8
- package/lib/tools/keyboard.js +16 -19
- package/lib/tools/navigate.js +41 -43
- package/lib/tools/network.js +51 -0
- package/lib/tools/pdf.js +47 -11
- package/lib/tools/screen.js +140 -76
- package/lib/tools/snapshot.js +145 -100
- package/lib/tools/tabs.js +52 -56
- package/lib/tools/tool.js +4 -0
- package/lib/tools/utils.js +2 -2
- package/package.json +6 -3
package/lib/server.js
CHANGED
|
@@ -19,10 +19,11 @@ exports.ServerList = void 0;
|
|
|
19
19
|
exports.createServerWithTools = createServerWithTools;
|
|
20
20
|
const index_js_1 = require("@modelcontextprotocol/sdk/server/index.js");
|
|
21
21
|
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
22
|
+
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
22
23
|
const context_1 = require("./context");
|
|
23
24
|
function createServerWithTools(options) {
|
|
24
25
|
const { name, version, tools, resources } = options;
|
|
25
|
-
const context = new context_1.Context(options);
|
|
26
|
+
const context = new context_1.Context(tools, options);
|
|
26
27
|
const server = new index_js_1.Server({ name, version }, {
|
|
27
28
|
capabilities: {
|
|
28
29
|
tools: {},
|
|
@@ -30,7 +31,13 @@ function createServerWithTools(options) {
|
|
|
30
31
|
}
|
|
31
32
|
});
|
|
32
33
|
server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => {
|
|
33
|
-
return {
|
|
34
|
+
return {
|
|
35
|
+
tools: tools.map(tool => ({
|
|
36
|
+
name: tool.schema.name,
|
|
37
|
+
description: tool.schema.description,
|
|
38
|
+
inputSchema: (0, zod_to_json_schema_1.zodToJsonSchema)(tool.schema.inputSchema)
|
|
39
|
+
})),
|
|
40
|
+
};
|
|
34
41
|
});
|
|
35
42
|
server.setRequestHandler(types_js_1.ListResourcesRequestSchema, async () => {
|
|
36
43
|
return { resources: resources.map(resource => resource.schema) };
|
|
@@ -43,9 +50,20 @@ function createServerWithTools(options) {
|
|
|
43
50
|
isError: true,
|
|
44
51
|
};
|
|
45
52
|
}
|
|
53
|
+
const modalStates = context.modalStates().map(state => state.type);
|
|
54
|
+
if ((tool.clearsModalState && !modalStates.includes(tool.clearsModalState)) ||
|
|
55
|
+
(!tool.clearsModalState && modalStates.length)) {
|
|
56
|
+
const text = [
|
|
57
|
+
`Tool "${request.params.name}" does not handle the modal state.`,
|
|
58
|
+
...context.modalStatesMarkdown(),
|
|
59
|
+
].join('\n');
|
|
60
|
+
return {
|
|
61
|
+
content: [{ type: 'text', text }],
|
|
62
|
+
isError: true,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
46
65
|
try {
|
|
47
|
-
|
|
48
|
-
return result;
|
|
66
|
+
return await context.run(tool, request.params.arguments);
|
|
49
67
|
}
|
|
50
68
|
catch (error) {
|
|
51
69
|
return {
|
|
@@ -75,7 +93,7 @@ class ServerList {
|
|
|
75
93
|
this._serverFactory = serverFactory;
|
|
76
94
|
}
|
|
77
95
|
async create() {
|
|
78
|
-
const server = this._serverFactory();
|
|
96
|
+
const server = await this._serverFactory();
|
|
79
97
|
this._servers.push(server);
|
|
80
98
|
return server;
|
|
81
99
|
}
|
package/lib/tools/common.js
CHANGED
|
@@ -16,74 +16,70 @@
|
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
const zod_1 = require("zod");
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
time: zod_1.z.number().describe('The time to wait in seconds'),
|
|
22
|
-
});
|
|
23
|
-
const wait = {
|
|
19
|
+
const tool_1 = require("./tool");
|
|
20
|
+
const wait = captureSnapshot => (0, tool_1.defineTool)({
|
|
24
21
|
capability: 'wait',
|
|
25
22
|
schema: {
|
|
26
23
|
name: 'browser_wait',
|
|
27
24
|
description: 'Wait for a specified time in seconds',
|
|
28
|
-
inputSchema:
|
|
25
|
+
inputSchema: zod_1.z.object({
|
|
26
|
+
time: zod_1.z.number().describe('The time to wait in seconds'),
|
|
27
|
+
}),
|
|
29
28
|
},
|
|
30
29
|
handle: async (context, params) => {
|
|
31
|
-
|
|
32
|
-
await new Promise(f => setTimeout(f, Math.min(10000, validatedParams.time * 1000)));
|
|
30
|
+
await new Promise(f => setTimeout(f, Math.min(10000, params.time * 1000)));
|
|
33
31
|
return {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}],
|
|
32
|
+
code: [`// Waited for ${params.time} seconds`],
|
|
33
|
+
captureSnapshot,
|
|
34
|
+
waitForNetwork: false,
|
|
38
35
|
};
|
|
39
36
|
},
|
|
40
|
-
};
|
|
41
|
-
const
|
|
42
|
-
const close = {
|
|
37
|
+
});
|
|
38
|
+
const close = (0, tool_1.defineTool)({
|
|
43
39
|
capability: 'core',
|
|
44
40
|
schema: {
|
|
45
41
|
name: 'browser_close',
|
|
46
42
|
description: 'Close the page',
|
|
47
|
-
inputSchema:
|
|
43
|
+
inputSchema: zod_1.z.object({}),
|
|
48
44
|
},
|
|
49
45
|
handle: async (context) => {
|
|
50
46
|
await context.close();
|
|
51
47
|
return {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}],
|
|
48
|
+
code: [`// Internal to close the page`],
|
|
49
|
+
captureSnapshot: false,
|
|
50
|
+
waitForNetwork: false,
|
|
56
51
|
};
|
|
57
52
|
},
|
|
58
|
-
};
|
|
59
|
-
const resizeSchema = zod_1.z.object({
|
|
60
|
-
width: zod_1.z.number().describe('Width of the browser window'),
|
|
61
|
-
height: zod_1.z.number().describe('Height of the browser window'),
|
|
62
53
|
});
|
|
63
|
-
const resize = captureSnapshot => ({
|
|
54
|
+
const resize = captureSnapshot => (0, tool_1.defineTool)({
|
|
64
55
|
capability: 'core',
|
|
65
56
|
schema: {
|
|
66
57
|
name: 'browser_resize',
|
|
67
58
|
description: 'Resize the browser window',
|
|
68
|
-
inputSchema:
|
|
59
|
+
inputSchema: zod_1.z.object({
|
|
60
|
+
width: zod_1.z.number().describe('Width of the browser window'),
|
|
61
|
+
height: zod_1.z.number().describe('Height of the browser window'),
|
|
62
|
+
}),
|
|
69
63
|
},
|
|
70
64
|
handle: async (context, params) => {
|
|
71
|
-
const
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
await
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
65
|
+
const tab = context.currentTabOrDie();
|
|
66
|
+
const code = [
|
|
67
|
+
`// Resize browser window to ${params.width}x${params.height}`,
|
|
68
|
+
`await page.setViewportSize({ width: ${params.width}, height: ${params.height} });`
|
|
69
|
+
];
|
|
70
|
+
const action = async () => {
|
|
71
|
+
await tab.page.setViewportSize({ width: params.width, height: params.height });
|
|
72
|
+
};
|
|
73
|
+
return {
|
|
74
|
+
code,
|
|
75
|
+
action,
|
|
81
76
|
captureSnapshot,
|
|
82
|
-
|
|
77
|
+
waitForNetwork: true
|
|
78
|
+
};
|
|
83
79
|
},
|
|
84
80
|
});
|
|
85
81
|
exports.default = (captureSnapshot) => [
|
|
86
82
|
close,
|
|
87
|
-
wait,
|
|
83
|
+
wait(captureSnapshot),
|
|
88
84
|
resize(captureSnapshot)
|
|
89
85
|
];
|
|
@@ -15,20 +15,30 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
const zod_1 = require("zod");
|
|
19
|
+
const tool_1 = require("./tool");
|
|
20
|
+
const console = (0, tool_1.defineTool)({
|
|
21
|
+
capability: 'core',
|
|
20
22
|
schema: {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
name: 'browser_console_messages',
|
|
24
|
+
description: 'Returns all console messages',
|
|
25
|
+
inputSchema: zod_1.z.object({}),
|
|
24
26
|
},
|
|
25
|
-
|
|
26
|
-
const messages =
|
|
27
|
+
handle: async (context) => {
|
|
28
|
+
const messages = context.currentTabOrDie().console();
|
|
27
29
|
const log = messages.map(message => `[${message.type().toUpperCase()}] ${message.text()}`).join('\n');
|
|
28
|
-
return
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
return {
|
|
31
|
+
code: [`// <internal code to get console messages>`],
|
|
32
|
+
action: async () => {
|
|
33
|
+
return {
|
|
34
|
+
content: [{ type: 'text', text: log }]
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
captureSnapshot: false,
|
|
38
|
+
waitForNetwork: false,
|
|
39
|
+
};
|
|
33
40
|
},
|
|
34
|
-
};
|
|
41
|
+
});
|
|
42
|
+
exports.default = [
|
|
43
|
+
console,
|
|
44
|
+
];
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Microsoft Corporation.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
const zod_1 = require("zod");
|
|
19
|
+
const tool_1 = require("./tool");
|
|
20
|
+
const handleDialog = captureSnapshot => (0, tool_1.defineTool)({
|
|
21
|
+
capability: 'core',
|
|
22
|
+
schema: {
|
|
23
|
+
name: 'browser_handle_dialog',
|
|
24
|
+
description: 'Handle a dialog',
|
|
25
|
+
inputSchema: zod_1.z.object({
|
|
26
|
+
accept: zod_1.z.boolean().describe('Whether to accept the dialog.'),
|
|
27
|
+
promptText: zod_1.z.string().optional().describe('The text of the prompt in case of a prompt dialog.'),
|
|
28
|
+
}),
|
|
29
|
+
},
|
|
30
|
+
handle: async (context, params) => {
|
|
31
|
+
const dialogState = context.modalStates().find(state => state.type === 'dialog');
|
|
32
|
+
if (!dialogState)
|
|
33
|
+
throw new Error('No dialog visible');
|
|
34
|
+
if (params.accept)
|
|
35
|
+
await dialogState.dialog.accept(params.promptText);
|
|
36
|
+
else
|
|
37
|
+
await dialogState.dialog.dismiss();
|
|
38
|
+
context.clearModalState(dialogState);
|
|
39
|
+
const code = [
|
|
40
|
+
`// <internal code to handle "${dialogState.dialog.type()}" dialog>`,
|
|
41
|
+
];
|
|
42
|
+
return {
|
|
43
|
+
code,
|
|
44
|
+
captureSnapshot,
|
|
45
|
+
waitForNetwork: false,
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
clearsModalState: 'dialog',
|
|
49
|
+
});
|
|
50
|
+
exports.default = (captureSnapshot) => [
|
|
51
|
+
handleDialog(captureSnapshot),
|
|
52
|
+
];
|
package/lib/tools/files.js
CHANGED
|
@@ -16,31 +16,35 @@
|
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
const zod_1 = require("zod");
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
paths: zod_1.z.array(zod_1.z.string()).describe('The absolute paths to the files to upload. Can be a single file or multiple files.'),
|
|
22
|
-
});
|
|
23
|
-
const uploadFile = captureSnapshot => ({
|
|
19
|
+
const tool_1 = require("./tool");
|
|
20
|
+
const uploadFile = captureSnapshot => (0, tool_1.defineTool)({
|
|
24
21
|
capability: 'files',
|
|
25
22
|
schema: {
|
|
26
23
|
name: 'browser_file_upload',
|
|
27
24
|
description: 'Upload one or multiple files',
|
|
28
|
-
inputSchema:
|
|
25
|
+
inputSchema: zod_1.z.object({
|
|
26
|
+
paths: zod_1.z.array(zod_1.z.string()).describe('The absolute paths to the files to upload. Can be a single file or multiple files.'),
|
|
27
|
+
}),
|
|
29
28
|
},
|
|
30
29
|
handle: async (context, params) => {
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
30
|
+
const modalState = context.modalStates().find(state => state.type === 'fileChooser');
|
|
31
|
+
if (!modalState)
|
|
32
|
+
throw new Error('No file chooser visible');
|
|
33
|
+
const code = [
|
|
34
|
+
`// <internal code to chose files ${params.paths.join(', ')}`,
|
|
35
|
+
];
|
|
36
|
+
const action = async () => {
|
|
37
|
+
await modalState.fileChooser.setFiles(params.paths);
|
|
38
|
+
context.clearModalState(modalState);
|
|
39
|
+
};
|
|
40
|
+
return {
|
|
41
|
+
code,
|
|
42
|
+
action,
|
|
40
43
|
captureSnapshot,
|
|
41
|
-
|
|
42
|
-
}
|
|
44
|
+
waitForNetwork: true,
|
|
45
|
+
};
|
|
43
46
|
},
|
|
47
|
+
clearsModalState: 'fileChooser',
|
|
44
48
|
});
|
|
45
49
|
exports.default = (captureSnapshot) => [
|
|
46
50
|
uploadFile(captureSnapshot),
|
package/lib/tools/install.js
CHANGED
|
@@ -21,13 +21,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
21
21
|
const child_process_1 = require("child_process");
|
|
22
22
|
const path_1 = __importDefault(require("path"));
|
|
23
23
|
const zod_1 = require("zod");
|
|
24
|
-
const
|
|
25
|
-
const install = {
|
|
24
|
+
const tool_1 = require("./tool");
|
|
25
|
+
const install = (0, tool_1.defineTool)({
|
|
26
26
|
capability: 'install',
|
|
27
27
|
schema: {
|
|
28
28
|
name: 'browser_install',
|
|
29
29
|
description: 'Install the browser specified in the config. Call this if you get an error about the browser not being installed.',
|
|
30
|
-
inputSchema:
|
|
30
|
+
inputSchema: zod_1.z.object({}),
|
|
31
31
|
},
|
|
32
32
|
handle: async (context) => {
|
|
33
33
|
const channel = context.options.launchOptions?.channel ?? context.options.browserName ?? 'chrome';
|
|
@@ -47,13 +47,12 @@ const install = {
|
|
|
47
47
|
});
|
|
48
48
|
});
|
|
49
49
|
return {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}],
|
|
50
|
+
code: [`// Browser ${channel} installed`],
|
|
51
|
+
captureSnapshot: false,
|
|
52
|
+
waitForNetwork: false,
|
|
54
53
|
};
|
|
55
54
|
},
|
|
56
|
-
};
|
|
55
|
+
});
|
|
57
56
|
exports.default = [
|
|
58
57
|
install,
|
|
59
58
|
];
|
package/lib/tools/keyboard.js
CHANGED
|
@@ -14,34 +14,31 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
-
};
|
|
20
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
18
|
const zod_1 = require("zod");
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
key: zod_1.z.string().describe('Name of the key to press or a character to generate, such as `ArrowLeft` or `a`'),
|
|
25
|
-
});
|
|
26
|
-
const pressKey = captureSnapshot => ({
|
|
19
|
+
const tool_1 = require("./tool");
|
|
20
|
+
const pressKey = captureSnapshot => (0, tool_1.defineTool)({
|
|
27
21
|
capability: 'core',
|
|
28
22
|
schema: {
|
|
29
23
|
name: 'browser_press_key',
|
|
30
24
|
description: 'Press a key on the keyboard',
|
|
31
|
-
inputSchema:
|
|
25
|
+
inputSchema: zod_1.z.object({
|
|
26
|
+
key: zod_1.z.string().describe('Name of the key to press or a character to generate, such as `ArrowLeft` or `a`'),
|
|
27
|
+
}),
|
|
32
28
|
},
|
|
33
29
|
handle: async (context, params) => {
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
30
|
+
const tab = context.currentTabOrDie();
|
|
31
|
+
const code = [
|
|
32
|
+
`// Press ${params.key}`,
|
|
33
|
+
`await page.keyboard.press('${params.key}');`,
|
|
34
|
+
];
|
|
35
|
+
const action = () => tab.page.keyboard.press(params.key);
|
|
36
|
+
return {
|
|
37
|
+
code,
|
|
38
|
+
action,
|
|
43
39
|
captureSnapshot,
|
|
44
|
-
|
|
40
|
+
waitForNetwork: true
|
|
41
|
+
};
|
|
45
42
|
},
|
|
46
43
|
});
|
|
47
44
|
exports.default = (captureSnapshot) => [
|
package/lib/tools/navigate.js
CHANGED
|
@@ -16,72 +16,70 @@
|
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
const zod_1 = require("zod");
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
url: zod_1.z.string().describe('The URL to navigate to'),
|
|
22
|
-
});
|
|
23
|
-
const navigate = captureSnapshot => ({
|
|
19
|
+
const tool_1 = require("./tool");
|
|
20
|
+
const navigate = captureSnapshot => (0, tool_1.defineTool)({
|
|
24
21
|
capability: 'core',
|
|
25
22
|
schema: {
|
|
26
23
|
name: 'browser_navigate',
|
|
27
24
|
description: 'Navigate to a URL',
|
|
28
|
-
inputSchema:
|
|
25
|
+
inputSchema: zod_1.z.object({
|
|
26
|
+
url: zod_1.z.string().describe('The URL to navigate to'),
|
|
27
|
+
}),
|
|
29
28
|
},
|
|
30
29
|
handle: async (context, params) => {
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return { code };
|
|
40
|
-
}, {
|
|
30
|
+
const tab = await context.ensureTab();
|
|
31
|
+
await tab.navigate(params.url);
|
|
32
|
+
const code = [
|
|
33
|
+
`// Navigate to ${params.url}`,
|
|
34
|
+
`await page.goto('${params.url}');`,
|
|
35
|
+
];
|
|
36
|
+
return {
|
|
37
|
+
code,
|
|
41
38
|
captureSnapshot,
|
|
42
|
-
|
|
39
|
+
waitForNetwork: false,
|
|
40
|
+
};
|
|
43
41
|
},
|
|
44
42
|
});
|
|
45
|
-
const
|
|
46
|
-
const goBack = snapshot => ({
|
|
43
|
+
const goBack = captureSnapshot => (0, tool_1.defineTool)({
|
|
47
44
|
capability: 'history',
|
|
48
45
|
schema: {
|
|
49
46
|
name: 'browser_navigate_back',
|
|
50
47
|
description: 'Go back to the previous page',
|
|
51
|
-
inputSchema:
|
|
48
|
+
inputSchema: zod_1.z.object({}),
|
|
52
49
|
},
|
|
53
50
|
handle: async (context) => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
captureSnapshot
|
|
63
|
-
|
|
51
|
+
const tab = await context.ensureTab();
|
|
52
|
+
await tab.page.goBack();
|
|
53
|
+
const code = [
|
|
54
|
+
`// Navigate back`,
|
|
55
|
+
`await page.goBack();`,
|
|
56
|
+
];
|
|
57
|
+
return {
|
|
58
|
+
code,
|
|
59
|
+
captureSnapshot,
|
|
60
|
+
waitForNetwork: false,
|
|
61
|
+
};
|
|
64
62
|
},
|
|
65
63
|
});
|
|
66
|
-
const
|
|
67
|
-
const goForward = snapshot => ({
|
|
64
|
+
const goForward = captureSnapshot => (0, tool_1.defineTool)({
|
|
68
65
|
capability: 'history',
|
|
69
66
|
schema: {
|
|
70
67
|
name: 'browser_navigate_forward',
|
|
71
68
|
description: 'Go forward to the next page',
|
|
72
|
-
inputSchema:
|
|
69
|
+
inputSchema: zod_1.z.object({}),
|
|
73
70
|
},
|
|
74
71
|
handle: async (context) => {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
captureSnapshot
|
|
84
|
-
|
|
72
|
+
const tab = context.currentTabOrDie();
|
|
73
|
+
await tab.page.goForward();
|
|
74
|
+
const code = [
|
|
75
|
+
`// Navigate forward`,
|
|
76
|
+
`await page.goForward();`,
|
|
77
|
+
];
|
|
78
|
+
return {
|
|
79
|
+
code,
|
|
80
|
+
captureSnapshot,
|
|
81
|
+
waitForNetwork: false,
|
|
82
|
+
};
|
|
85
83
|
},
|
|
86
84
|
});
|
|
87
85
|
exports.default = (captureSnapshot) => [
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Microsoft Corporation.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
const zod_1 = require("zod");
|
|
19
|
+
const tool_1 = require("./tool");
|
|
20
|
+
const requests = (0, tool_1.defineTool)({
|
|
21
|
+
capability: 'core',
|
|
22
|
+
schema: {
|
|
23
|
+
name: 'browser_network_requests',
|
|
24
|
+
description: 'Returns all network requests since loading the page',
|
|
25
|
+
inputSchema: zod_1.z.object({}),
|
|
26
|
+
},
|
|
27
|
+
handle: async (context) => {
|
|
28
|
+
const requests = context.currentTabOrDie().requests();
|
|
29
|
+
const log = [...requests.entries()].map(([request, response]) => renderRequest(request, response)).join('\n');
|
|
30
|
+
return {
|
|
31
|
+
code: [`// <internal code to list network requests>`],
|
|
32
|
+
action: async () => {
|
|
33
|
+
return {
|
|
34
|
+
content: [{ type: 'text', text: log }]
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
captureSnapshot: false,
|
|
38
|
+
waitForNetwork: false,
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
function renderRequest(request, response) {
|
|
43
|
+
const result = [];
|
|
44
|
+
result.push(`[${request.method().toUpperCase()}] ${request.url()}`);
|
|
45
|
+
if (response)
|
|
46
|
+
result.push(`=> [${response.status()}] ${response.statusText()}`);
|
|
47
|
+
return result.join(' ');
|
|
48
|
+
}
|
|
49
|
+
exports.default = [
|
|
50
|
+
requests,
|
|
51
|
+
];
|
package/lib/tools/pdf.js
CHANGED
|
@@ -14,6 +14,39 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
20
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
21
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
22
|
+
}
|
|
23
|
+
Object.defineProperty(o, k2, desc);
|
|
24
|
+
}) : (function(o, m, k, k2) {
|
|
25
|
+
if (k2 === undefined) k2 = k;
|
|
26
|
+
o[k2] = m[k];
|
|
27
|
+
}));
|
|
28
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
29
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
+
}) : function(o, v) {
|
|
31
|
+
o["default"] = v;
|
|
32
|
+
});
|
|
33
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
34
|
+
var ownKeys = function(o) {
|
|
35
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
36
|
+
var ar = [];
|
|
37
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
38
|
+
return ar;
|
|
39
|
+
};
|
|
40
|
+
return ownKeys(o);
|
|
41
|
+
};
|
|
42
|
+
return function (mod) {
|
|
43
|
+
if (mod && mod.__esModule) return mod;
|
|
44
|
+
var result = {};
|
|
45
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
46
|
+
__setModuleDefault(result, mod);
|
|
47
|
+
return result;
|
|
48
|
+
};
|
|
49
|
+
})();
|
|
17
50
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
51
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
52
|
};
|
|
@@ -21,28 +54,31 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
21
54
|
const os_1 = __importDefault(require("os"));
|
|
22
55
|
const path_1 = __importDefault(require("path"));
|
|
23
56
|
const zod_1 = require("zod");
|
|
24
|
-
const
|
|
57
|
+
const tool_1 = require("./tool");
|
|
25
58
|
const utils_1 = require("./utils");
|
|
26
|
-
const
|
|
27
|
-
const pdf = {
|
|
59
|
+
const javascript = __importStar(require("../javascript"));
|
|
60
|
+
const pdf = (0, tool_1.defineTool)({
|
|
28
61
|
capability: 'pdf',
|
|
29
62
|
schema: {
|
|
30
63
|
name: 'browser_pdf_save',
|
|
31
64
|
description: 'Save page as PDF',
|
|
32
|
-
inputSchema:
|
|
65
|
+
inputSchema: zod_1.z.object({}),
|
|
33
66
|
},
|
|
34
67
|
handle: async (context) => {
|
|
35
|
-
const tab = context.
|
|
68
|
+
const tab = context.currentTabOrDie();
|
|
36
69
|
const fileName = path_1.default.join(os_1.default.tmpdir(), (0, utils_1.sanitizeForFilePath)(`page-${new Date().toISOString()}`)) + '.pdf';
|
|
37
|
-
|
|
70
|
+
const code = [
|
|
71
|
+
`// Save page as ${fileName}`,
|
|
72
|
+
`await page.pdf(${javascript.formatObject({ path: fileName })});`,
|
|
73
|
+
];
|
|
38
74
|
return {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
75
|
+
code,
|
|
76
|
+
action: async () => tab.page.pdf({ path: fileName }).then(() => { }),
|
|
77
|
+
captureSnapshot: false,
|
|
78
|
+
waitForNetwork: false,
|
|
43
79
|
};
|
|
44
80
|
},
|
|
45
|
-
};
|
|
81
|
+
});
|
|
46
82
|
exports.default = [
|
|
47
83
|
pdf,
|
|
48
84
|
];
|