go-rod / rod

A Chrome DevTools Protocol driver for web automation and scraping.
https://go-rod.github.io
MIT License
5k stars 328 forks source link

Feat: Add the PagePool.TryGet method while it returns an error for processing. #1051

Closed zeoxisca closed 1 month ago

zeoxisca commented 2 months ago

Development guide

Link

Test on local before making the PR

go run ./lib/utils/simple-check

PagePool Change

The PagePool.Get can now only accept create func() *Page as input, so there is no way to output the error that may exist in the create func other than using a closure or using recover, and it is inconvenient for users in a multi-routine environment to perform logical processing based on the actual error that occurred. I added the PagePool.MustGet method to solve this. However, I'm not sure whether this change would be in line with the original design.

Besides, PagePool.CleanUp may stuck while pp is not full (forget/panic to Put, etc). I also think this might be an issue when using PagePool. Use select to prevent stucking