Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
/**
* 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 * as z from 'zod';
import { defineTool } from './tool';
import { renderTabsMarkdown } from './response';
const browserTabs = defineTool({
capability: 'core-tabs',
schema: {
name: 'browser_tabs',
title: 'Manage tabs',
description: 'List, create, close, or select a browser tab.',
inputSchema: z.object({
action: z.enum(['list', 'new', 'close', 'select']).describe('Operation to perform'),
index: z.number().optional().describe('Tab index, used for close/select. If omitted for close, current tab is closed.'),
url: z.string().optional().describe('URL to navigate to in the new tab, used for new.'),
isolatedContext: z.string().optional().describe('Name of an isolated browser context to create the new tab in, used for new. Tabs in the same isolated context share cookies and storage, tabs in different contexts are fully isolated. If omitted or "default", the tab is created in the default context.'),
}),
type: 'action',
},
handle: async (context, params, response) => {
switch (params.action) {
case 'list': {
await context.ensureTab();
break;
}
case 'new': {
const tab = await context.newTab(params.isolatedContext);
if (params.url) {
const url = await tab.checkUrlAndNavigate(params.url);
response.setIncludeSnapshot();
response.addAction({ name: 'navigate', url });
}
break;
}
case 'close': {
await context.closeTab(params.index);
break;
}
case 'select': {
if (params.index === undefined)
throw new Error('Tab index is required');
await context.selectTab(params.index);
break;
}
}
const tabHeaders = await Promise.all(context.tabs().map(tab => tab.headerSnapshot()));
const result = renderTabsMarkdown(tabHeaders);
response.addTextResult(result.join('\n'));
},
});
export default [
browserTabs,
];