From 5cda60de24bdefad4ffddc65eb7f731565053465 Mon Sep 17 00:00:00 2001 From: acoulton Date: Tue, 10 May 2022 09:51:06 +0100 Subject: [PATCH] Fix detecting "page load" after internal navigation If you click (or do) anything that causes the URL to change either with e.g. history.replaceState or by clicking a link to #wherever on the same doc, Chrome sends: - Page.frameStartedLoading - Page.navigatedWithinDocument - Page.frameStoppedLoading But obviously there is no new Page.loadEventFired. So, for the moment we need to treat Page.navigatedWithinDocument as being the equivalent to loadEventFired. It may actually be better to use Page.frameStoppedLoading if we always get that, then there's a simple startedLoading / stoppedLoading pair? --- src/ChromePage.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/ChromePage.php b/src/ChromePage.php index 42d4f62..f28dbe1 100644 --- a/src/ChromePage.php +++ b/src/ChromePage.php @@ -179,7 +179,22 @@ protected function processResponse(array $data): void } break; case 'Page.navigatedWithinDocument': - // Can't see this doing anything if we're only starting the pageload on the networky events + // On a same-page navigation in at least some instances - e.g. in the flickr photoset page where it + // uses history.replaceState - you get: + // - potentially some animationy stuff + // - Page.frameStartedLoading + // - Page.navigatedWithinDocument + // - Page.frameStoppedLoading + + // But no Page.loadEventFired. + // At the moment I'm marking page_ready = False on Page.frameStartedLoading, so need to clear it + // here. If I used Page.frameStoppedLoading instead of Page.loadEventFired this would maybe not + // be necessary. + // This is another example where we want click-> to wait a bit to see if something happens, but + // it can't just wait for readyState to change because that may not change (it doesn't in this case). + if ($data['params']['frameId'] === $this->window_id) { + $this->setPageReady(TRUE, $data['method']); + } break; case 'Page.loadEventFired':