microsoft / MSIX-PackageSupportFramework

The Package Support Framework (PSF) is a kit for applying compatibility fixes to packaged desktop applications.
MIT License
114 stars 57 forks source link

Installing an MSIX including Microsoft.Playwright (nugget package that automate browser tasks) #219

Open kaidoatgit opened 1 year ago

kaidoatgit commented 1 year ago

Hello,

Im currently trying to publish a desktop application that uses Microsoft Playwright to automate few task, however it seems that im missing something... So after creating a windows package project in visual studio to package my application (Publish > Create Package > ...) I ended up with an installer: image The application installs correctly and all other dependencies such as API and Database are working correctly but Playwright is not working for some reason.

For testing purpose I've created a Mock project that has a simple button that calls playwright:

try
{
    var exitCode = Microsoft.Playwright.Program.Main(new[] { "install" });
    if (exitCode != 0)
    {
        Console.WriteLine("Failed to install browsers");
    }

    using var playwright = await Playwright.CreateAsync();
    await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions() { Headless = false });
    await using var browserContext = await browser.NewContextAsync();
    var page = await browserContext.NewPageAsync();
    await page.GotoAsync("https://www.google.com");
    await page.WaitForTimeoutAsync(10000f);
}
catch (Exception exception)
{
    output.Text = exception.Message + Environment.NewLine + exception.StackTrace + Environment.NewLine;
}

The package installation details: .NET CORE 6 Playwright package version: 1.27.2 Windows 10 x64

After the package is installed I run the application that looks like this: image

When the Test button is pressed, the above code runs and this is the final output: image

Playwright fails to install and therefore the launching/creation not working which I believe the exception is pointing to.

.playwright folder exist after installing my package image

It seems I cant run/execute any kind of action in this folder C:\Program Files\WindowsApps ... which means that I cant install playwright, even if playwright is installed manually the app cant launch it... All MSIX (package installers generated by Visual studio) are installed in this particular folder with high security.

Any clue how to solve this problem without getting access to this folder? Clients shouldnt unsecure this folder

Thanks.

Note: I really want to install using MSIX because I want to upload my application into microsoft store

dhoehna commented 1 year ago

@kaidoatgit would Install location vitualization work?

kaidoatgit commented 1 year ago

@kaidoatgit would Install location vitualization work?

Hello mate, I will give a try and research about it, thanks for your answer, i will give feedback as soon as possible

kaidoatgit commented 1 year ago

@kaidoatgit would Install location vitualization work?

Hello mate, I will give a try and research about it, thanks for your answer, i will give feedback as soon as possible

It does not work :(

dhoehna commented 1 year ago

Coolio. Thank you for trying my suggestion. Before I continue with suggestions I want to make sure I understand your problem.

What is the main issue? playwright can't be installed?

kaidoatgit commented 1 year ago

Coolio. Thank you for trying my suggestion. Before I continue with suggestions I want to make sure I understand your problem.

What is the main issue? playwright can't be installed?

Im currently deploying my MSIX Package, everything works perfect in localhost however when I install using the package itself some funcionalities of my WPF dont work. After some researches I found that all MSIX package are deployed into this super protected folder with read-only permissions: C:\Program Files\WindowsApps.

My problem is that im using a nugget package from Microsoft to install Microsoft.Playwright which is a tool to automate browser tasks. The following code installs the binaries for chromium browser:

var exitCode = Microsoft.Playwright.Program.Main(new[] { "install", "chromium" });
            if (exitCode != 0)
            {
                   output.Text += "Failed to install browsers" + Environment.NewLine;
            }

However because of the super protected folder C:\Program Files\WindowsApps the code above does not work.

I've tried another approach that was to install the binaries manually and then use the following code to create the object to automate browser task:

using var playwright = await Playwright.CreateAsync();
                await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions() { Headless = false });
                await using var browserContext = await browser.NewContextAsync();
                var page = await browserContext.NewPageAsync();
                await page.GotoAsync(website_url);
                await page.WaitForTimeoutAsync(10000f);

Even this way it still doesnt work. I did give permission myself to write on this super protected folder: C:\Program Files\WindowsApps and this is the only way that works, but this is a big NO, because this folder shouldnt be unsecured.