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

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

Open
kaidoatgit opened this issue Nov 15, 2022 · 5 comments

Comments

@kaidoatgit
Copy link

kaidoatgit commented Nov 15, 2022

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
Copy link
Contributor

dhoehna commented Nov 15, 2022

@kaidoatgit would Install location vitualization work?

@kaidoatgit
Copy link
Author

@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
Copy link
Author

@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
Copy link
Contributor

dhoehna commented Nov 15, 2022

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
Copy link
Author

kaidoatgit commented Nov 15, 2022

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.

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

No branches or pull requests

2 participants