@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/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 { tools: tools.map(tool => tool.schema) };
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
- const result = await tool.handle(context, request.params.arguments);
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
  }
@@ -16,74 +16,70 @@
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  const zod_1 = require("zod");
19
- const zod_to_json_schema_1 = require("zod-to-json-schema");
20
- const waitSchema = zod_1.z.object({
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: (0, zod_to_json_schema_1.zodToJsonSchema)(waitSchema),
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
- const validatedParams = waitSchema.parse(params);
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
- content: [{
35
- type: 'text',
36
- text: `Waited for ${validatedParams.time} seconds`,
37
- }],
32
+ code: [`// Waited for ${params.time} seconds`],
33
+ captureSnapshot,
34
+ waitForNetwork: false,
38
35
  };
39
36
  },
40
- };
41
- const closeSchema = zod_1.z.object({});
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: (0, zod_to_json_schema_1.zodToJsonSchema)(closeSchema),
43
+ inputSchema: zod_1.z.object({}),
48
44
  },
49
45
  handle: async (context) => {
50
46
  await context.close();
51
47
  return {
52
- content: [{
53
- type: 'text',
54
- text: `Page closed`,
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: (0, zod_to_json_schema_1.zodToJsonSchema)(resizeSchema),
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 validatedParams = resizeSchema.parse(params);
72
- const tab = context.currentTab();
73
- return await tab.run(async (tab) => {
74
- await tab.page.setViewportSize({ width: validatedParams.width, height: validatedParams.height });
75
- const code = [
76
- `// Resize browser window to ${validatedParams.width}x${validatedParams.height}`,
77
- `await page.setViewportSize({ width: ${validatedParams.width}, height: ${validatedParams.height} });`
78
- ];
79
- return { code };
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
- exports.console = void 0;
19
- exports.console = {
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
- uri: 'browser://console',
22
- name: 'Page console',
23
- mimeType: 'text/plain',
23
+ name: 'browser_console_messages',
24
+ description: 'Returns all console messages',
25
+ inputSchema: zod_1.z.object({}),
24
26
  },
25
- read: async (context, uri) => {
26
- const messages = await context.currentTab().console();
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
- uri,
30
- mimeType: 'text/plain',
31
- text: log
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
+ ];
@@ -16,31 +16,35 @@
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  const zod_1 = require("zod");
19
- const zod_to_json_schema_1 = require("zod-to-json-schema");
20
- const uploadFileSchema = zod_1.z.object({
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: (0, zod_to_json_schema_1.zodToJsonSchema)(uploadFileSchema),
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
- const tab = context.currentTab();
33
- return await tab.runAndWait(async () => {
34
- await tab.submitFileChooser(validatedParams.paths);
35
- const code = [
36
- `// <internal code to chose files ${validatedParams.paths.join(', ')}`,
37
- ];
38
- return { code };
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
- noClearFileChooser: true,
42
- });
44
+ waitForNetwork: true,
45
+ };
43
46
  },
47
+ clearsModalState: 'fileChooser',
44
48
  });
45
49
  exports.default = (captureSnapshot) => [
46
50
  uploadFile(captureSnapshot),
@@ -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 zod_to_json_schema_1 = require("zod-to-json-schema");
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: (0, zod_to_json_schema_1.zodToJsonSchema)(zod_1.z.object({})),
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
- content: [{
51
- type: 'text',
52
- text: `Browser ${channel} installed`,
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
  ];
@@ -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 zod_to_json_schema_1 = __importDefault(require("zod-to-json-schema"));
23
- const pressKeySchema = zod_1.z.object({
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: (0, zod_to_json_schema_1.default)(pressKeySchema),
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
- return await context.currentTab().runAndWait(async (tab) => {
36
- await tab.page.keyboard.press(validatedParams.key);
37
- const code = [
38
- `// Press ${validatedParams.key}`,
39
- `await page.keyboard.press('${validatedParams.key}');`,
40
- ];
41
- return { code };
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) => [
@@ -16,72 +16,70 @@
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  const zod_1 = require("zod");
19
- const zod_to_json_schema_1 = require("zod-to-json-schema");
20
- const navigateSchema = zod_1.z.object({
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: (0, zod_to_json_schema_1.zodToJsonSchema)(navigateSchema),
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
- const currentTab = await context.ensureTab();
33
- return await currentTab.run(async (tab) => {
34
- await tab.navigate(validatedParams.url);
35
- const code = [
36
- `// Navigate to ${validatedParams.url}`,
37
- `await page.goto('${validatedParams.url}');`,
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 goBackSchema = zod_1.z.object({});
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: (0, zod_to_json_schema_1.zodToJsonSchema)(goBackSchema),
48
+ inputSchema: zod_1.z.object({}),
52
49
  },
53
50
  handle: async (context) => {
54
- return await context.currentTab().runAndWait(async (tab) => {
55
- await tab.page.goBack();
56
- const code = [
57
- `// Navigate back`,
58
- `await page.goBack();`,
59
- ];
60
- return { code };
61
- }, {
62
- captureSnapshot: snapshot,
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 goForwardSchema = zod_1.z.object({});
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: (0, zod_to_json_schema_1.zodToJsonSchema)(goForwardSchema),
69
+ inputSchema: zod_1.z.object({}),
73
70
  },
74
71
  handle: async (context) => {
75
- return await context.currentTab().runAndWait(async (tab) => {
76
- await tab.page.goForward();
77
- const code = [
78
- `// Navigate forward`,
79
- `await page.goForward();`,
80
- ];
81
- return { code };
82
- }, {
83
- captureSnapshot: snapshot,
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 zod_to_json_schema_1 = require("zod-to-json-schema");
57
+ const tool_1 = require("./tool");
25
58
  const utils_1 = require("./utils");
26
- const pdfSchema = zod_1.z.object({});
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: (0, zod_to_json_schema_1.zodToJsonSchema)(pdfSchema),
65
+ inputSchema: zod_1.z.object({}),
33
66
  },
34
67
  handle: async (context) => {
35
- const tab = context.currentTab();
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
- await tab.page.pdf({ path: fileName });
70
+ const code = [
71
+ `// Save page as ${fileName}`,
72
+ `await page.pdf(${javascript.formatObject({ path: fileName })});`,
73
+ ];
38
74
  return {
39
- content: [{
40
- type: 'text',
41
- text: `Saved as ${fileName}`,
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
  ];