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(cli): add command to list installed browsers #35240

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

niba
Copy link

@niba niba commented Mar 17, 2025

Add a new CLI command to list all browser installations managed by Playwright. Fixes #34183

This command shows browsers installed by the current Playwright instance
npx playwright list

image

To list browsers installed by all Playwright instances, use the --all flag:

npx playwright list --all

image

@niba
Copy link
Author

niba commented Mar 17, 2025

@microsoft-github-policy-service agree

@niba niba force-pushed the feat/list_command branch from 203f77c to 3c0f06e Compare March 17, 2025 18:39
@niba niba force-pushed the feat/list_command branch from 3c0f06e to 7f73578 Compare March 17, 2025 18:40

This comment has been minimized.

Copy link
Contributor

Test results for "tests 1"

1 failed
❌ [webkit-library] › tests/library/screenshot.spec.ts:44:14 › page screenshot › should work with a mobile viewport @webkit-ubuntu-22.04-node18

3 flaky ⚠️ [firefox-page] › tests/page/page-evaluate.spec.ts:403:3 › should throw for too deep reference chain @firefox-ubuntu-22.04-node18
⚠️ [webkit-library] › tests/library/screenshot.spec.ts:55:14 › page screenshot › should work with a mobile viewport and clip @webkit-ubuntu-22.04-node18
⚠️ [playwright-test] › tests/ui-mode-test-watch.spec.ts:145:5 › should watch all @windows-latest-node18-1

38784 passed, 808 skipped
✔️✔️✔️

Merge workflow run.

@dgozman dgozman changed the title feat(cli): add command to list installed browsers (#34183) feat(cli): add command to list installed browsers Mar 20, 2025
Copy link
Contributor

@dgozman dgozman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR! I left some higher-level comments for now.

@@ -199,6 +199,29 @@ Examples:
- $ install chrome firefox
Install custom browsers, supports ${suggestedBrowsersToInstall()}.`);

program
.command('list')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that issues talks about npx playwright install --list instead of npx playwright list. Generally, we'd prefer everything about browsers to be under install/uninstall.

Copy link
Author

@niba niba Mar 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, that's my fault. I should have shared my thought process in the PR description.
Initially, I started implementing the ⁠--list option. Then, I discovered that it is possible to list installations for all instances of Playwright, and I realized the ⁠--all flag could be useful. I felt that adding ⁠--all and ⁠--list to the install command would be excessive, especially since ⁠--all only works in combination with ⁠--list.
That's why I decided to implement standalone command list
This approach also follows the same pattern as the remove command:
• ⁠npx playwright remove (--all)
⁠npx playwright list (--all)

If you still prefer --list and --all flags I can change it.

// All new applications have a marker file right away.
(browserName !== 'firefox' && browserName !== 'chromium' && browserName !== 'webkit');
if (!shouldHaveMarkerFile || (await existsAsync(browserDirectoryToMarkerFilePath(usedBrowserPath))))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of copying pretty much half of this method, perhaps we can extract the "step 1" from this function into a separate one and reuse it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit lost. I extracted a part of the code that verifies the marker file into a standalone function ⁠_validateMarkerFile. I did this to reuse the same code in the remove and list functions.
What do you mean by saying 'step 1'?

.action(async (options: { all?: boolean }) => {
await registry.list(!!options.all).then(browsersInfo => {
for (const info of browsersInfo) {
const whichInstanceLog = ` (${info.currentInstance ? 'CURRENT' : 'OTHER'})`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kinda find CURRENT/OTHER being very much in my face. Can we tone it down somehow? Perhaps not show "other" at all, because we print the target directory anyway, and only mark current as (current) when --all is not passed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: list installed browsers
2 participants