ddp_utils.browser.backends.playwright.launcher¶
import ddp_utils.browser.backends.playwright.launcher
Lazy lifecycle launcher for Playwright and Camoufox providers.
- class ddp_utils.browser.backends.playwright.launcher.PlaywrightBrowserLauncher(*, playwright_factory: Callable[[], Any] | None = None, camoufox_factory: Callable[[...], Any] | None = None, camoufox_preparer: Callable[[str], Any] | None = None)¶
Bases:
objectCreate or attach Playwright-family native objects with exact ownership.
Parameters
Name
Type
Description
playwright_factory
Callable[[], Any] | None
Optional
sync_playwrightreplacement for tests.camoufox_factory
Callable[..., Any] | None
Optional
Camoufoxreplacement for tests.camoufox_preparer
Callable[[str], Any] | None
Optional runtime-preparation replacement for tests.
Examples
Construct without importing optional browser dependencies:
launcher = PlaywrightBrowserLauncher()
Store optional dependency injection points without launching anything.
Parameters
Name
Type
Description
playwright_factory
Callable[[], Any] | None
Callable returning a Playwright manager.
camoufox_factory
Callable[..., Any] | None
Callable returning a Camoufox context manager.
camoufox_preparer
Callable[[str], Any] | None
Callable validating Camoufox’s browser binary.
Examples
Inject deterministic fakes for lifecycle tests:
launcher = PlaywrightBrowserLauncher( playwright_factory=fake_sync_playwright )
- launch(config: BrowserConfig, options: PlaywrightLaunchOptions, *, provider: str) PlaywrightNativeObjects¶
Launch the selected provider or attach to an existing browser.
Parameters
Name
Type
Description
config
Validated neutral browser configuration.
options
Strict provider-specific options.
provider
str
Concrete
playwrightorcamoufoxprovider.Returns
Type
Description
Native objects with explicit resource-ownership flags.
Raises
Exception
Description
The requested combination is impossible.
Optional imports or provider startup fail.
Examples
Launch after the backend validates its identity:
native = launcher.launch(config, options, provider="playwright")