Skip to content

Commit ab591af

Browse files
authored
[1.9] Fix rare crash in getHtml (#516)
For a split second, documentElement might be missing, causing getHtml() to crash.
1 parent c3a3652 commit ab591af

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/Page.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,10 +887,20 @@ public function setHtml(string $html, int $timeout = 3000, string $eventName = s
887887
* Gets the raw html of the current page.
888888
*
889889
* @throws CommunicationException
890+
* @throws JavascriptException
890891
*/
891892
public function getHtml(?int $timeout = null): string
892893
{
893-
return $this->evaluate('document.documentElement.outerHTML')->getReturnValue($timeout);
894+
try {
895+
return $this->evaluate('document.documentElement.outerHTML')->getReturnValue($timeout);
896+
} catch (JavascriptException $e) {
897+
if (0 === \strpos($e->getMessage(), 'Error during javascript evaluation: TypeError: Cannot read properties of null (reading \'outerHTML\')')) {
898+
\usleep(1000);
899+
900+
return $this->evaluate('document.documentElement.outerHTML')->getReturnValue($timeout);
901+
}
902+
throw $e;
903+
}
894904
}
895905

896906
/**

0 commit comments

Comments
 (0)