2025-03-21 10:58:58 -07:00
|
|
|
/**
|
|
|
|
|
* Copyright (c) Microsoft Corporation.
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import { z } from 'zod';
|
2025-07-22 07:53:33 -07:00
|
|
|
import { defineTabTool, defineTool } from './tool.js';
|
2025-03-21 10:58:58 -07:00
|
|
|
|
2025-04-22 13:24:38 +02:00
|
|
|
const close = defineTool({
|
2025-04-04 17:14:30 -07:00
|
|
|
capability: 'core',
|
2025-04-16 19:36:48 -07:00
|
|
|
|
2025-03-21 10:58:58 -07:00
|
|
|
schema: {
|
|
|
|
|
name: 'browser_close',
|
2025-05-05 17:38:22 -07:00
|
|
|
title: 'Close browser',
|
2025-03-21 10:58:58 -07:00
|
|
|
description: 'Close the page',
|
2025-04-22 13:24:38 +02:00
|
|
|
inputSchema: z.object({}),
|
2025-05-05 17:38:22 -07:00
|
|
|
type: 'readOnly',
|
2025-03-21 10:58:58 -07:00
|
|
|
},
|
2025-04-16 19:36:48 -07:00
|
|
|
|
2025-07-22 16:36:21 -07:00
|
|
|
handle: async (context, params, response) => {
|
2025-07-23 17:41:15 -07:00
|
|
|
await context.closeBrowserContext();
|
2025-07-22 16:36:21 -07:00
|
|
|
response.setIncludeTabs();
|
|
|
|
|
response.addCode(`await page.close()`);
|
2025-03-21 10:58:58 -07:00
|
|
|
},
|
2025-04-15 01:09:48 +02:00
|
|
|
});
|
|
|
|
|
|
2025-07-22 07:53:33 -07:00
|
|
|
const resize = defineTabTool({
|
2025-04-15 01:09:48 +02:00
|
|
|
capability: 'core',
|
|
|
|
|
schema: {
|
|
|
|
|
name: 'browser_resize',
|
2025-05-05 17:38:22 -07:00
|
|
|
title: 'Resize browser window',
|
2025-04-15 01:09:48 +02:00
|
|
|
description: 'Resize the browser window',
|
2025-04-22 13:24:38 +02:00
|
|
|
inputSchema: z.object({
|
|
|
|
|
width: z.number().describe('Width of the browser window'),
|
|
|
|
|
height: z.number().describe('Height of the browser window'),
|
|
|
|
|
}),
|
2025-05-05 17:38:22 -07:00
|
|
|
type: 'readOnly',
|
2025-04-15 01:09:48 +02:00
|
|
|
},
|
2025-04-16 19:36:48 -07:00
|
|
|
|
2025-07-22 16:36:21 -07:00
|
|
|
handle: async (tab, params, response) => {
|
|
|
|
|
response.addCode(`// Resize browser window to ${params.width}x${params.height}`);
|
|
|
|
|
response.addCode(`await page.setViewportSize({ width: ${params.width}, height: ${params.height} });`);
|
2025-04-16 19:36:48 -07:00
|
|
|
|
2025-07-22 17:43:42 -07:00
|
|
|
await tab.waitForCompletion(async () => {
|
2025-04-22 13:24:38 +02:00
|
|
|
await tab.page.setViewportSize({ width: params.width, height: params.height });
|
2025-07-22 17:43:42 -07:00
|
|
|
});
|
2025-04-15 01:09:48 +02:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2025-07-16 16:40:00 -07:00
|
|
|
export default [
|
2025-04-04 15:22:00 -07:00
|
|
|
close,
|
2025-07-16 16:40:00 -07:00
|
|
|
resize
|
2025-04-04 15:22:00 -07:00
|
|
|
];
|