chrome-php / chrome

Instrument headless chrome/chromium instances from PHP
MIT License
2.25k stars 276 forks source link

How to achieve a cyclic refresh of the page to obtain the latest content? #587

Open quyunet opened 9 months ago

quyunet commented 9 months ago

How to achieve a cyclic refresh of the page to obtain the latest content?

An error occurred in the following code.

$page->navigate($url)->waitForNavigation('DOMContentLoaded', 100000);
for($i=1;$i<=5;$i++){
  if($i > 1){
      $page->getSession()->sendMessageSync(new \HeadlessChromium\Communication\Message('Page.reload'));   //Refresh shopping cart
      //$page->navigate($url)->waitForNavigation();    //Method 2
  }
  $cartHTML = $page->getHtml();
  if(!strpos($cartHTML, 'product')){
       .....
       //asynchronous add shopingcart.
       continue;      //
  }
}

error: Fatal error: Uncaught HeadlessChromium\Exception\OperationTimedOut: Operation timed out after 5s. in D:\demo\vendor\chrome-php\chrome\src\Exception\OperationTimedOut.php:18 Stack trace:

0 D:\demo\vendor\chrome-php\chrome\src\Utils.php(67): HeadlessChromium\Exception\OperationTimedOut::createFromTimeout(5000000)

1 D:\demo\vendor\chrome-php\chrome\src\Communication\ResponseReader.php(114): HeadlessChromium\Utils::tryWithTimeout(5000000, Object(Generator))

2 D:\demo\vendor\chrome-php\chrome\src\PageUtils\PageEvaluation.php(77): HeadlessChromium\Communication\ResponseReader->waitForResponse(5000)

3 D:\demo\vendor\chrome-php\chrome\src\PageUtils\PageEvaluation.php(108): HeadlessChromium\PageUtils\PageEvaluation->waitForResponse(NULL)

4 D:\demo\myLibrary\includes\functions.php(68): HeadlessChromium\PageUtils\PageEvaluation->getReturnValue()

5 D:\demo\myLibrary\api\order.php(82): myOrder->newOrder()

6 {main}

thrown in D:\demo\vendor\chrome-php\chrome\src\Exception\OperationTimedOut.php on line 18

How to solve the problem of refreshing pages?

enricodias commented 9 months ago

Have you tried this?

$page->getSession()->sendMessageSync(new \HeadlessChromium\Communication\Message('Page.reload'));
$page->waitForNavigation('DOMContentLoaded');
quyunet commented 9 months ago
$page->waitForNavigation('DOMContentLoaded');

Fatal error: Uncaught Error: Call to undefined method HeadlessChromium\Page::waitForNavigation() in