# NOTE: This patch file is generated automatically and is not used, it is only for documentation. The driver is actually patched using [patchright_driver_patch](https://github.com/Kaliiiiiiiiii-Vinyzu/patchright/blob/main/patchright_driver_patch.ts), see [the workflow](https://github.com/Kaliiiiiiiiii-Vinyzu/patchright/blob/main/.github/workflows/patch_file_updater.yml) diff -ruN -x protocol.yml --minimal playwright/node_modules/playwright-core/src/cli/program.ts patchright/node_modules/playwright-core/src/cli/program.ts --- +++ @@ -1,21 +1,3 @@ -/** - * 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. - */ - -/* eslint-disable no-console */ - import { program } from 'commander'; import { gracefullyProcessExitDoNotHang } from '@utils/processLauncher'; import { getPackageManagerExecCommand } from '@utils/env'; @@ -34,90 +16,124 @@ import type { Command } from 'commander'; export function decorateProgram(program: Command) { - program - .version('Version ' + (process.env.PW_CLI_DISPLAY_VERSION || packageJSON.version)) - .name(buildBasePlaywrightCLICommand(process.env.PW_LANG_NAME)); + .version('Version ' + (process.env.PW_CLI_DISPLAY_VERSION || packageJSON.version)) + .name(buildBasePlaywrightCLICommand(process.env.PW_LANG_NAME)); program - .command('mark-docker-image [dockerImageNameTemplate]', { hidden: true }) - .description('mark docker image') - .allowUnknownOption(true) - .action(async function(dockerImageNameTemplate) { - markDockerImage(dockerImageNameTemplate).catch(logErrorAndExit); - }); + .command('mark-docker-image [dockerImageNameTemplate]', { hidden: true }) + .description('mark docker image') + .allowUnknownOption(true) + .action(async function (dockerImageNameTemplate) { + markDockerImage(dockerImageNameTemplate).catch(logErrorAndExit); + }); commandWithOpenOptions('open [url]', 'open page in browser specified via -b, --browser', []) - .action(async function(url, options) { - open(options, url).catch(logErrorAndExit); - }) - .addHelpText('afterAll', ` + .action(async function (url, options) { + open(options, url).catch(logErrorAndExit); + }) + .addHelpText( + 'afterAll', + ` Examples: $ open - $ open -b webkit https://example.com`); + $ open -b webkit https://example.com`, + ); - commandWithOpenOptions('codegen [url]', 'open page and generate code for user actions', - [ - ['-o, --output ', 'saves the generated script to a file'], - ['--target ', `language to generate, one of javascript, playwright-test, python, python-async, python-pytest, csharp, csharp-mstest, csharp-nunit, csharp-xunit, java, java-junit`, codegenId()], - ['--test-id-attribute ', 'use the specified attribute to generate data test ID selectors'], - ]).action(async function(url, options) { - await codegen(options, url); - }).addHelpText('afterAll', ` + commandWithOpenOptions('codegen [url]', 'open page and generate code for user actions', [ + ['-o, --output ', 'saves the generated script to a file'], + [ + '--target ', + `language to generate, one of javascript, playwright-test, python, python-async, python-pytest, csharp, csharp-mstest, csharp-nunit, csharp-xunit, java, java-junit`, + codegenId(), + ], + ['--test-id-attribute ', 'use the specified attribute to generate data test ID selectors'], + ]) + .action(async function (url, options) { + await codegen(options, url); + }) + .addHelpText( + 'afterAll', + ` Examples: $ codegen $ codegen --target=python - $ codegen -b webkit https://example.com`); + $ codegen -b webkit https://example.com`, + ); program - .command('install [browser...]') - .description('ensure browsers necessary for this version of Playwright are installed') - .option('--with-deps', 'install system dependencies for browsers') - .option('--dry-run', 'do not execute installation, only print information') - .option('--list', 'prints list of browsers from all playwright installations') - .option('--force', 'force reinstall of already installed browsers') - .option('--only-shell', 'only install headless shell when installing chromium') - .option('--no-shell', 'do not install chromium headless shell') - .option('--no-progress', 'do not show download progress bars') - .option('--no-remove', 'do not remove unused browsers') - .action(async function(args: string[], options: { withDeps?: boolean, force?: boolean, dryRun?: boolean, list?: boolean, shell?: boolean, onlyShell?: boolean, progress?: boolean, remove?: boolean }) { - try { - await installBrowsers(args, options); - } catch (e) { - console.log(`Failed to install browsers\n${e}`); - gracefullyProcessExitDoNotHang(1); - } - }).addHelpText('afterAll', ` + .command('install [browser...]') + .description('ensure browsers necessary for this version of Patchright are installed') + .option('--with-deps', 'install system dependencies for browsers') + .option('--dry-run', 'do not execute installation, only print information') + .option('--list', 'prints list of browsers from all patchright installations') + .option('--force', 'force reinstall of already installed browsers') + .option('--only-shell', 'only install headless shell when installing chromium') + .option('--no-shell', 'do not install chromium headless shell') + .option('--no-progress', 'do not show download progress bars') + .option('--no-remove', 'do not remove unused browsers') + .action(async function ( + args: string[], + options: { + withDeps?: boolean; + force?: boolean; + dryRun?: boolean; + list?: boolean; + shell?: boolean; + onlyShell?: boolean; + progress?: boolean; + remove?: boolean; + }, + ) { + try { + await installBrowsers(args, options); + } catch (e) { + console.log(`Failed to install browsers\n${e}`); + gracefullyProcessExitDoNotHang(1); + } + }) + .addHelpText( + 'afterAll', + ` Examples: - $ install Install default browsers. - $ install chrome firefox - Install custom browsers, supports chromium, firefox, webkit, chromium-headless-shell.`); + Install custom browsers, supports chromium, firefox, webkit, chromium-headless-shell.`, + ); program - .command('uninstall') - .description('Removes browsers used by this installation of Playwright from the system (chromium, firefox, webkit, ffmpeg). This does not include branded channels.') - .option('--all', 'Removes all browsers used by any Playwright installation from the system.') - .action(async (options: { all?: boolean }) => { - uninstallBrowsers(options).catch(logErrorAndExit); - }); + .command('uninstall') + .description( + 'Removes browsers used by this installation of Patchright from the system (chromium, firefox, webkit, ffmpeg). This does not include branded channels.', + ) + .option('--all', 'Removes all browsers used by any Patchright installation from the system.') + .action(async (options: { all?: boolean }) => { + uninstallBrowsers(options).catch(logErrorAndExit); + }); program - .command('install-deps [browser...]') - .description('install dependencies necessary to run browsers (will ask for sudo permissions)') - .option('--dry-run', 'Do not modify the system. On Linux, simulate the install via apt-get and exit with a non-zero code if any required packages are missing; on Windows, print the install command.') - .action(async function(args: string[], options: { dryRun?: boolean }) { - try { - await installDeps(args, options); - } catch (e) { - console.log(`Failed to install browser dependencies\n${e}`); - gracefullyProcessExitDoNotHang(1); - } - }).addHelpText('afterAll', ` + .command('install-deps [browser...]') + .description('install dependencies necessary to run browsers (will ask for sudo permissions)') + .option( + '--dry-run', + 'Do not modify the system. On Linux, simulate the install via apt-get and exit with a non-zero code if any required packages are missing; on Windows, print the install command.', + ) + .action(async function (args: string[], options: { dryRun?: boolean }) { + try { + await installDeps(args, options); + } catch (e) { + console.log(`Failed to install browser dependencies\n${e}`); + gracefullyProcessExitDoNotHang(1); + } + }) + .addHelpText( + 'afterAll', + ` Examples: - $ install-deps Install dependencies for default browsers. @@ -126,7 +142,8 @@ Install dependencies for specific browsers, supports chromium, firefox, webkit, chromium-headless-shell. - $ install-deps --dry-run - Report which required system dependencies are missing without modifying the system. Exits non-zero if any are missing. Useful for non-interactive verification scripts.`); + Report which required system dependencies are missing without modifying the system. Exits non-zero if any are missing. Useful for non-interactive verification scripts.`, + ); const browsers = [ { alias: 'cr', name: 'Chromium', type: 'chromium' }, @@ -136,127 +153,136 @@ for (const { alias, name, type } of browsers) { commandWithOpenOptions(`${alias} [url]`, `open page in ${name}`, []) - .action(async function(url, options) { - open({ ...options, browser: type }, url).catch(logErrorAndExit); - }).addHelpText('afterAll', ` + .action(async function (url, options) { + open({ ...options, browser: type }, url).catch(logErrorAndExit); + }) + .addHelpText( + 'afterAll', + ` Examples: - $ ${alias} https://example.com`); + $ ${alias} https://example.com`, + ); } - commandWithOpenOptions('screenshot ', 'capture a page screenshot', - [ - ['--wait-for-selector ', 'wait for selector before taking a screenshot'], - ['--wait-for-timeout ', 'wait for timeout in milliseconds before taking a screenshot'], - ['--full-page', 'whether to take a full page screenshot (entire scrollable area)'], - ]).action(async function(url, filename, command) { - screenshot(command, command, url, filename).catch(logErrorAndExit); - }).addHelpText('afterAll', ` + commandWithOpenOptions('screenshot ', 'capture a page screenshot', [ + ['--wait-for-selector ', 'wait for selector before taking a screenshot'], + ['--wait-for-timeout ', 'wait for timeout in milliseconds before taking a screenshot'], + ['--full-page', 'whether to take a full page screenshot (entire scrollable area)'], + ]) + .action(async function (url, filename, command) { + screenshot(command, command, url, filename).catch(logErrorAndExit); + }) + .addHelpText( + 'afterAll', + ` Examples: - $ screenshot -b webkit https://example.com example.png`); + $ screenshot -b webkit https://example.com example.png`, + ); - commandWithOpenOptions('pdf ', 'save page as pdf', - [ - ['--paper-format ', 'paper format: Letter, Legal, Tabloid, Ledger, A0, A1, A2, A3, A4, A5, A6'], - ['--wait-for-selector ', 'wait for given selector before saving as pdf'], - ['--wait-for-timeout ', 'wait for given timeout in milliseconds before saving as pdf'], - ]).action(async function(url, filename, options) { - pdf(options, options, url, filename).catch(logErrorAndExit); - }).addHelpText('afterAll', ` + commandWithOpenOptions('pdf ', 'save page as pdf', [ + ['--paper-format ', 'paper format: Letter, Legal, Tabloid, Ledger, A0, A1, A2, A3, A4, A5, A6'], + ['--wait-for-selector ', 'wait for given selector before saving as pdf'], + ['--wait-for-timeout ', 'wait for given timeout in milliseconds before saving as pdf'], + ]) + .action(async function (url, filename, options) { + pdf(options, options, url, filename).catch(logErrorAndExit); + }) + .addHelpText( + 'afterAll', + ` Examples: - $ pdf https://example.com example.pdf`); + $ pdf https://example.com example.pdf`, + ); - program - .command('run-driver', { hidden: true }) - .action(async function(options) { - runDriver(); - }); + program.command('run-driver', { hidden: true }).action(async function (options) { + runDriver(); + }); program - .command('run-server', { hidden: true }) - .option('--port ', 'Server port') - .option('--host ', 'Server host') - .option('--path ', 'Endpoint Path', '/') - .option('--max-clients ', 'Maximum clients') - .option('--mode ', 'Server mode, either "default" or "extension"') - .option('--artifacts-dir ', 'Artifacts directory') - .option('--unsafe', 'Allow clients to set unsafe launch options (args, executablePath, ignoreAllDefaultArgs, etc)') - .action(async function(options) { - runServer({ - port: options.port ? +options.port : undefined, - host: options.host, - path: options.path, - maxConnections: options.maxClients ? +options.maxClients : Infinity, - extension: options.mode === 'extension' || !!process.env.PW_EXTENSION_MODE, - artifactsDir: options.artifactsDir, - unsafe: !!options.unsafe, - }).catch(logErrorAndExit); - }); + .command('run-server', { hidden: true }) + .option('--port ', 'Server port') + .option('--host ', 'Server host') + .option('--path ', 'Endpoint Path', '/') + .option('--max-clients ', 'Maximum clients') + .option('--mode ', 'Server mode, either "default" or "extension"') + .option('--artifacts-dir ', 'Artifacts directory') + .option('--unsafe', 'Allow clients to set unsafe launch options (args, executablePath, ignoreAllDefaultArgs, etc)') + .action(async function (options) { + runServer({ + port: options.port ? +options.port : undefined, + host: options.host, + path: options.path, + maxConnections: options.maxClients ? +options.maxClients : Infinity, + extension: options.mode === 'extension' || !!process.env.PW_EXTENSION_MODE, + artifactsDir: options.artifactsDir, + unsafe: !!options.unsafe, + }).catch(logErrorAndExit); + }); program - .command('launch-server', { hidden: true }) - .requiredOption('--browser ', 'Browser name, one of "chromium", "firefox" or "webkit"') - .option('--config ', 'JSON file with launchServer options') - .action(async function(options) { - launchBrowserServer(options.browser, options.config); - }); + .command('launch-server', { hidden: true }) + .requiredOption('--browser ', 'Browser name, one of "chromium", "firefox" or "webkit"') + .option('--config ', 'JSON file with launchServer options') + .action(async function (options) { + launchBrowserServer(options.browser, options.config); + }); program - .command('show-trace [trace]') - .option('-b, --browser ', 'browser to use, one of cr, chromium, ff, firefox, wk, webkit', 'chromium') - .option('-h, --host ', 'Host to serve trace on; specifying this option opens trace in a browser tab') - .option('-p, --port ', 'Port to serve trace on, 0 for any free port; specifying this option opens trace in a browser tab') - .option('--stdin', 'Accept trace URLs over stdin to update the viewer') - .description('show trace viewer') - .action(async function(trace, options) { - if (options.browser === 'cr') - options.browser = 'chromium'; - if (options.browser === 'ff') - options.browser = 'firefox'; - if (options.browser === 'wk') - options.browser = 'webkit'; + .command('show-trace [trace]') + .option('-b, --browser ', 'browser to use, one of cr, chromium, ff, firefox, wk, webkit', 'chromium') + .option('-h, --host ', 'Host to serve trace on; specifying this option opens trace in a browser tab') + .option( + '-p, --port ', + 'Port to serve trace on, 0 for any free port; specifying this option opens trace in a browser tab', + ) + .option('--stdin', 'Accept trace URLs over stdin to update the viewer') + .description('show trace viewer') + .action(async function (trace, options) { + if (options.browser === 'cr') options.browser = 'chromium'; + if (options.browser === 'ff') options.browser = 'firefox'; + if (options.browser === 'wk') options.browser = 'webkit'; - const openOptions: TraceViewerServerOptions = { - host: options.host, - port: +options.port, - isServer: !!options.stdin, - }; + const openOptions: TraceViewerServerOptions = { + host: options.host, + port: +options.port, + isServer: !!options.stdin, + }; - if (options.port !== undefined || options.host !== undefined) - runTraceInBrowser(trace, openOptions).catch(logErrorAndExit); - else - runTraceViewerApp(trace, options.browser, openOptions).catch(logErrorAndExit); - }).addHelpText('afterAll', ` + if (options.port !== undefined || options.host !== undefined) + runTraceInBrowser(trace, openOptions).catch(logErrorAndExit); + else runTraceViewerApp(trace, options.browser, openOptions).catch(logErrorAndExit); + }) + .addHelpText( + 'afterAll', + ` Examples: $ show-trace - $ show-trace https://example.com/trace.zip`); + $ show-trace https://example.com/trace.zip`, + ); addTraceCommands(program, logErrorAndExit); program - .command('cli') - .description('run playwright cli commands from terminal') - .allowExcessArguments(true) - .allowUnknownOption(true) - .helpOption(false) - .action(async options => { - process.argv.splice(process.argv.indexOf('cli'), 1); - cliProgram().catch(logErrorAndExit); - }); + .command('cli') + .description('run playwright cli commands from terminal') + .allowExcessArguments(true) + .allowUnknownOption(true) + .helpOption(false) + .action(async options => { + process.argv.splice(process.argv.indexOf('cli'), 1); + cliProgram().catch(logErrorAndExit); + }); - decorateMCPCommand(program - .command('mcp') - .description('run the Playwright MCP server')); + decorateMCPCommand(program.command('mcp').description('run the Playwright MCP server')); } function logErrorAndExit(e: Error) { - if (process.env.PWDEBUGIMPL) - console.error(e); - else - console.error(e.name + ': ' + e.message); + if (process.env.PWDEBUGIMPL) console.error(e); + else console.error(e.name + ': ' + e.message); gracefullyProcessExitDoNotHang(1); } @@ -266,42 +292,53 @@ function commandWithOpenOptions(command: string, description: string, options: any[][]): Command { let result = program.command(command).description(description); - for (const option of options) - result = result.option(option[0], ...option.slice(1)); + for (const option of options) result = result.option(option[0], ...option.slice(1)); return result - .option('-b, --browser ', 'browser to use, one of cr, chromium, ff, firefox, wk, webkit', 'chromium') - .option('--block-service-workers', 'block service workers') - .option('--channel ', 'Chromium distribution channel, "chrome", "chrome-beta", "msedge-dev", etc') - .option('--color-scheme ', 'emulate preferred color scheme, "light" or "dark"') - .option('--device ', 'emulate device, for example "iPhone 11"') - .option('--geolocation ', 'specify geolocation coordinates, for example "37.819722,-122.478611"') - .option('--http-credentials ', 'specify HTTP authentication credentials as "username:password", for example --http-credentials="admin:secret"') - .option('--ignore-https-errors', 'ignore https errors') - .option('--load-storage ', 'load context storage state from the file, previously saved with --save-storage') - .option('--lang ', 'specify language / locale, for example "en-GB"') - .option('--proxy-server ', 'specify proxy server, for example "http://myproxy:3128", "http://user:password@myproxy:3128" or "socks5://myproxy:8080"') - .option('--proxy-bypass ', 'comma-separated domains to bypass proxy, for example ".com,chromium.org,.domain.com"') - .option('--save-har ', 'save HAR file with all network activity at the end') - .option('--save-har-glob ', 'filter entries in the HAR by matching url against this glob pattern') - .option('--save-storage ', 'save context storage state at the end, for later use with --load-storage') - .option('--timezone