From 1db982d572bd7f71ad8de399778a8f2e1fc46bf4 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Wed, 6 Nov 2024 05:26:54 -0500 Subject: [PATCH 1/2] Wait for events to be processed instead of sleeping in getHtml --- src/Page.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Page.php b/src/Page.php index 1192258..a9c0ddf 100644 --- a/src/Page.php +++ b/src/Page.php @@ -944,7 +944,8 @@ public function getHtml(?int $timeout = null): string 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); + + $this->getSession()->getConnection()->processAllEvents(); return $this->evaluate('document.documentElement.outerHTML')->getReturnValue($timeout); } From 30f902da96112b13f34ae509e8e7f95c03fbf619 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Wed, 6 Nov 2024 05:30:33 -0500 Subject: [PATCH 2/2] Update Page.php --- src/Page.php | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/Page.php b/src/Page.php index a9c0ddf..116b6eb 100644 --- a/src/Page.php +++ b/src/Page.php @@ -940,17 +940,9 @@ public function setHtml(string $html, int $timeout = 3000, string $eventName = s */ public function getHtml(?int $timeout = null): string { - 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\')')) { + $this->getSession()->getConnection()->processAllEvents(); - $this->getSession()->getConnection()->processAllEvents(); - - return $this->evaluate('document.documentElement.outerHTML')->getReturnValue($timeout); - } - throw $e; - } + return $this->evaluate('document.documentElement.outerHTML')->getReturnValue($timeout); } /**