chrome-php / chrome

Instrument headless chrome/chromium instances from PHP
MIT License
2.2k stars 269 forks source link

Fix could not find node with given id #620

Open Seriyyy95 opened 2 months ago

Seriyyy95 commented 2 months ago

It is a fix for issue 469

Previously, a new Dom instance was created for each call of $page->dom(). In this pull request, I have stored $dom as a variable in the Page class and added an auto-update of the root node id using the DOM.documentUpdated event. 

I use waitForData() from upcoming chrome-php/wrench 1.7 to process all events before each request without blocking execution if there is no data to process. When the page is refreshed in Chrome, chrome-php will be notified about it before making any requests. Somehow, Chrome fires two DOM.documentUpdated events during one reload, so I decided to not fetch the node ID in the event handler but just mark the node as stale and request a new node ID before making a request if the old one is stale.