playwright-dotnet: Can't find the driver

Greetings,

I’ve been using Playwright Sharp and it’s been working really well on my local development machine. However, when I try to deploy my application to one of my servers, I am sometimes greeted with the following exception:

Unhandled exception. System.AggregateException: One or more errors occurred. (Driver not found in any of the locations.)
 ---> PlaywrightSharp.PlaywrightSharpException: Driver not found in any of the locations.
   at PlaywrightSharp.Transport.Connection.GetExecutablePath() in /home/runner/work/playwright-sharp/playwright-sharp/src/PlaywrightSharp/Transport/Connection.cs:line 270
   at PlaywrightSharp.Transport.Connection.GetProcess(String driverExecutablePath) in /home/runner/work/playwright-sharp/playwright-sharp/src/PlaywrightSharp/Transport/Connection.cs:line 233
   at PlaywrightSharp.Transport.Connection..ctor(ILoggerFactory loggerFactory, TransportTaskScheduler scheduler, String driverExecutablePath, String browsersPath) in /home/runner/work/playwright-sharp/playwright-sharp/src/PlaywrightSharp/Transport/Connection.cs:line 74
   at PlaywrightSharp.Playwright.CreateAsync(ILoggerFactory loggerFactory, TransportTaskScheduler scheduler, String driverExecutablePath, String browsersPath, String debug) in /home/runner/work/playwright-sharp/playwright-sharp/src/PlaywrightSharp/Playwright.cs:line 109

This exception is thrown when I call CreateAsync() or InstallAsync() as well. Here’s what I’ve tried so far:

  • Call Create and Install as the first line of code in my application, this only threw the above exception
  • Attempt to build and dotnet publish my application so the build-time Playwright tools could do their magic
  • Ran npx playwright install to install any missing drivers. This returns without any errors, but the exception still occurs

The %USERPROFILE%\AppData\Local\ms-playwright contains the following directories:


    Directory: C:\Users\aevitas\AppData\Local\ms-playwright


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----          3/2/2021   9:49 AM                .links
d-----         2/27/2021  11:33 PM                chromium-844399
d-----         2/28/2021   9:35 AM                chromium-854489
d-----         2/28/2021   9:35 AM                ffmpeg-1005
d-----         2/27/2021  11:33 PM                firefox-1225
d-----         2/28/2021   9:35 AM                firefox-1234
d-----         2/27/2021  11:33 PM                webkit-1423
d-----         2/28/2021   9:35 AM                webkit-1438

Playwright did initially work on this server for a while, but after a redeploy without any significant code changes, it randomly stopped working. Is there anything I’m missing here?

Thanks!

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 2
  • Comments: 54 (9 by maintainers)

Most upvoted comments

@andreasvatne We’ve published a significant new release this morning - now available as Microsoft.Playwright on NuGet. It should also fix the problem you were seeing.

@kblok Do you know when a new release including the dotnet publish fix will be out?

Found the problem. When installing PlaywrightShap in one of my assemblies, and referencing that assembly from my application assembly, I can use the Playwright class “indirectly”, without having a reference to PlaywrightSharp in my executable project.

This means that the build steps required to properly install and configure Playwright never actually run, most of the time. Adding a reference to PlaywrightSharp to my executable projects solved the problem.

A few interesting points:

  • Docker builds did not seem to follow this pattern, a docker build would still run the PW install stuff
  • At some point, it did work with an indirect reference

Either way, I don’t know how I’d fix this in code as I’m not proficient in MSBuild enough to propose such a change, so I’ll be closing this ticket.

Thanks for the help and for the great work on PlaywrightSharp.

I literally just got the old version (0.192) working yesterday, so I will keep that for now. It works both while debugging and also in a Docker container. The only drawback is that I need to reference PlaywrightSharp in the host project and add this in the .csproj file (as described earlier in this thread):

  <!-- remove this target if this is fixed: https://github.com/microsoft/playwright-sharp/issues/1226 -->
  <Target Name="PostPublish" AfterTargets="Publish">
    <ItemGroup>
      <PlaywrightContent Include="$(TargetDir).playwright\win-x64\**\*.*"/>
    </ItemGroup>
    <Copy SourceFiles="@(PlaywrightContent)" DestinationFiles="@(PlaywrightContent->'$(PublishDir)\.playwright\win-x64\%(RecursiveDir)%(Filename)%(Extension)')"/>
  </Target>

The workaround I came up with for a DevOps build pipeline is to add a Copy Files task after the build and before publishing artifacts for deployment.

image image

We seem to be having the same issue. It’s a .NET Core 3.1 Web Api project that depends on Playwright 0.192 from NuGet. Running on win-x64. I have a await Playwright.CreateAsync() call in a static class, as far as I understand it should try to install the driver(s) indirectly. It all works fine on my dev machine because playwright.cmd install is ran as part of the build process by MSBuild but it throws the exception seen in the OP’s post when ran on the server (built by TeamCity and deployed by Octopus).

In the docs there is an example of how to install on the server but we were unable to locate the executable. Is that documentation still valid?

@ChadNedzlek this is next on my To-Do list, we will fix it.

@kblok Thank you for explaining why this was changed, I wasn’t aware of the behind the scenes changes made in 0.190.0 with regards to the drivers. I have created a library that integrates xUnit with PlaywrightSharp to more easily write UI tests and that is what we use in our company for multiple projects (it is currently only available internally but I am considering open sourcing it). It’s a shame that we will have to add direct references to PlaywrightSharp when upgrading, but at least now I understand why it is needed.

I have this same issue in multiple projects of mine (.NET 5 on linux, running in xUnit projects as well as normal console projects), however I’d rather not reference PlaywrightSharp in my main project and would like to have it transparently copy the drivers over. This is how it used to work in version 0.180.0 (and for that reason I’m still using it).

@kblok is there something I can help with to get this fixed? from my observations it happened between versions 0.180.0 and 0.191.0 and occurs when you don’t directly depend on PlaywrightSharp. (also, can this issue be reopened as this issue is not fixed)