Merged
Conversation
Split `capture_page` into two helper functions to reduce duplication and make the capture lifecycle easier to follow: * `setup_page_capture()`: gathers per-page event wiring that was previously inline in `capture_page`. This includes download tracking, request-body storage for favicon extraction, dialog acceptance, and the headless-Chromium PDF workaround. Returns a `PageCaptureState` TypedDict so that the same state can be passed to finalization without relying on closure variables. * `_finalize_capture()`: consolidates post-navigation teardown formerly in `capture_page`’s `finally` block. This handles multiple-download deduplication/zip, cookie and storage collection, page/context shutdown, HAR loading, SOCKS5 IP resolution, and trusted-timestamp requests. `capture_page` now delegates to these helpers; observable behavior remains unchanged. The `PageCaptureState` TypedDict and the `Awaitable`/`Callable`/`Mapping` imports required for its annotations are added in this commit. No feature changes are included in this refactor.
`Capture.__init__` now accepts an optional `display` parameter (default `None`). When provided, `__aenter__` constructs a per-launch environment dictionary that overrides `DISPLAY`, allowing each concurrent interactive session to target its own X11 server without modifying the process-global `os.environ`. A new `capture_current_page()` method captures the current page state without navigating or recursing into child URLs. It reuses `setup_page_capture` (called by the caller before navigation) and the existing `_finalize_capture` workflow for cookies, storage, HAR, and trusted timestamps. This method serves as the final-capture step when an interactive session signals it is ready.
…nch signature The env parameter of BrowserType.launch() expects dict[str, str | float | bool] | None, not dict[str, str] | None. Widen the launch_env annotation to satisfy mypy --strict.
Align keyword-only parameter defaults with the rest of the codebase (no spaces around '=').
…_current_page When the bare 'except Exception' handler re-raises, _finalize_capture was skipped because it was called sequentially after the try/except rather than in a finally block. This left the page/context unclosed and the HAR file unflushed. Wrap the try/except in an outer try/finally, matching the pattern already used by capture_page.
Remove `_coerce_cookie_mapping()` and rely on the `lookyloo-models` `Cookie` model to handle normalization.
…nt_page - Replace `PageCaptureState` `TypedDict` with instance attributes (`_multiple_downloads`, `_store_request`, `_mark_favicons_done`) on `Capture`. - `setup_page_capture()` now returns `None` and `_finalize_capture()` reads from `self`. - Make `url` optional and add `current_page_only` flag to `capture_page()` - when `True`, the method snapshots the page as-is without navigation. - Delete the now-redundant `capture_current_page()` method.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@DocArmoryTech I did some heavy refactoring in your PR, I hope you don't mind. It is mostly to make the code leaner, there were a few bits that I missed with the Pydantic models, and I think some of the code you implemented in LacusCore make more sense in this library instead.
I'm pretty sure breaks your PR against LacusCore, sorry. If you have time and want to adapt the LacusCore PR accordingly, I'm happy to let you do it, but I also totally understand if prefer me to deal with it.