Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: list installed browsers #34258

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/actions/run-test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ runs:
echo "::endgroup::"
shell: bash
- run: |
echo "::group::npx playwright install --with-deps"
npx playwright install --with-deps ${{ inputs.browsers-to-install }}
echo "::group::npx playwright install --with-deps --list"
npx playwright install --with-deps --list ${{ inputs.browsers-to-install }}
echo "::endgroup::"
shell: bash
- name: Run tests
Expand Down
64 changes: 64 additions & 0 deletions docs/src/cli.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Playwright CLI

## `playwright ls`

List installed browsers.

### Usage

```sh
npx playwright ls
```

### Description

The `playwright ls` command lists all installed browsers along with their versions and installation locations.

### Example

```sh
$ npx playwright ls
Browser: chromium
Version: 91.0.4472.124
Install location: /path/to/chromium

Browser: firefox
Version: 89.0
Install location: /path/to/firefox

Browser: webkit
Version: 14.2
Install location: /path/to/webkit
```

## `npx playwright install --list`

List installed browsers after installing them.

### Usage

```sh
npx playwright install --list
```

### Description

The `--list` option for the `npx playwright install` command lists all installed browsers along with their versions and installation locations after installing them.

### Example

```sh
$ npx playwright install --list
Installing browsers...
Browser: chromium
Version: 91.0.4472.124
Install location: /path/to/chromium

Browser: firefox
Version: 89.0
Install location: /path/to/firefox

Browser: webkit
Version: 14.2
Install location: /path/to/webkit
```
37 changes: 37 additions & 0 deletions packages/playwright-core/src/cli/commands/install.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* 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 { registry } from '../../server';
import { gracefullyProcessExitDoNotHang } from '../../utils';

async function listInstalledBrowsers() {
try {
const executables = registry.executables();
for (const executable of executables) {
if (executable.installType !== 'none') {
console.log(`Browser: ${executable.name}`);

Check failure on line 25 in packages/playwright-core/src/cli/commands/install.ts

View workflow job for this annotation

GitHub Actions / docs & lint

Unexpected console statement
console.log(` Version: ${executable.browserVersion}`);

Check failure on line 26 in packages/playwright-core/src/cli/commands/install.ts

View workflow job for this annotation

GitHub Actions / docs & lint

Unexpected console statement
console.log(` Install location: ${executable.directory}`);

Check failure on line 27 in packages/playwright-core/src/cli/commands/install.ts

View workflow job for this annotation

GitHub Actions / docs & lint

Unexpected console statement
console.log('');

Check failure on line 28 in packages/playwright-core/src/cli/commands/install.ts

View workflow job for this annotation

GitHub Actions / docs & lint

Unexpected console statement
}
}
} catch (e) {
console.error(`Failed to list installed browsers\n${e}`);

Check failure on line 32 in packages/playwright-core/src/cli/commands/install.ts

View workflow job for this annotation

GitHub Actions / docs & lint

Unexpected console statement
gracefullyProcessExitDoNotHang(1);
}
}

export { listInstalledBrowsers };
25 changes: 25 additions & 0 deletions packages/playwright-core/src/cli/commands/ls.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* 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 { execSync } from 'child_process';
import { expect, test } from '@playwright/test';

test('playwright ls command should list installed browsers', async () => {
const result = execSync('npx playwright ls').toString();
expect(result).toContain('Browser:');
expect(result).toContain('Version:');
expect(result).toContain('Install location:');
});
21 changes: 21 additions & 0 deletions packages/playwright-core/src/cli/commands/ls.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { registry } from '../../server';

Check failure on line 1 in packages/playwright-core/src/cli/commands/ls.ts

View workflow job for this annotation

GitHub Actions / docs & lint

Missing notice header
import { gracefullyProcessExitDoNotHang } from '../../utils';

async function listInstalledBrowsers() {
try {
const executables = registry.executables();
for (const executable of executables) {
if (executable.installType !== 'none') {
console.log(`Browser: ${executable.name}`);

Check failure on line 9 in packages/playwright-core/src/cli/commands/ls.ts

View workflow job for this annotation

GitHub Actions / docs & lint

Unexpected console statement
console.log(` Version: ${executable.browserVersion}`);

Check failure on line 10 in packages/playwright-core/src/cli/commands/ls.ts

View workflow job for this annotation

GitHub Actions / docs & lint

Unexpected console statement
console.log(` Install location: ${executable.directory}`);

Check failure on line 11 in packages/playwright-core/src/cli/commands/ls.ts

View workflow job for this annotation

GitHub Actions / docs & lint

Unexpected console statement
console.log('');

Check failure on line 12 in packages/playwright-core/src/cli/commands/ls.ts

View workflow job for this annotation

GitHub Actions / docs & lint

Unexpected console statement
}
}
} catch (e) {
console.log(`Failed to list installed browsers\n${e}`);
gracefullyProcessExitDoNotHang(1);
}
}

export { listInstalledBrowsers };
14 changes: 13 additions & 1 deletion packages/playwright-core/src/cli/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { wrapInASCIIBox, isLikelyNpxGlobal, assert, gracefullyProcessExitDoNotHa
import type { Executable } from '../server';
import { registry, writeDockerVersion } from '../server';
import { isTargetClosedError } from '../client/errors';
import { listInstalledBrowsers } from './commands/ls';

const packageJSON = require('../../package.json');

Expand Down Expand Up @@ -133,7 +134,8 @@ program
.option('--force', 'force reinstall of stable browser channels')
.option('--only-shell', 'only install headless shell when installing chromium')
.option('--no-shell', 'do not install chromium headless shell')
.action(async function(args: string[], options: { withDeps?: boolean, force?: boolean, dryRun?: boolean, shell?: boolean, noShell?: boolean, onlyShell?: boolean }) {
.option('--list', 'list installed browsers')
.action(async function(args: string[], options: { withDeps?: boolean, force?: boolean, dryRun?: boolean, shell?: boolean, noShell?: boolean, onlyShell?: boolean, list?: boolean }) {
// For '--no-shell' option, commander sets `shell: false` instead.
if (options.shell === false)
options.noShell = true;
Expand Down Expand Up @@ -183,6 +185,9 @@ program
console.error(e);
});
}
if (options.list) {
await listInstalledBrowsers();
}
} catch (e) {
console.log(`Failed to install browsers\n${e}`);
gracefullyProcessExitDoNotHang(1);
Expand Down Expand Up @@ -338,6 +343,13 @@ Examples:

$ show-trace https://example.com/trace.zip`);

program
.command('ls')
.description('list installed browsers')
.action(async function() {
await listInstalledBrowsers();
});

type Options = {
browser: string;
channel?: string;
Expand Down
Loading