aeat.adapters.outbound.aeat.browser._factory module¶
Default Playwright browser-session factory for auth providers.
Auth providers accept a
adapters.outbound.aeat.auth.BrowserSessionFactory: an async
callable that returns a
adapters.outbound.aeat.auth.BrowserSessionLike. The default
factory supplies that protocol with a Playwright-backed BrowserSession,
while adapters.outbound.aeat.auth.select_provider() still accepts
browser_session_factory=None so tests and callers can inject their own
in-process implementations.
This module provides:
DefaultBrowserSession, theBrowserSessionLikewrapper that owns aPlaywrightruntime andBrowserSessionpair.default_browser_session_factory(), the productionBrowserSessionFactoryentry point used by auth providers and diagnostics.shared_playwright_runtime()andopened_browser_page(), the lower-level helpers used by bulk Sede readers that need to reuse one Playwright runtime across severalProfile-scoped contexts.
The factory path owns Playwright startup, optional browser extra checks, and
best-effort teardown logging. Auth providers remain typed to the protocol, while
this module carries the concrete runtime wiring.
- class DefaultBrowserSession(playwright, session)[source]¶
Bases:
objectConcrete
BrowserSessionLike.Auth providers depend on the protocol rather than on
BrowserSessionor Playwright directly.DefaultBrowserSessionis the production adapter for that protocol: it owns one Playwright runtime, oneBrowserSession, and aProfilethrough the wrapped session. Itsclose()method tears the pair down in order, so providerclose()paths do not need a second runtime-specific hook.- Parameters:
playwright (Playwright)
session (BrowserSession)
- async create_context(*, provisioner=None, storage_state_path=None, storage_state=None)[source]¶
Delegate context creation to the underlying
BrowserSession.Accepts the same keyword arguments as
BrowserSession.create_context()and forwards them unchanged, so certificate provisioners and persisted Cl@ve storage state use the same path as callers that work withBrowserSessiondirectly.
Navigate through
BrowserSession.navigate().
- async default_browser_session_factory(settings)[source]¶
Start Playwright and return a wrapped
DefaultBrowserSession.The returned object satisfies
adapters.outbound.aeat.auth.BrowserSessionLikeand owns its Playwright runtime for the full lifetime. TheProfilename follows the active bucket when one exists and falls back to a diagnostic sentinel so browser connectivity probes can run before profile setup is complete.Auth providers pass their own kind-namespaced storage-state paths to
BrowserSession.create_context(); the profile storage path built here is only the fallback for direct callers. Callawait session.close()when you are done. Auth providers already do that in theirclose()path.- Return type:
- Parameters:
settings (Settings)
- async create_browser_session(settings, profile)[source]¶
Start Playwright and return a
DefaultBrowserSession.Wraps a
BrowserSessionforprofileafter the optionalbrowserextra has been checked by_start_playwright. If wrapper construction fails after Playwright starts, the partially opened runtime is stopped before the original failure is re-raised.- Return type:
- Parameters:
Yield a centrally owned Playwright runtime for bulk browser workflows.
Callers that need several
Profile-scoped contexts can start Playwright once here and pass the yielded runtime intoopened_browser_page(). The context manager owns only the Playwright runtime; each page/context pair is still owned by the helper that opens it.- Return type:
AsyncIterator[Playwright]
- opened_browser_page(playwright, settings, profile, *, provisioner=None, storage_state_path=None, storage_state=None)[source]¶
Yield a
BrowserSessionpage/context pair and close both.The helper builds a short-lived
BrowserSessionaround the supplied Playwright runtime, forwardsprovisionerand storage-state arguments toBrowserSession.create_context(), yields the fresh(page, context)pair, and closes the context and browser session during teardown.