[Question]: How to set up a custom driver path? (Does not work with ASP.NET 4.8)

See original GitHub issue

Your question

Hi, I use the Playwright 1.16.1 with an ASP.NET NET Application (.NET Framework 4.8) on the WIndows machine. I would like to ship my application together with the next entities in the App_Data folder:

  1. A bundled browser - OK. I can set up a custom path via ExecutablePath of the BrowserTypeLaunchOptions class.
  2. Playwright driver - I don’t see a needed API that allows me to set up a custom path for the Playwright driver (the .playwright folder).

Question: How to have a custom path for the .playwright folder?

What I tried: I see the BrowserTypeLaunchOptions class also contains the Env key-value property. I’ve tried to add the PLAYWRIGHT_DRIVER_PATH key with a custom path value but looks like it doesn’t work.

Problem and what I can see: I have debugged the Playwright tool itself and discovered the next things:

The responsible class for the driver path is Microsoft.Playwright.Helpers.Patch which has the GetExecutablePath method. Please check the code with the 1-4 comments below:

internal static class Paths
    {
        internal static string GetExecutablePath()
        {
            //1 - The AppContexts.BaseDirectory for me is the root of the ASP.NET solution, at this level I can see the App_Data, bin folders etc.
            DirectoryInfo assemblyDirectory = new(AppContext.BaseDirectory);
            //2 - then there is a check which looking for the Microsoft.Playwright.dll at the previously mentioned path, but there is no such Playwright dll, because it's under the bin folder.
            if (!assemblyDirectory.Exists || !File.Exists(Path.Combine(assemblyDirectory.FullName, "Microsoft.Playwright.dll")))
            {
                //3 - the dll haven't found at the root of website and now code looking for the type. 
                //The type was found under the Temporary ASP.NET Files (the path is: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\13163ddd\37e5e286\assembly\dl3\.playwright\node).
                var assemblyLocation = typeof(Playwright).Assembly.Location;
                //4 - then the rest of the code relies on the assemblyDirectory variable which is the Temporary ASP.NET Files.
                // If manually add the .playwright folder there, my application works but I would like to avoid manually put the driver here.
                assemblyDirectory = new FileInfo(assemblyLocation).Directory;
            }

            string executableFile = GetPath(assemblyDirectory.FullName);
            if (File.Exists(executableFile))
            {
                return executableFile;
            }

            // if the above fails, we can assume we're in the nuget registry
            executableFile = GetPath(assemblyDirectory.Parent.Parent.FullName);
            if (File.Exists(executableFile))
            {
                return executableFile;
            }

            throw new PlaywrightException($"Driver not found: {executableFile}");
        }

Should this class be more flexible? Is there any other approach that I don’t see? Thank you in advance! 😃 Please let me know if I should clarify something more.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
smitbmxcommented, Jan 18, 2022

Hi, @mxschmitt, there is the sample project as you’ve asked: https://github.com/smitbmx/DemoPlaywrightASPNET48

As I described previously, there is a workaround to add the .playwright folder under the Temporary ASP.NET Files, but I strongly would like to avoid it. It would be really nice to have a customizable path for the Playwright driver as if was done for the bundled browsers via ExecutablePath variable of the BrowserTypeLaunchOptions class. Then it gives the ability to keep the driver somewhere under the App_Data folder of the ASP.NET solutions. Please let me know if you have additional questions.

1reaction
smitbmxcommented, Jan 18, 2022

Hi @mxschmitt, sure, I’ll make it and let you know when it’s ready.

Read more comments on GitHub >

github_iconTop Results From Across the Web

.NET Framework 4.8 on Windows Server 2019 - installation ...
I have tried to install the cab file separately by downloading it from Microsoft Update Catalog (https://www.catalog.update.microsoft.com/Search ...
Read more >
What's new in .NET Framework
See what's new in various versions of .NET Framework. Read a summary of key new features and improvements in each version.
Read more >
Adding configurations to manually created startup.cs class ...
cs file in my web API project, so I have added an OWIN startup class . This class has a Configuration method but...
Read more >
NetIQ Identity Manager 4.8.6: Installation and Upgrade Guide
2 Navigate to the <ISO mounted location> and run the following command: ./install.sh. 3 Specify the component that you want to update. NOTE:...
Read more >
Accessing and using certificate private keys in .NET ...
Any library that implements PKCS#1/8 could work with such keys, thus providing a way to use custom cryptographic libraries on a single platform....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found