Skip to content

Commit

Permalink
Apply page load timeout from when page starts loading
Browse files Browse the repository at this point in the history
If there's an error during waitForLoad (e.g. due to chrome crash
or just brokenness) in the scenario, and then hooks also need
to run things that waitForLoad, it was getting the timeout for
each waitForLoad call.

But actually pageload timeout should just be from the time it
started loading, so subsequent (e.g. ->getCurrentUrl()) get an
almost immediate timeout rather than giving it another
30 seconds.
  • Loading branch information
acoulton committed Sep 15, 2022
1 parent 596f43a commit 0af4e15
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/ChromePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class ChromePage extends DevToolsConnection

private bool $is_recovering_from_crash = false;

private ?\DateTimeImmutable $page_ready_timeout = NULL;

public function __construct(
private string $window_id,
$url,
Expand Down Expand Up @@ -57,13 +59,11 @@ public function waitForLoad()
{
if (!$this->page_ready) {
try {
// @todo: need a better way of setting the timeout expiry based on the start of pageload rather than specific call
$timeout = new \DateTimeImmutable('+30 seconds');
$this->waitFor(function () {
return $this->page_ready;
},
'wait-for-load',
$timeout
$this->page_ready_timeout
);
} catch (DriverException $exception) {
// This could then be decorated with more detail on what we're waiting for
Expand Down Expand Up @@ -314,6 +314,13 @@ private function setPageReady(bool $state, string $change_trigger): void
if (!$state) {
// Clear the response ahead of loading a new doc
$this->response = null;
// Set a timeout from when the page went "not ready" so it's not affected by multiple calls to waitForLoad
// e.g. after an exception during loading the page.
// @todo: pageload expiry time should be configurable
$this->page_ready_timeout = new \DateTimeImmutable('+30 seconds');
} else {
// Clear the timeout for the next load
$this->page_ready_timeout = NULL;
}
$this->logger->logPageReadyStateChange($state, $change_trigger);
$this->page_ready = $state;
Expand Down

0 comments on commit 0af4e15

Please sign in to comment.