@playwright/mcp 0.0.14 → 0.0.16
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 +124 -65
- package/config.d.ts +113 -0
- package/index.d.ts +2 -39
- package/lib/config.js +157 -0
- package/lib/context.js +35 -154
- package/lib/index.js +7 -59
- package/lib/pageSnapshot.js +96 -0
- package/lib/program.js +12 -85
- package/lib/server.js +22 -36
- package/lib/tab.js +81 -0
- package/lib/tools/common.js +17 -22
- package/lib/tools/console.js +5 -6
- package/lib/tools/dialogs.js +8 -10
- package/lib/tools/files.js +7 -9
- package/lib/tools/install.js +5 -5
- package/lib/tools/keyboard.js +8 -13
- package/lib/tools/navigate.js +12 -16
- package/lib/tools/network.js +51 -0
- package/lib/tools/pdf.js +6 -12
- package/lib/tools/screen.js +45 -53
- package/lib/tools/snapshot.js +64 -72
- package/lib/tools/tabs.js +21 -27
- package/lib/tools/tool.js +4 -0
- package/lib/transport.js +124 -0
- package/package.json +5 -5
package/lib/tab.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Microsoft Corporation.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.Tab = void 0;
|
|
19
|
+
const pageSnapshot_1 = require("./pageSnapshot");
|
|
20
|
+
class Tab {
|
|
21
|
+
context;
|
|
22
|
+
page;
|
|
23
|
+
_console = [];
|
|
24
|
+
_requests = new Map();
|
|
25
|
+
_snapshot;
|
|
26
|
+
_onPageClose;
|
|
27
|
+
constructor(context, page, onPageClose) {
|
|
28
|
+
this.context = context;
|
|
29
|
+
this.page = page;
|
|
30
|
+
this._onPageClose = onPageClose;
|
|
31
|
+
page.on('console', event => this._console.push(event));
|
|
32
|
+
page.on('request', request => this._requests.set(request, null));
|
|
33
|
+
page.on('response', response => this._requests.set(response.request(), response));
|
|
34
|
+
page.on('framenavigated', frame => {
|
|
35
|
+
if (!frame.parentFrame())
|
|
36
|
+
this._clearCollectedArtifacts();
|
|
37
|
+
});
|
|
38
|
+
page.on('close', () => this._onClose());
|
|
39
|
+
page.on('filechooser', chooser => {
|
|
40
|
+
this.context.setModalState({
|
|
41
|
+
type: 'fileChooser',
|
|
42
|
+
description: 'File chooser',
|
|
43
|
+
fileChooser: chooser,
|
|
44
|
+
}, this);
|
|
45
|
+
});
|
|
46
|
+
page.on('dialog', dialog => this.context.dialogShown(this, dialog));
|
|
47
|
+
page.setDefaultNavigationTimeout(60000);
|
|
48
|
+
page.setDefaultTimeout(5000);
|
|
49
|
+
}
|
|
50
|
+
_clearCollectedArtifacts() {
|
|
51
|
+
this._console.length = 0;
|
|
52
|
+
this._requests.clear();
|
|
53
|
+
}
|
|
54
|
+
_onClose() {
|
|
55
|
+
this._clearCollectedArtifacts();
|
|
56
|
+
this._onPageClose(this);
|
|
57
|
+
}
|
|
58
|
+
async navigate(url) {
|
|
59
|
+
await this.page.goto(url, { waitUntil: 'domcontentloaded' });
|
|
60
|
+
// Cap load event to 5 seconds, the page is operational at this point.
|
|
61
|
+
await this.page.waitForLoadState('load', { timeout: 5000 }).catch(() => { });
|
|
62
|
+
}
|
|
63
|
+
hasSnapshot() {
|
|
64
|
+
return !!this._snapshot;
|
|
65
|
+
}
|
|
66
|
+
snapshotOrDie() {
|
|
67
|
+
if (!this._snapshot)
|
|
68
|
+
throw new Error('No snapshot available');
|
|
69
|
+
return this._snapshot;
|
|
70
|
+
}
|
|
71
|
+
console() {
|
|
72
|
+
return this._console;
|
|
73
|
+
}
|
|
74
|
+
requests() {
|
|
75
|
+
return this._requests;
|
|
76
|
+
}
|
|
77
|
+
async captureSnapshot() {
|
|
78
|
+
this._snapshot = await pageSnapshot_1.PageSnapshot.create(this.page);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.Tab = Tab;
|
package/lib/tools/common.js
CHANGED
|
@@ -16,34 +16,31 @@
|
|
|
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 = captureSnapshot => ({
|
|
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
|
-
code: [`// Waited for ${
|
|
32
|
+
code: [`// Waited for ${params.time} seconds`],
|
|
35
33
|
captureSnapshot,
|
|
36
34
|
waitForNetwork: false,
|
|
37
35
|
};
|
|
38
36
|
},
|
|
39
37
|
});
|
|
40
|
-
const
|
|
41
|
-
const close = {
|
|
38
|
+
const close = (0, tool_1.defineTool)({
|
|
42
39
|
capability: 'core',
|
|
43
40
|
schema: {
|
|
44
41
|
name: 'browser_close',
|
|
45
42
|
description: 'Close the page',
|
|
46
|
-
inputSchema:
|
|
43
|
+
inputSchema: zod_1.z.object({}),
|
|
47
44
|
},
|
|
48
45
|
handle: async (context) => {
|
|
49
46
|
await context.close();
|
|
@@ -53,27 +50,25 @@ const close = {
|
|
|
53
50
|
waitForNetwork: false,
|
|
54
51
|
};
|
|
55
52
|
},
|
|
56
|
-
};
|
|
57
|
-
const resizeSchema = zod_1.z.object({
|
|
58
|
-
width: zod_1.z.number().describe('Width of the browser window'),
|
|
59
|
-
height: zod_1.z.number().describe('Height of the browser window'),
|
|
60
53
|
});
|
|
61
|
-
const resize = captureSnapshot => ({
|
|
54
|
+
const resize = captureSnapshot => (0, tool_1.defineTool)({
|
|
62
55
|
capability: 'core',
|
|
63
56
|
schema: {
|
|
64
57
|
name: 'browser_resize',
|
|
65
58
|
description: 'Resize the browser window',
|
|
66
|
-
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
|
+
}),
|
|
67
63
|
},
|
|
68
64
|
handle: async (context, params) => {
|
|
69
|
-
const validatedParams = resizeSchema.parse(params);
|
|
70
65
|
const tab = context.currentTabOrDie();
|
|
71
66
|
const code = [
|
|
72
|
-
`// Resize browser window to ${
|
|
73
|
-
`await page.setViewportSize({ width: ${
|
|
67
|
+
`// Resize browser window to ${params.width}x${params.height}`,
|
|
68
|
+
`await page.setViewportSize({ width: ${params.width}, height: ${params.height} });`
|
|
74
69
|
];
|
|
75
70
|
const action = async () => {
|
|
76
|
-
await tab.page.setViewportSize({ width:
|
|
71
|
+
await tab.page.setViewportSize({ width: params.width, height: params.height });
|
|
77
72
|
};
|
|
78
73
|
return {
|
|
79
74
|
code,
|
package/lib/tools/console.js
CHANGED
|
@@ -16,17 +16,16 @@
|
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
const zod_1 = require("zod");
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const console = {
|
|
19
|
+
const tool_1 = require("./tool");
|
|
20
|
+
const console = (0, tool_1.defineTool)({
|
|
22
21
|
capability: 'core',
|
|
23
22
|
schema: {
|
|
24
23
|
name: 'browser_console_messages',
|
|
25
24
|
description: 'Returns all console messages',
|
|
26
|
-
inputSchema:
|
|
25
|
+
inputSchema: zod_1.z.object({}),
|
|
27
26
|
},
|
|
28
27
|
handle: async (context) => {
|
|
29
|
-
const messages =
|
|
28
|
+
const messages = context.currentTabOrDie().console();
|
|
30
29
|
const log = messages.map(message => `[${message.type().toUpperCase()}] ${message.text()}`).join('\n');
|
|
31
30
|
return {
|
|
32
31
|
code: [`// <internal code to get console messages>`],
|
|
@@ -39,7 +38,7 @@ const console = {
|
|
|
39
38
|
waitForNetwork: false,
|
|
40
39
|
};
|
|
41
40
|
},
|
|
42
|
-
};
|
|
41
|
+
});
|
|
43
42
|
exports.default = [
|
|
44
43
|
console,
|
|
45
44
|
];
|
package/lib/tools/dialogs.js
CHANGED
|
@@ -16,25 +16,23 @@
|
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
const zod_1 = require("zod");
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
accept: zod_1.z.boolean().describe('Whether to accept the dialog.'),
|
|
22
|
-
promptText: zod_1.z.string().optional().describe('The text of the prompt in case of a prompt dialog.'),
|
|
23
|
-
});
|
|
24
|
-
const handleDialog = captureSnapshot => ({
|
|
19
|
+
const tool_1 = require("./tool");
|
|
20
|
+
const handleDialog = captureSnapshot => (0, tool_1.defineTool)({
|
|
25
21
|
capability: 'core',
|
|
26
22
|
schema: {
|
|
27
23
|
name: 'browser_handle_dialog',
|
|
28
24
|
description: 'Handle a dialog',
|
|
29
|
-
inputSchema:
|
|
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
|
+
}),
|
|
30
29
|
},
|
|
31
30
|
handle: async (context, params) => {
|
|
32
|
-
const validatedParams = handleDialogSchema.parse(params);
|
|
33
31
|
const dialogState = context.modalStates().find(state => state.type === 'dialog');
|
|
34
32
|
if (!dialogState)
|
|
35
33
|
throw new Error('No dialog visible');
|
|
36
|
-
if (
|
|
37
|
-
await dialogState.dialog.accept(
|
|
34
|
+
if (params.accept)
|
|
35
|
+
await dialogState.dialog.accept(params.promptText);
|
|
38
36
|
else
|
|
39
37
|
await dialogState.dialog.dismiss();
|
|
40
38
|
context.clearModalState(dialogState);
|
package/lib/tools/files.js
CHANGED
|
@@ -16,27 +16,25 @@
|
|
|
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 validatedParams = uploadFileSchema.parse(params);
|
|
32
30
|
const modalState = context.modalStates().find(state => state.type === 'fileChooser');
|
|
33
31
|
if (!modalState)
|
|
34
32
|
throw new Error('No file chooser visible');
|
|
35
33
|
const code = [
|
|
36
|
-
`// <internal code to chose files ${
|
|
34
|
+
`// <internal code to chose files ${params.paths.join(', ')}`,
|
|
37
35
|
];
|
|
38
36
|
const action = async () => {
|
|
39
|
-
await modalState.fileChooser.setFiles(
|
|
37
|
+
await modalState.fileChooser.setFiles(params.paths);
|
|
40
38
|
context.clearModalState(modalState);
|
|
41
39
|
};
|
|
42
40
|
return {
|
package/lib/tools/install.js
CHANGED
|
@@ -21,16 +21,16 @@ 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
|
-
const channel = context.
|
|
33
|
+
const channel = context.config.browser?.launchOptions?.channel ?? context.config.browser?.launchOptions.browserName ?? 'chrome';
|
|
34
34
|
const cli = path_1.default.join(require.resolve('playwright/package.json'), '..', 'cli.js');
|
|
35
35
|
const child = (0, child_process_1.fork)(cli, ['install', channel], {
|
|
36
36
|
stdio: 'pipe',
|
|
@@ -52,7 +52,7 @@ const install = {
|
|
|
52
52
|
waitForNetwork: false,
|
|
53
53
|
};
|
|
54
54
|
},
|
|
55
|
-
};
|
|
55
|
+
});
|
|
56
56
|
exports.default = [
|
|
57
57
|
install,
|
|
58
58
|
];
|
package/lib/tools/keyboard.js
CHANGED
|
@@ -14,30 +14,25 @@
|
|
|
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 validatedParams = pressKeySchema.parse(params);
|
|
35
30
|
const tab = context.currentTabOrDie();
|
|
36
31
|
const code = [
|
|
37
|
-
`// Press ${
|
|
38
|
-
`await page.keyboard.press('${
|
|
32
|
+
`// Press ${params.key}`,
|
|
33
|
+
`await page.keyboard.press('${params.key}');`,
|
|
39
34
|
];
|
|
40
|
-
const action = () => tab.page.keyboard.press(
|
|
35
|
+
const action = () => tab.page.keyboard.press(params.key);
|
|
41
36
|
return {
|
|
42
37
|
code,
|
|
43
38
|
action,
|
package/lib/tools/navigate.js
CHANGED
|
@@ -16,24 +16,22 @@
|
|
|
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 validatedParams = navigateSchema.parse(params);
|
|
32
30
|
const tab = await context.ensureTab();
|
|
33
|
-
await tab.navigate(
|
|
31
|
+
await tab.navigate(params.url);
|
|
34
32
|
const code = [
|
|
35
|
-
`// Navigate to ${
|
|
36
|
-
`await page.goto('${
|
|
33
|
+
`// Navigate to ${params.url}`,
|
|
34
|
+
`await page.goto('${params.url}');`,
|
|
37
35
|
];
|
|
38
36
|
return {
|
|
39
37
|
code,
|
|
@@ -42,13 +40,12 @@ const navigate = captureSnapshot => ({
|
|
|
42
40
|
};
|
|
43
41
|
},
|
|
44
42
|
});
|
|
45
|
-
const
|
|
46
|
-
const goBack = captureSnapshot => ({
|
|
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
51
|
const tab = await context.ensureTab();
|
|
@@ -64,13 +61,12 @@ const goBack = captureSnapshot => ({
|
|
|
64
61
|
};
|
|
65
62
|
},
|
|
66
63
|
});
|
|
67
|
-
const
|
|
68
|
-
const goForward = captureSnapshot => ({
|
|
64
|
+
const goForward = captureSnapshot => (0, tool_1.defineTool)({
|
|
69
65
|
capability: 'history',
|
|
70
66
|
schema: {
|
|
71
67
|
name: 'browser_navigate_forward',
|
|
72
68
|
description: 'Go forward to the next page',
|
|
73
|
-
inputSchema:
|
|
69
|
+
inputSchema: zod_1.z.object({}),
|
|
74
70
|
},
|
|
75
71
|
handle: async (context) => {
|
|
76
72
|
const tab = context.currentTabOrDie();
|
|
@@ -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
|
@@ -47,27 +47,21 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
47
47
|
return result;
|
|
48
48
|
};
|
|
49
49
|
})();
|
|
50
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
51
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
52
|
-
};
|
|
53
50
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
-
const os_1 = __importDefault(require("os"));
|
|
55
|
-
const path_1 = __importDefault(require("path"));
|
|
56
51
|
const zod_1 = require("zod");
|
|
57
|
-
const
|
|
58
|
-
const utils_1 = require("./utils");
|
|
52
|
+
const tool_1 = require("./tool");
|
|
59
53
|
const javascript = __importStar(require("../javascript"));
|
|
60
|
-
const
|
|
61
|
-
const pdf = {
|
|
54
|
+
const config_1 = require("../config");
|
|
55
|
+
const pdf = (0, tool_1.defineTool)({
|
|
62
56
|
capability: 'pdf',
|
|
63
57
|
schema: {
|
|
64
58
|
name: 'browser_pdf_save',
|
|
65
59
|
description: 'Save page as PDF',
|
|
66
|
-
inputSchema:
|
|
60
|
+
inputSchema: zod_1.z.object({}),
|
|
67
61
|
},
|
|
68
62
|
handle: async (context) => {
|
|
69
63
|
const tab = context.currentTabOrDie();
|
|
70
|
-
const fileName =
|
|
64
|
+
const fileName = await (0, config_1.outputFile)(context.config, `page-${new Date().toISOString()}'.pdf'`);
|
|
71
65
|
const code = [
|
|
72
66
|
`// Save page as ${fileName}`,
|
|
73
67
|
`await page.pdf(${javascript.formatObject({ path: fileName })});`,
|
|
@@ -79,7 +73,7 @@ const pdf = {
|
|
|
79
73
|
waitForNetwork: false,
|
|
80
74
|
};
|
|
81
75
|
},
|
|
82
|
-
};
|
|
76
|
+
});
|
|
83
77
|
exports.default = [
|
|
84
78
|
pdf,
|
|
85
79
|
];
|