Skip to content

Ucd cci feature/interactive sessions#190

Merged
Rafiot merged 13 commits intomainfrom
UCD-CCI-feature/interactive-sessions
Apr 10, 2026
Merged

Ucd cci feature/interactive sessions#190
Rafiot merged 13 commits intomainfrom
UCD-CCI-feature/interactive-sessions

Conversation

@Rafiot
Copy link
Copy Markdown
Member

@Rafiot Rafiot commented Apr 6, 2026

@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.

DocArmoryTech and others added 13 commits April 3, 2026 10:09
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.
@Rafiot Rafiot merged commit 319c2b4 into main Apr 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants