playwright-dotnet: [BUG] Exception thrown when using playwright in a single-file published program

Context:

  • Playwright Version: 1.24.1
  • Operating System: Windows 10
  • .NET version: .NET 6
  • Browser: All
  • Extra:

Code Snippet

See code to reproduce this bug here: https://github.com/resurge/PlaywrightSingleFilePathError

Describe the bug When publishing a project as single file and running the published executable the following error will be shown:

Unhandled exception. System.ArgumentException: The path is empty. (Parameter 'path')
   at System.IO.Path.GetFullPath(String path)
   at System.IO.FileInfo..ctor(String originalPath, String fullPath, String fileName, Boolean isNormalized)
   at System.IO.FileInfo..ctor(String fileName)
   at Microsoft.Playwright.Helpers.Driver.GetExecutablePath() in /_/src/Playwright/Helpers/Driver.cs:line 41
   at Microsoft.Playwright.Transport.StdIOTransport.GetProcess() in /_/src/Playwright/Transport/StdIOTransport.cs:line 119
   at Microsoft.Playwright.Transport.StdIOTransport..ctor() in /_/src/Playwright/Transport/StdIOTransport.cs:line 44
   at Microsoft.Playwright.Playwright.CreateAsync() in /_/src/Playwright/Playwright.cs:line 44
   at Program.<Main>$(String[] args) in C:\Users\jeroe\Documents\repos\PlaywrightSingleFilePathError\Program.cs:line 3
   at Program.<Main>(String[] args)

I would expect the program to behave the same way as a regular Debug or Release build.
But choosing to publish as a single file causes the behaviour of the executable to change. (And not work)

The following tickets were about the same bug but were closed because of no code to reproduce:

EDIT: Some other issues I found relating to this bug:

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 11
  • Comments: 21 (7 by maintainers)

Most upvoted comments

While that seems to be the initial reason Playwright was created it is used for more that that.
I myself use it for scraping or transforming html to PDF. I would like to be able to share a single executable with users instead of having to make a zip file or installer as release.

I agree more with the description that is written in the README of this repo.
(Browser automation in general, not just specifically for testing)

Playwright for .NET is the official language port of Playwright, the library to automate Chromium, Firefox and WebKit with a single API.

The linked issues show that there is a need for this type of publishing.
EDIT: I found some more tickets about people using it this way, I added them above.

Starting from v1.44 (will be released in 3-4 weeks) this should be fixed: https://github.com/microsoft/playwright-dotnet/pull/2909

Browsers need to be installed via Microsoft.Playwright.Program.Main(["install"]);

Same issue here. We publish a single-file self-contained executable in a docker image, alongside the playwright stuff.

When dealing with docker images that is significantly more convenient and eliminates many dependency problems (which is why it is such a popular approach in the docker world).

But playwright conflicts with that deployment model.

@jeroenpelgrims … Are we going to resolve this or it would take more time?

I’ll try to test tomorrow. I actually haven’t worked on the project this was for since the creation of this issue.

You verified it working on your end?

EDIT: Still doesn’t seem to work although I get a clearer error message now.

Unhandled exception. System.NotSupportedException: CodeBase is not supported on assemblies loaded from a single-file bundle.
   at System.Reflection.RuntimeAssembly.get_CodeBase()
   at Microsoft.Playwright.Helpers.Driver.GetExecutablePath() in /_/src/Playwright/Helpers/Driver.cs:line 47
   at Microsoft.Playwright.Transport.StdIOTransport.GetProcess() in /_/src/Playwright/Transport/StdIOTransport.cs:line 114
   at Microsoft.Playwright.Transport.StdIOTransport..ctor() in /_/src/Playwright/Transport/StdIOTransport.cs:line 44
   at Microsoft.Playwright.Playwright.CreateAsync() in /_/src/Playwright/Playwright.cs:line 44
   at ResumeBuilder.Pdf.PdfBuilder.SavePdf(String htmlPath, String outputFile) in C:\Users\....\PdfBuilder.cs:line 9
   at Program.<Main>$(String[] args) in C:\Users\...\Program.cs:line 11
   at Program.<Main>(String[] args)

Same result when publishing self contained or framework dependent.