myesn

myEsn2E9

hi
github

Install Playwright for .NET

Installation Steps#

Warning

Although the installation process is universal, this article is mainly for Windows users.

Perform the following steps in the target project where you want to install Playwright:

  1. Install Playwright dependencies for the specified project:
dotnet add package Microsoft.Playwright
  1. Build the project, which will generate the playwright.ps1 file in the bin directory (used for downloading headless browsers Chromium, WebKit, and Firefox, and some other dependencies):
dotnet build
  1. Install or update the PowerShell global command pwsh:
    If it doesn't exist, it will be automatically installed during update
dotnet tool update --global PowerShell
  1. Replace netX with the actual output folder name to execute the script file in the bin directory for installing the required browsers, such as net7.0:
    image
pwsh bin/Debug/netX/playwright.ps1 install

If you encounter the following error during install, it is because the .NET Core type does not copy the NuGet package DLLs to the debug directory. Refer to: https://github.com/microsoft/playwright-dotnet/issues/2127#issuecomment-1148565925
image

Therefore, you need to execute install in the console or web project that references the libraries, as that is where the Microsoft.Playwright.dll and other files will be present. It should be executed as shown in the screenshot below:
image

After execution, three different browser engines will be downloaded:
image

Installation Directory#

After the installation is complete, you can find the headless browsers (Windows) in the following directory:

%USERPROFILE%\AppData\Local\ms-playwright

References#

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.