4

I have previously used Puppeteer in Node.js and I am now using Microsoft.Playwright in .Net

I have a need to wait until all XHR / Ajax requests have finished so that the page is in a truly "ready" state. Using timouts and delays is unreliable.

With Puppeteer I used a library Pending XHR Puppeteer https://www.npmjs.com/package/pending-xhr-puppeteer which was designed for this issue specifically

So in node.js I would load the page etc inside a warapper and then when needed I would just call

await pageWrapper.waitForAllXhrFinished()

I am assuming that behind the scenes it is keeping count of the ajax requests sent and returning the function once they have all returned.

Note: for one of my scenarios there are 2 XHR requests set and they are from exactly the same URL.

How can we achieve this in Playwright for .Net ?

Martin Thompson
  • 3,415
  • 10
  • 38
  • 62

1 Answers1

4

Dotnet:

await popup.WaitForLoadStateAsync(LoadState.Networkidle)

https://playwright.dev/dotnet/docs/api/class-page#page-wait-for-load-state

JS:

await page.waitForLoadState("networkidle")

https://playwright.dev/docs/api/class-page#page-wait-for-load-state

unickq
  • 1,497
  • 12
  • 18