playwrightplaywright-dotnet

Configure Playwright to run in an ASP.NET Core 8 web app


I am trying to use Playwright to run within an ASP.NET Core 8 web app. It installed the browsers under the user profile.

Everything works in development. When I deploy the web app for release, it throws the error:

Microsoft.Playwright.PlaywrightException: Executable doesn't exist   
at C:\Windows\system32\config\systemprofile\AppData\Local\ms-playwright\chromium_headless_shell-1161\chrome-win\headless_shell.exe

I know I can just copy the files over to this location, but would rather not. How can I get it to look for a custom folder?

I am using .NET 8.


Solution

  • Playwright looks for its binaries in %LOCALAPPDATA%\ms-playwright.
    An IIS worker that starts under systemprofile has no %LOCALAPPDATA%, so it tries
    C:\Windows\system32\config\systemprofile\AppData\Local\ms-playwright\… and finds nothing (see https://playwright.dev/dotnet/docs/browsers).

    Two ways to fix it:

    1. Load a user profile
      IIS Manager → Application Pools → your pool, Advanced Settings → set Load User Profile = True
      Then run playwright install once while logged in as the same identity. The profile now contains the browsers and Playwright starts fine.

    2. Use a shared cache