chrome-php / chrome

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

[Question] How to close all opened browsers #585

Closed batata004 closed 6 months ago

batata004 commented 6 months ago

Hi,

Sometimes I execute createBrowser and forget to execute $browser->close();. When I check Task Manager, I see dozens and dozens of Chrome processes opened. I need to killall using command line. So I was wondering: is there a way I can kill all those headless browsers that were opened previously using your library? Or the only way is indeed using command line to kill all chrome processes?

enricodias commented 6 months ago

If the php script finishes executing without closing the browser, it looses the reference to the chrome process. You could put your code inside a try clause and put the $browser->close(); code in the finally clause to make sure it runs every time. When developing and debugging, using unit tests is easier.

batata004 commented 6 months ago

Thank you so much!!!!