chrome-php / chrome

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

Wait for iframe #640

Open andreas-globi opened 1 month ago

andreas-globi commented 1 month ago

In the man DOM, you can use JS to click on an element, and use waitForPageReload() to wait for the reload to complete

eg:

$page->evaluate($code)->waitForPageReload();

But if you're clicking on an element in an iframe that causes the iframe to reload, waitForPageReload() won't work because the main page doesn't reload.

waitForResponse() doesn't work either, because the next call could be broken due to the iframe reloading.

How can we evaluate() and then wait for the iframe to reload?

enricodias commented 1 month ago

I don't think iframes fire onload events or anything similar. You would have to inspect the iframe's content manually in a loop until the info you are looking for gets loaded there.

andreas-globi commented 1 month ago

That's what I'm trying.

The issue though is that occasionally an exception is thrown while evaluating when the evaluate call is made DURING the iframe reload.

I get the same issue with the main page, but waitForPageReload() fixes it there.

I guess I could just try catch the iframe evals until a timeout is hit.