microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
65.93k stars 3.59k forks source link

[Bug]: page.waitForLoadState api not behaving as per expectation #32751

Open ThatYodaCoder opened 6 days ago

ThatYodaCoder commented 6 days ago

Version

1.44.1

Steps to reproduce

Page does not wait for load state, but when I do page.content I get page is still navigating error.

can't post the actual page due some issues. But this is happening frequently.

1) Why waitFor load state does not wait ? What is the exact behaviour of this api. From doc its not clear.

I open an html form in browser which trigger a url which in turn trigger many more urls.

2) How do I know in this case that my page is loaded completely?

code I am using

page.waitForResponse("url", options, ()->page.setContent(html))
page.waitForLoadState(LoadState.LOAD, new Page.WaitForLoadStateOptions().setTimeout(30000));
page.content()
com.microsoft.playwright.PlaywrightException: Error {
  message='Unable to retrieve content because the page is navigating and changing the content.
  name='Error
  stack='Error: Unable to retrieve content because the page is navigating and changing the content.
    at Frame.content (/private/var/folders/2t/_wf5dp41445ggspsmp9ymjsrb9bjrn/T/playwright-java-16743717214464829023/package/lib/server/frames.js:755:13)
    at async FrameDispatcher.content (/private/var/folders/2t/_wf5dp41445ggspsmp9ymjsrb9bjrn/T/playwright-java-16743717214464829023/package/lib/server/dispatchers/frameDispatcher.js:140:14)
    at async LongStandingScope._race (/private/var/folders/2t/_wf5dp41445ggspsmp9ymjsrb9bjrn/T/playwright-java-16743717214464829023/package/lib/utils/manualPromise.js:96:14)
    at async FrameDispatcher._handleCommand (/private/var/folders/2t/_wf5dp41445ggspsmp9ymjsrb9bjrn/T/playwright-java-16743717214464829023/package/lib/server/dispatchers/dispatcher.js:96:14)
    at async DispatcherConnection.dispatch (/private/var/folders/2t/_wf5dp41445ggspsmp9ymjsrb9bjrn/T/playwright-java-16743717214464829023/package/lib/server/dispatchers/dispatcher.js:361:22)

Expected behavior

page should wait for loading all resources

Actual behavior

com.microsoft.playwright.PlaywrightException: Error {
  message='Unable to retrieve content because the page is navigating and changing the content.
  name='Error
  stack='Error: Unable to retrieve content because the page is navigating and changing the content.
    at Frame.content (/private/var/folders/2t/_wf5dp41445ggspsmp9ymjsrb9bjrn/T/playwright-java-16743717214464829023/package/lib/server/frames.js:755:13)
    at async FrameDispatcher.content (/private/var/folders/2t/_wf5dp41445ggspsmp9ymjsrb9bjrn/T/playwright-java-16743717214464829023/package/lib/server/dispatchers/frameDispatcher.js:140:14)
    at async LongStandingScope._race (/private/var/folders/2t/_wf5dp41445ggspsmp9ymjsrb9bjrn/T/playwright-java-16743717214464829023/package/lib/utils/manualPromise.js:96:14)
    at async FrameDispatcher._handleCommand (/private/var/folders/2t/_wf5dp41445ggspsmp9ymjsrb9bjrn/T/playwright-java-16743717214464829023/package/lib/server/dispatchers/dispatcher.js:96:14)
    at async DispatcherConnection.dispatch (/private/var/folders/2t/_wf5dp41445ggspsmp9ymjsrb9bjrn/T/playwright-java-16743717214464829023/package/lib/server/dispatchers/dispatcher.js:361:22)

Additional context

No response

Environment

linux focal image
yury-s commented 4 days ago

can't post the actual page due some issues. But this is happening frequently.

Unfortunately, we cannot debug this without a repro. From the description it looks like the page keeps navigating (can't tell without a repro if it's the same document or a different) and Playwright is working as expected. Please share are repro which we could run locally.