/** * 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 type * as playwright from 'playwright'; export type ToolCapability = | 'core' | 'tabs' | 'pdf' | 'history' | 'wait' | 'files' | 'install' | 'testing' | 'core-install' // Deprecated alias for 'install'; requires explicit opt-in. | 'core-tabs' | 'devtools' | 'vision' | 'verify'; export type Config = { /** * The browser to use. */ browser?: { /** * Use browser agent (experimental). */ browserAgent?: string; /** * The type of browser to use. */ browserName?: 'chromium' | 'firefox' | 'webkit'; /** * Keep the browser profile in memory, do not save it to disk. */ isolated?: boolean; /** * Path to a user data directory for browser profile persistence. * Temporary directory is created by default. */ userDataDir?: string; /** * Chrome profile directory name used in extension mode (for example * "Default" or "Profile 1"); defaults to the last-used profile that * has the extension installed. */ profileDirName?: string; /** * Launch options passed to * @see https://playwright.dev/docs/api/class-browsertype#browser-type-launch-persistent-context * * This is useful for settings options like `channel`, `headless`, `executablePath`, etc. */ launchOptions?: playwright.LaunchOptions; /** * Context options for the browser context. * * This is useful for settings options like `viewport`. */ contextOptions?: playwright.BrowserContextOptions; /** * Chrome DevTools Protocol endpoint to connect to an existing browser instance in case of Chromium family browsers. */ cdpEndpoint?: string; /** * Additional HTTP headers to send with the CDP connect request. Useful for * endpoints that require header-based authentication (for example * `{ "Authorization": "Bearer " }`). */ cdpHeaders?: Record; /** * Timeout in milliseconds for connecting to the CDP endpoint. Defaults to 30000 (30 seconds). */ cdpTimeout?: number; /** * Launch a Chromium-based desktop app with CDP enabled and attach to it. */ cdpLaunch?: { command: string; args?: string[]; cwd?: string; env?: Record; port?: number; startupTimeoutMs?: number; }; /** * Remote endpoint to connect to an existing Playwright server. */ remoteEndpoint?: string; /** * Directories that browser_file_upload and browser_drop may read files from. * When unset (default), any absolute path is allowed; when set, upload * canonical file paths must stay inside these directories. Restricted * uploads accept regular files up to 50 MiB total per call. [] denies all; * non-empty lists require macOS or Linux with /proc/self/fd available. * Roots must exist and are canonicalized once at startup. null is invalid. * blank entries are invalid. Also PLAYWRIGHT_MCP_ALLOWED_UPLOAD_DIRS or * --allowed-upload-dirs (semicolon-separated; empty string means []). */ allowedUploadDirs?: string[]; }, server?: { /** * The port to listen on for SSE or MCP transport. */ port?: number; /** * The host to bind the server to. Default is localhost. Use 0.0.0.0 to bind to all interfaces. */ host?: string; /** * When set, HTTP transport requests must carry `Authorization: Bearer `. * Blank or malformed tokens are rejected. Requires a loopback listener; * remote access must use a TLS reverse proxy. Also configurable through * PLAYWRIGHT_MCP_AUTH_TOKEN. */ authToken?: string; }, /** * List of enabled tool capabilities. Possible values: * - 'core': Core browser automation features. * - 'tabs': Tab management features. * - 'pdf': PDF generation and manipulation. * - 'history': Browser history access. * - 'wait': Wait and timing utilities. * - 'files': File upload/download support. * - 'install': Browser installation utilities. * - 'devtools': Browser recording utilities. */ capabilities?: ToolCapability[]; /** * Run server that uses screenshots (Aria snapshots are used by default). */ vision?: boolean; /** * Whether to save the Playwright trace of the session into the output directory. */ saveTrace?: boolean; /** * Whether to persist session logs for the current run. */ saveSession?: boolean; /** * The directory to save output files. */ outputDir?: string; network?: { /** * List of origins to allow the browser to request. Default is to allow all. Origins matching both `allowedOrigins` and `blockedOrigins` will be blocked. */ allowedOrigins?: string[]; /** * List of origins to block the browser to request. Origins matching both `allowedOrigins` and `blockedOrigins` will be blocked. */ blockedOrigins?: string[]; }; /** * Image response policy. Defaults to "allow"; "auto" is a legacy alias for "allow". * "omit" excludes images. "only" omits text from successful responses containing images, * but preserves errors, browser lifecycle notices, structured content and resource links. Responses without images keep text. */ imageResponses?: 'allow' | 'omit' | 'auto' | 'only'; snapshot?: { /** * Include each element's bounding box as [box=x,y,width,height] in snapshots. * Coordinates are viewport-relative CSS pixels. */ boxes?: boolean; }; /** * Timeout settings for Playwright operations. */ timeouts?: { /** * Maximum time in milliseconds for page navigation. Defaults to 60000ms (60 seconds). */ navigationTimeout?: number; /** * Default timeout for all Playwright operations (clicks, fills, etc). Defaults to 5000ms (5 seconds). */ defaultTimeout?: number; /** * How long to wait after each action for triggered work to settle before responding. Defaults to 500ms. */ settle?: number; /** * Release the default browser context after this many idle milliseconds. Zero (the default) disables it. * Explicit browser sessions retain their separate idle TTL. */ idle?: number; }; };