Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

2.7 KB
Raw Blame
/**
 * 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 common from './common';
import config from './config';
import console from './console';
import cookies from './cookies';
import devtools from './devtools';
import dialogs from './dialogs';
import emulation from './emulation';
import evaluate from './evaluate';
import files from './files';
import find from './find';
import form from './form';
import keyboard from './keyboard';
import mouse from './mouse';
import navigate from './navigate';
import network from './network';
import pdf from './pdf';
import recorder from './recorder';
import route from './route';
import runCode from './runCode';
import snapshot from './snapshot';
import screenshot from './screenshot';
import storage from './storage';
import tabs from './tabs';
import tracing from './tracing';
import verify from './verify';
import video from './video';
import wait from './wait';
import webmcp from './webmcp';
import webstorage from './webstorage';

import type { Tool } from './tool';
import type { ContextConfig } from './context';

export const browserTools: Tool<any>[] = [
  ...common,
  ...config,
  ...console,
  ...cookies,
  ...devtools,
  ...dialogs,
  ...emulation,
  ...evaluate,
  ...files,
  ...find,
  ...form,
  ...keyboard,
  ...mouse,
  ...navigate,
  ...network,
  ...pdf,
  ...recorder,
  ...route,
  ...runCode,
  ...screenshot,
  ...snapshot,
  ...storage,
  ...tabs,
  ...tracing,
  ...verify,
  ...video,
  ...wait,
  ...webmcp,
  ...webstorage,
];

export function filteredTools(config: Pick<ContextConfig, 'capabilities'>) {
  return browserTools.filter(tool => tool.capability.startsWith('core') || config.capabilities?.includes(tool.capability)).filter(tool => !tool.skillOnly).map(tool => ({
    ...tool,
    schema: {
      ...tool.schema,
      // Note: we first ensure that "selector" property is present, so that we can omit() it without an error.
      inputSchema: tool.schema.inputSchema
          .extend({ selector: z.string(), startSelector: z.string(), endSelector: z.string() })
          .omit({ selector: true, startSelector: true, endSelector: true }),
    },
  }));
}