2

We have a single Asp Core API method that is transforming provided html into PDF using headless Chromium. Currently the API method is using Puppeteer, which connects to an existing instance of Chromium using the debugging port and generates the PDF. Chromium needs to be launched before or on application start. All this works fine.

We are now considering rewriting the API to use Microsoft.Playwright instead of the Puppeteer. However, it seems that with Playwright for .Net we can't connect to an existing browser instance and we always need to use BrowserType.LaunchAsync, which creates a new instance. I can see the BrowserType.Connect available for all other APIs (node, python, java) but not for .Net.

Is there a way to avoid launching a new browser for every API request using the .Net Playwright API? It is very time-consuming and performance is very important in our case.

filip
  • 1,444
  • 1
  • 20
  • 40
  • 1
    Playwright for dotnet doesn't have that feature yet – hardkoded Jun 15 '21 at 13:06
  • Its very funny that Playwright Sharp doesnt yave the connect method yet though being backed by Microsoft ...who created .Net – Nicober Mani Jun 18 '21 at 02:56
  • Regarding launching new browser instance every-time - you don't have to. BrowserContext will take take of it and it is cheap - https://playwright.dev/docs/core-concepts#browser-contexts – rai-gaurav Jul 05 '21 at 18:38
  • We used to open chromium.exe from server directory using puppeteerSharp. No such option is available while using Playwright. Playwright.CreateAsync() call is must and it is throwing Microsoft.Playwright.PlaywrightException: Driver not found. @hardkoded How to use executables available in server directory. it's intranet application – PalakM Aug 04 '21 at 14:49

0 Answers0