From 7e8f6c708b155e17aed4b67fc1a85372d8db0f51 Mon Sep 17 00:00:00 2001 From: alok-108 <166419621+alok-108@users.noreply.github.com> Date: Sat, 21 Nov 2026 21:40:37 +0530 Subject: [PATCH] docs(readme): align configuration schema and env docs with runtime Fixes: https://github.com/microsoft/playwright-cli/issues/550 --- README.md | 158 +++++++++++++++++++++++++++++++++----- tests/integration.spec.ts | 51 ++++++++++++ 2 files changed, 188 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 8b3a377..75eb7ad 100644 --- a/README.md +++ b/README.md @@ -484,6 +484,7 @@ Playwright CLI will load config from `.playwright/cli.config.json` by default so /** * Path to a user data directory for browser profile persistence. * Temporary directory is created by default. + * Relative paths are resolved against the config file's directory. */ userDataDir?: string; @@ -492,6 +493,7 @@ Playwright CLI will load config from `.playwright/cli.config.json` by default so * @see https://playwright.dev/docs/api/class-browsertype#browser-type-launch-persistent-context * * This is useful for settings options like `channel`, `headless`, `executablePath`, etc. + * Relative paths are resolved against the config file's directory. */ launchOptions?: playwright.LaunchOptions; @@ -499,6 +501,7 @@ Playwright CLI will load config from `.playwright/cli.config.json` by default so * Context options for the browser context. * * This is useful for settings options like `viewport`. + * Relative paths are resolved against the config file's directory. */ contextOptions?: playwright.BrowserContextOptions; @@ -518,39 +521,85 @@ Playwright CLI will load config from `.playwright/cli.config.json` by default so cdpTimeout?: number; /** - * Remote endpoint to connect to an existing Playwright server. + * Remote endpoint to connect to an existing Playwright server. May be a + * WebSocket URL string, or a [ConnectOptions] object that mirrors the + * `connectOptions` shape used by the test runner. When passed as an object, + * `exposeNetwork`, `headers`, `slowMo`, and `timeout` are forwarded to the + * underlying connect call. */ - remoteEndpoint?: string; + remoteEndpoint?: string | playwright.ConnectOptions & { endpoint: string }; /** * Paths to TypeScript files to add as initialization scripts for Playwright page. + * Relative paths are resolved against the config file's directory. */ initPage?: string[]; /** * Paths to JavaScript files to add as initialization scripts. * The scripts will be evaluated in every page before any of the page's scripts. + * Relative paths are resolved against the config file's directory. */ initScript?: string[]; }, /** - * If specified, saves the Playwright video of the session into the output directory. + * Connect to a running browser instance (Edge/Chrome only). If specified, `browser` + * config is ignored. + * Requires the "Playwright Extension" to be installed. */ - saveVideo?: { - width: number; - height: number; - }; + extension?: boolean; + + /** + * Group controlled tabs when using the extension. Defaults to true. + */ + tabGroup?: boolean; + + /** + * Color of the session: blue, red, yellow, green, pink, purple, cyan or orange. With the extension, + * it is the color of the tab group for controlled tabs, which defaults to the first color that no other client uses. + */ + sessionColor?: string; + + /** + * Do not activate controlled tabs or focus the browser window when using the extension. + * Defaults to false. + */ + background?: boolean; + + /** + * Whether to collect and expose the tools that a page registers through the + * experimental WebMCP API. Enabled by default. + */ + webmcp?: boolean; + + /** + * Secrets are used to replace matching plain text in the tool responses to prevent the LLM + * from accidentally getting sensitive data. It is a convenience and not a security feature, + * make sure to always examine information coming in and from the tool on the client. + */ + secrets?: Record; /** - * The directory to save output files. + * Names of URL query and fragment parameters, for example `access_token` or `code`, whose values + * are replaced with `` in the tool responses. Use it for session and grant values that + * are minted at runtime and cannot be listed in `secrets`. Like `secrets`, it is a convenience + * and not a security feature. + */ + redactUrlParams?: string[]; + + /** + * The directory for automatically named output files, for example a screenshot taken without an + * explicit file name. Files with an explicit name are resolved against the workspace root instead + * and are not affected by this option. + * Relative paths are resolved against the config file's directory. */ outputDir?: string; /** - * Whether to save snapshots, console messages, network logs and other session logs to a file or to the standard output. Defaults to "stdout". + * Threshold for evicting old output files, in bytes. */ - outputMode?: 'file' | 'stdout'; + outputMaxSize?: number; console?: { /** @@ -562,11 +611,19 @@ Playwright CLI will load config from `.playwright/cli.config.json` by default so network?: { /** * List of origins to allow the browser to request. Default is to allow all. Origins matching both `allowedOrigins` and `blockedOrigins` will be blocked. + * + * Supported formats: + * - Full origin: `https://example.com:8080` - matches only that origin + * - Wildcard port: `http://localhost:*` - matches any port on localhost with http protocol */ allowedOrigins?: string[]; /** * List of origins to block the browser to request. Origins matching both `allowedOrigins` and `blockedOrigins` will be blocked. + * + * Supported formats: + * - Full origin: `https://example.com:8080` - matches only that origin + * - Wildcard port: `http://localhost:*` - matches any port on localhost with http protocol */ blockedOrigins?: string[]; }; @@ -586,18 +643,60 @@ Playwright CLI will load config from `.playwright/cli.config.json` by default so * Configures default navigation timeout: https://playwright.dev/docs/api/class-page#page-set-default-navigation-timeout. Defaults to 60000ms. */ navigation?: number; + + /** + * Configures default expect timeout: https://playwright.dev/docs/test-timeouts#expect-timeout. Defaults to 5000ms. + */ + expect?: number; + + /** + * How long to wait after each action for triggered work (navigations, requests) to settle before responding. Defaults to 500ms. + */ + settle?: number; + + /** + * Shut the session down after this many milliseconds without a command. + * Defaults to one hour for headless browsers, and to no timeout for headed or attached ones. Pass 0 to disable. + */ + idle?: number; }; /** - * Whether to allow file uploads from anywhere on the file system. - * By default (false), file uploads are restricted to paths within the MCP roots only. + * Whether to send image responses to the client. Can be "allow", "omit", or "only". Defaults to "allow". + */ + imageResponses?: 'allow' | 'omit' | 'only'; + + /** + * How file paths are rendered in tool results. Can be "relative" to the workspace root or "absolute". Defaults to "relative". + */ + filePaths?: 'relative' | 'absolute'; + + snapshot?: { + /** + * Whether to include each element's bounding box as [box=x,y,width,height] in snapshots. + * Coordinates are viewport-relative, in CSS pixels (Element.getBoundingClientRect). + */ + boxes?: boolean; + }; + + /** + * allowUnrestrictedFileAccess acts as a guardrail to prevent the LLM from accidentally + * wandering outside its intended workspace. It is a convenience defense to catch unintended + * file access, not a secure boundary; a deliberate attempt to reach other directories can be + * easily worked around, so always rely on client-level permissions for true security. */ allowUnrestrictedFileAccess?: boolean; + /** + * Do not ask the client for its workspace roots, use the current working directory + * as the workspace root instead. + */ + ignoreRoots?: boolean; + /** * Specify the language to use for code generation. */ - codegen?: 'typescript' | 'none'; + codegen?: 'typescript' | 'python' | 'java' | 'csharp' | 'none'; } ``` @@ -608,41 +707,58 @@ Playwright CLI will load config from `.playwright/cli.config.json` by default so | Environment | |-------------| -| `PLAYWRIGHT_MCP_ALLOWED_HOSTS` comma-separated list of hosts this server is allowed to serve from. Defaults to the host the server is bound to. Pass '*' to disable the host check. | +| `PLAYWRIGHT_MCP_ALLOWED_HOSTS` comma-separated list of hosts this server is allowed to serve from. Defaults to localhost, loopback IPs and the host passed via --host; other hosts must be listed explicitly. Pass '*' to disable the host check. | | `PLAYWRIGHT_MCP_ALLOWED_ORIGINS` semicolon-separated list of TRUSTED origins to allow the browser to request. Default is to allow all. Important: *does not* serve as a security boundary and *does not* affect redirects. | | `PLAYWRIGHT_MCP_ALLOW_UNRESTRICTED_FILE_ACCESS` allow access to files outside of the workspace roots. Also allows unrestricted access to file:// URLs. By default access to file system is restricted to workspace root directories (or cwd if no roots are configured) only, and navigation to file:// URLs is blocked. | +| `PLAYWRIGHT_MCP_BACKGROUND` do not activate controlled tabs or focus the browser window when using `--extension`. | | `PLAYWRIGHT_MCP_BLOCKED_ORIGINS` semicolon-separated list of origins to block the browser from requesting. Blocklist is evaluated before allowlist. If used without the allowlist, requests not matching the blocklist are still allowed. Important: *does not* serve as a security boundary and *does not* affect redirects. | | `PLAYWRIGHT_MCP_BLOCK_SERVICE_WORKERS` block service workers | | `PLAYWRIGHT_MCP_BROWSER` browser or chrome channel to use, possible values: chrome, firefox, webkit, msedge. | -| `PLAYWRIGHT_MCP_CAPS` comma-separated list of additional capabilities to enable, possible values: vision, pdf. | +| `PLAYWRIGHT_MCP_CAPS` comma-separated list of additional capabilities to enable, possible values: vision, pdf, devtools. | | `PLAYWRIGHT_MCP_CDP_ENDPOINT` CDP endpoint to connect to. | | `PLAYWRIGHT_MCP_CDP_HEADERS` CDP headers to send with the connect request, multiple can be specified. | -| `PLAYWRIGHT_MCP_CDP_TIMEOUT` timeout for the CDP connection. | +| `PLAYWRIGHT_MCP_CDP_TIMEOUT` timeout in milliseconds for connecting to CDP endpoint, defaults to 30000ms | +| `PLAYWRIGHT_MCP_CODEGEN` specify the language to use for code generation, possible values: "typescript", "python", "java", "csharp", "none". Default is "typescript". | | `PLAYWRIGHT_MCP_CONFIG` path to the configuration file. | | `PLAYWRIGHT_MCP_CONSOLE_LEVEL` level of console messages to return: "error", "warning", "info", "debug". Each level includes the messages of more severe levels. | | `PLAYWRIGHT_MCP_DEVICE` device to emulate, for example: "iPhone 15" | | `PLAYWRIGHT_MCP_EXECUTABLE_PATH` path to the browser executable. | -| `PLAYWRIGHT_MCP_EXTENSION` Connect to a running browser instance (Edge/Chrome only). Requires the "Playwright MCP Bridge" browser extension to be installed. | +| `PLAYWRIGHT_MCP_EXTENSION` Connect to a running browser instance (Edge/Chrome only). Requires the "Playwright Extension" to be installed. | +| `PLAYWRIGHT_MCP_EXTENSION_TOKEN` authentication token for connecting to the Playwright Extension without an interactive approval prompt. | +| `PLAYWRIGHT_MCP_FILE_PATHS` how file paths are rendered in tool results, "relative" to the workspace root or "absolute". Default is "relative". | | `PLAYWRIGHT_MCP_GRANT_PERMISSIONS` List of permissions to grant to the browser context, for example "geolocation", "clipboard-read", "clipboard-write". | | `PLAYWRIGHT_MCP_HEADLESS` whether to run browser in headless mode, headless by default. | +| `PLAYWRIGHT_MCP_HOST` host to bind server to. Default is localhost. Use 0.0.0.0 to bind to all interfaces. | +| `PLAYWRIGHT_MCP_IDLE_TIMEOUT` shut the session down after this many milliseconds without a command. Defaults to one hour for headless browsers, never for headed ones, 0 disables. | | `PLAYWRIGHT_MCP_IGNORE_HTTPS_ERRORS` ignore https errors | +| `PLAYWRIGHT_MCP_IGNORE_ROOTS` do not ask the client for its workspace roots, use the current working directory as the workspace root instead. | +| `PLAYWRIGHT_MCP_IMAGE_RESPONSES` whether to send image responses to the client. Can be "allow", "omit" or "only". Defaults to "allow". | | `PLAYWRIGHT_MCP_INIT_PAGE` path to TypeScript file to evaluate on Playwright page object | | `PLAYWRIGHT_MCP_INIT_SCRIPT` path to JavaScript file to add as an initialization script. The script will be evaluated in every page before any of the page's scripts. Can be specified multiple times. | | `PLAYWRIGHT_MCP_ISOLATED` keep the browser profile in memory, do not save it to disk. | -| `PLAYWRIGHT_MCP_SANDBOX` whether to enable the browser sandbox. | -| `PLAYWRIGHT_MCP_OUTPUT_DIR` path to the directory for output files. | +| `PLAYWRIGHT_MCP_MOBILE` emulate a generic mobile device (Pixel 10 for Chromium, iPhone 17 for WebKit). Mobile pages are usually lighter, which saves tokens. Cannot be combined with `PLAYWRIGHT_MCP_DEVICE`. | +| `PLAYWRIGHT_MCP_NO_TAB_GROUP` do not group controlled tabs when using `--extension`. | +| `PLAYWRIGHT_MCP_OUTPUT_DIR` path to the directory for automatically named output files, for example a screenshot taken without an explicit file name. Files with an explicit name are resolved against the workspace root instead and are not affected by this option. | +| `PLAYWRIGHT_MCP_OUTPUT_MAX_SIZE` Threshold for evicting old output files, in bytes. | +| `PLAYWRIGHT_MCP_PORT` port to listen on for SSE transport. | +| `PLAYWRIGHT_MCP_PROFILE_DIR_NAME` name of the profile directory in the user data dir to connect to with `--extension`, for example "Profile 1". Defaults to the last used profile that has the extension installed. | | `PLAYWRIGHT_MCP_PROXY_BYPASS` comma-separated domains to bypass proxy, for example ".com,chromium.org,.domain.com" | | `PLAYWRIGHT_MCP_PROXY_SERVER` specify proxy server, for example "http://myproxy:3128" or "socks5://myproxy:8080" | -| `PLAYWRIGHT_MCP_SAVE_TRACE` Whether to save the Playwright Trace of the session into the output directory. | -| `PLAYWRIGHT_MCP_SAVE_VIDEO` Whether to save the video of the session into the output directory. For example "--save-video=800x600" | +| `PLAYWRIGHT_MCP_REDACT_URL_PARAMS` comma-separated list of URL query and fragment parameter names, for example "access_token,code", whose values are replaced with in tool responses. | +| `PLAYWRIGHT_MCP_REMOTE_HEADERS` HTTP headers to send when connecting to a remote Playwright server, e.g. "Authorization: Bearer token". | +| `PLAYWRIGHT_MCP_SANDBOX=false` disable the sandbox for all process types that are normally sandboxed. | +| `PLAYWRIGHT_MCP_SANDBOX` enable the sandbox for all process types that are normally not sandboxed. | | `PLAYWRIGHT_MCP_SECRETS_FILE` path to a file containing secrets in the dotenv format | +| `PLAYWRIGHT_MCP_SESSION_COLOR` color of the session: blue, red, yellow, green, pink, purple, cyan or orange. With `--extension`, it is the color of the tab group for controlled tabs. | | `PLAYWRIGHT_MCP_STORAGE_STATE` path to the storage state file for isolated sessions. | | `PLAYWRIGHT_MCP_TEST_ID_ATTRIBUTE` specify the attribute to use for test ids, defaults to "data-testid" | | `PLAYWRIGHT_MCP_TIMEOUT_ACTION` specify action timeout in milliseconds, defaults to 5000ms | | `PLAYWRIGHT_MCP_TIMEOUT_NAVIGATION` specify navigation timeout in milliseconds, defaults to 60000ms | +| `PLAYWRIGHT_MCP_TIMEOUT_SETTLE` how long to wait after each action for triggered work to settle, in milliseconds, defaults to 500ms | | `PLAYWRIGHT_MCP_USER_AGENT` specify user agent string | | `PLAYWRIGHT_MCP_USER_DATA_DIR` path to the user data directory. If not specified, a temporary directory will be created. | | `PLAYWRIGHT_MCP_VIEWPORT_SIZE` specify browser viewport size in pixels, for example "1280x720" | +| `PLAYWRIGHT_MCP_WEBMCP=false` do not collect or expose the tools that a page registers through the WebMCP API. | ## Specific tasks diff --git a/tests/integration.spec.ts b/tests/integration.spec.ts index 47c1afa..f545fd1 100644 --- a/tests/integration.spec.ts +++ b/tests/integration.spec.ts @@ -271,3 +271,54 @@ test('update check does not wait for a hanging registry', async ({ npmRegistry } })); expect(Date.now() - start).toBeLessThan(10000); }); + +test('documented env vars and config schema in README are supported by runtime', { + annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright-cli/issues/550' }, +}, async () => { + const readme = fs.readFileSync(path.join(__dirname, '../README.md'), 'utf8'); + const envSectionMatch = readme.match(/Configuration via env<\/summary>([\s\S]*?)<\/details>/); + expect(envSectionMatch).toBeTruthy(); + + const documentedEnvVars = [...envSectionMatch![1].matchAll(/`(PLAYWRIGHT_MCP_[A-Z0-9_]+)(?:=[^`]+)?`/g)].map(m => m[1]); + expect(documentedEnvVars.length).toBeGreaterThan(0); + + const coreBundle = fs.readFileSync(require.resolve('playwright-core/lib/coreBundle'), 'utf8'); + const runtimeEnvVars = new Set(coreBundle.match(/\bPLAYWRIGHT_MCP_[A-Z0-9_]+\b/g) || []); + expect(documentedEnvVars.filter(envVar => !runtimeEnvVars.has(envVar))).toEqual([]); + + const schemaSectionMatch = readme.match(/Configuration file schema<\/summary>([\s\S]*?)<\/details>/); + expect(schemaSectionMatch).toBeTruthy(); + expect(schemaSectionMatch![1]).not.toMatch(/\b(?:saveVideo|outputMode)\b/); + + const { tools } = require('playwright-core/lib/coreBundle'); + const config = await tools.resolveCLIConfigForCLI(test.info().outputPath(), 'default', {}, { + PLAYWRIGHT_MCP_SANDBOX: 'false', + PLAYWRIGHT_MCP_CODEGEN: 'python', + PLAYWRIGHT_MCP_WEBMCP: 'false', + PLAYWRIGHT_MCP_EXTENSION: 'true', + PLAYWRIGHT_MCP_SESSION_COLOR: 'blue', + PLAYWRIGHT_MCP_BACKGROUND: 'true', + PLAYWRIGHT_MCP_NO_TAB_GROUP: 'true', + PLAYWRIGHT_MCP_MOBILE: 'true', + PLAYWRIGHT_MCP_IMAGE_RESPONSES: 'omit', + PLAYWRIGHT_MCP_FILE_PATHS: 'absolute', + PLAYWRIGHT_MCP_OUTPUT_MAX_SIZE: '1024', + PLAYWRIGHT_MCP_TIMEOUT_SETTLE: '250', + PLAYWRIGHT_MCP_REDACT_URL_PARAMS: 'token,code', + PLAYWRIGHT_MCP_REMOTE_HEADERS: 'Authorization: Bearer test-token', + }); + expect(config.browser.launchOptions.chromiumSandbox).toBe(false); + expect(config.browser.launchOptions.headless).toBe(true); + expect(config.codegen).toBe('python'); + expect(config.webmcp).toBe(false); + expect(config.extension).toBe(true); + expect(config.sessionColor).toBe('blue'); + expect(config.background).toBe(true); + expect(config.tabGroup).toBe(false); + expect(config.imageResponses).toBe('omit'); + expect(config.filePaths).toBe('absolute'); + expect(config.outputMaxSize).toBe(1024); + expect(config.timeouts.settle).toBe(250); + expect(config.redactUrlParams).toEqual(['token', 'code']); + expect(config.browser.remoteHeaders).toEqual({ Authorization: 'Bearer test-token' }); +});