chrome-php / chrome

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

Redirects and difference between headless on and off #625

Closed consigliere23 closed 4 months ago

consigliere23 commented 4 months ago

How to follow redirects? Can we say when page is loaded fully-u to wait couple of seconds (until some JS is executed)?

I have one more question, what's the difference between headless true and false? If I set it to false, it should work same as with headless = true? I am having issue with one site, when headless is false it works, and if true it does not work?

enricodias commented 4 months ago

It's a real browser, it will follow any redirect by default. You can wait a couple of seconds manually in your php code, but you can't listen for the execution of a specific js in the browser.

The headless option enables or disables the browser UI. Some sites may try to detect this to prevent bots.

consigliere23 commented 4 months ago

Yes thanks, that's what I thought. How to set manually in code to wait? Just sleep or there is some method for it? As I need to wait ajax requests on page to finish in order to get html when these js are executed. One more question, is there any option to get get page status code?

enricodias commented 4 months ago

You can wait with using sleep or use the method Page::waitUntilContainsElement if the script you are waiting happens to create a new element on the page.

To get the page status code, see #41

consigliere23 commented 4 months ago

@enricodias thanks