feat: Add page lifecycle hooks to `BrowserPool` by Mantisus · Pull Request #1791 · apify/crawlee-python
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds four page lifecycle hooks to BrowserPool — pre_page_create_hook, post_page_create_hook, pre_page_close_hook, and post_page_close_hook — registered as decorators, aligning Python's BrowserPool closer to the JS Crawlee browser pool API as described in issue #1741.
Changes:
- Four hook registration methods added to
BrowserPool, each appending user-provided async callables to internal lists that are executed at the corresponding lifecycle point. - Close hooks are implemented by monkey-patching
page.closevia_override_page_closeafter page creation. - Comprehensive tests covering individual hook invocation, execution order, argument validation, and multiple hook registration.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/crawlee/browsers/_browser_pool.py |
Adds hook storage lists, _execute_hooks helper, _override_page_close for close hooks, and four public hook registration methods with docstrings. |
tests/unit/browsers/test_browser_pool.py |
Adds six tests covering each hook type, execution order, and multiple hook registration. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.