WaitForNavigationAsync should resolve if Frame already has requested lifecycle
See original GitHub issueI expect that calling:
await page.WaitForNavigationAsync();
would resolve immediately if the page have already collected ‘load’ lifecycle event before. Also, I expect the following sequence should complete successfully instead of hanging forever as it does currently with version 5.1.0 of puppeteer-sharp:
await page.GoToAsync(url, WaitUntilNavigation.DOMContentLoaded);
await page.WaitForNavigationAsync();
As a workaround for my project I slightly modified FrameManager.cs lines 149-164 to be:
public async Task<Response> WaitForFrameNavigationAsync(Frame frame, NavigationOptions options = null)
{
var timeout = options?.Timeout ?? TimeoutSettings.NavigationTimeout;
using (var watcher = new LifecycleWatcher(this, frame, options?.WaitUntil, timeout))
{
var raceTask = await Task.WhenAny(
watcher.NewDocumentNavigationTask,
watcher.SameDocumentNavigationTask,
watcher.LifecycleTask, // <-- add this line to resolve lifecycle events without waiting for actual navigation
watcher.TimeoutOrTerminationTask).ConfigureAwait(false);
await raceTask.ConfigureAwait(false);
return watcher.NavigationResponse;
}
}
Please check if it may be acceptable fix for public, or maybe a separate method for waiting for lifecycle events without doing actual navigation should be added.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Use PuppeteerSharp.Frame.NavigatedWithinDocument in ...
Use the NavigatedWithinDocument method in PuppeteerSharp package in your next Puppeteer-sharp project with LambdaTest Automation Testing Advisor.
Read more >Frame | Playwright .NET
Frame object's lifecycle is controlled by three events, dispatched on the page ... If current document has already reached the required state, resolves...
Read more >Untitled
WaitForNavigationAsync should resolve if Frame already has requested lifecycle #1841. evaluate resolves to undefined. Until(driver => driver.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The most common pattern is doing something like this:
I think that with the change you’re suggesting,
WaitForNavigationAsync
will immediately be resolved, breaking that pattern.High chances you can reproduce the issue with this simple test:
You’ll catch all DOMContentloaded but only few Load events…