Home

Using Playwright in Linqpad

To use PlayWright in dotnet it is required to install required drivers either via playwright.ps1 script that should be copied to output folder or by running Microsoft.Playwright.Program.Main method. In Linqpad it is possible to run Playwright only when I manually copy .playwright folder from vs solution that run Playwright Main method, when running Playwright Main method in Linqpad I get

Microsoft.Playwright assembly was found, but is missing required assets. Please ensure to build your project before running Playwright tool

is it possible to install it without manually copying .playwright folder?

Comments

  • You shouldn't need to manually copy anything. Just reference the Playwright NuGet package and invoke the Main method programmatically to install the required dependencies. Then you should be able to use Playwright as in the demos:

    using Microsoft.Playwright;
    
    Microsoft.Playwright.Program.Main(new[] { "install" });   // Install Playwright if not already installed
    
    using var playwright = await Playwright.CreateAsync();
    await using var browser = await playwright.Chromium.LaunchAsync();
    var page = await browser.NewPageAsync();
    await page.GotoAsync("https://playwright.dev/dotnet");
    await page.ScreenshotAsync(new PageScreenshotOptions { Path = "screenshot.png" });
    Util.Image (Path.GetFullPath ("screenshot.png")).Dump();
    
  • When I copied my code to the new query it started to work, in the previous one I think I must have pasted Playwright dll manually to the shadow folders... thanks!

Sign In or Register to comment.