Skip to content

Commit

Permalink
[1.9] Fix rare crash in getHtml (#516)
Browse files Browse the repository at this point in the history
For a split second, documentElement might be missing, causing getHtml() to crash.
  • Loading branch information
divinity76 authored May 4, 2023
1 parent c3a3652 commit ab591af
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -887,10 +887,20 @@ public function setHtml(string $html, int $timeout = 3000, string $eventName = s
* Gets the raw html of the current page.
*
* @throws CommunicationException
* @throws JavascriptException
*/
public function getHtml(?int $timeout = null): string
{
return $this->evaluate('document.documentElement.outerHTML')->getReturnValue($timeout);
try {
return $this->evaluate('document.documentElement.outerHTML')->getReturnValue($timeout);
} catch (JavascriptException $e) {
if (0 === \strpos($e->getMessage(), 'Error during javascript evaluation: TypeError: Cannot read properties of null (reading \'outerHTML\')')) {
\usleep(1000);

return $this->evaluate('document.documentElement.outerHTML')->getReturnValue($timeout);
}
throw $e;
}
}

/**
Expand Down

0 comments on commit ab591af

Please sign in to comment.