microsoft / microsoft/playwright-dotnet

[Feature] Suggestion: make installation easier, for example add InstallWhenNeeded

Open
#2,239 6 comments 13 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

P3-collecting-feedback
Dominant language
C#
Stars
3k
Forks
304
Avg merge
20h 47m
Merged PRs (30d)
6

Description

Hi,

I'm trying to get Playwright working in multiple teams. But different setup/code bases makes the installation a bit of a headache.

And then I had an idea, why don't we just make it supereasy? For example, add an option, like InstallWhenNeeded to BrowserTypeLaunchOptions that installs the browser when needed.

This will prevent then:

Executable doesn't exist
Looks like Playwright Test or Playwright was just installed or updated.
Please run the following command to download new browsers:

Proposal

My proposal, and feel free to use another name for InstallWhenNeeded

//  No install somewhere, will  do internally Program.Main(new[] { "install", "chromium" });
var browser = await playwright.Chromium.LaunchAsync();

// This should still work (manual install before launch)
Program.Main(new[] { "install", "chromium" }); 
var browser = await playwright.Chromium.LaunchAsync();

// Won't do internally Program.Main(new[] { "install", "chromium" });  - so old behavior. So crash if the browser aren't installed yet
var options = new BrowserTypeLaunchOptions { InstallWhenNeeded = false}; 
var browser = await playwright.Chromium.LaunchAsync(options);

Current work around

This is currently my work around to make things super easy:

private static async Task<IBrowser> LaunchChromiumBrowser(IPlaywright playwright, BrowserTypeLaunchOptions options)
{
    IBrowser browser;
    try
    {
        browser = await playwright.Chromium.LaunchAsync(options);
    }
    catch (PlaywrightException e) when (e.Message.Contains("Executable doesn't exist"))
    {
        Program.Main(new[] { "install", "chromium" });
        browser = await playwright.Chromium.LaunchAsync(options);
    }
    return browser;
}

Current work around - Generic version:

private static async Task<IBrowser> LaunchBrowser(IBrowserType browserType, BrowserTypeLaunchOptions options)
{
    IBrowser browser;
    try
    {
        browser = await browserType.LaunchAsync(options);
    }
    catch (PlaywrightException e) when (e.Message.Contains("Executable doesn't exist"))
    {
        Program.Main(new[] { "install", browserType.Name });
        browser = await browserType.LaunchAsync(options);
    }
    return browser;
}

And yes, it make the first test slow. But if that's an issue, you could still install it manually like before.

related:
#990, #1692,#1793, #1822, #2006, #2181, #2198

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading BrowserTypeLaunchOptions and the IBrowserType LaunchAsync entry points, then review the related issues #990, #1692, #1793, #1822, #2006, #2181 and #2198. Compare the proposed automatic installation behavior with the existing install command and manual-launch workaround. Done means the behavior and opt-out semantics are defined and covered for Chromium and generic browser types.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.