Skip to content

[Feature]: let cli-client program() accept parsed arguments #43938

Closed

Description

Problem

playwright-cli.js in microsoft/playwright-cli must know the command name before it calls program() from playwright-core/lib/tools/cli-client/program, because it checks for updates only for some commands. At the moment it finds the command with its own simple parser, and this parser can take a session name as the command (microsoft/playwright-cli#505).

microsoft/playwright-cli#521 fixes this, but it loads minimist.js and help.json from the internal files of playwright-core and copies the list of boolean options. Then program() parses the same arguments a second time.

Proposal

In packages/playwright-core/src/tools/cli-client/program.ts:

  • Move the minimist call and the -s → session and -g → global changes out of program() into a new exported function parseArgs(argv: string[]): MinimistArgs.
  • Add an optional args to the options of program(): program(options?: { args?: MinimistArgs, embedderVersion?: string }). When args is not set, program() parses process.argv.slice(2) as it does now, so the current callers continue to work.

Expected result: parseArgs(['-s', 'list', 'snapshot']) returns { _: ['snapshot'], session: 'list' }.

Follow-up in microsoft/playwright-cli

After a release, playwright-cli.js can parse the arguments one time:

const { program, parseArgs } = require('playwright-core/lib/tools/cli-client/program');

const args = parseArgs(process.argv.slice(2));
await checkForUpdates(args._[0]).catch(() => {});
program({ args, embedderVersion: packageJson.version });

program() changes args while it runs (for example in attach and runInSession), so the embedder must read what it needs before it calls program().

Activity

  1. github-actions commented on Nov 5, 2026

    @github-actions
  2. microsoft-playwright-automation commented on Nov 5, 2026

    @microsoft-playwright-automation
    Contributor

    Hi, I'm the Playwright bot. I checked the request and prepared the change.

    Implemented in a fix proposal. On Linux at 17ec699e4f4760bab5ad95f6ef9b954d5f1ce7eb (1.66.0-next), the CLI entry point did not export its parser. The proposal exports parseArgs(argv) and lets program({ args }) use the result without parsing again. Existing callers keep the same behavior.

    The test checks the exact -s list snapshot result, boolean options and alias normalization, then runs program() with parsed arguments. Parsing and help tests pass on Chromium, Firefox and WebKit.

    Draft PR: #43941

    Triaged on Linux by the Playwright bot - agent run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions