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: object

Create or attach Playwright-family native objects with exact ownership.

Parameters

Name

Type

Description

playwright_factory

Callable[[], Any] | None

Optional sync_playwright replacement for tests.

camoufox_factory

Callable[..., Any] | None

Optional Camoufox replacement 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

BrowserConfig

Validated neutral browser configuration.

options

PlaywrightLaunchOptions

Strict provider-specific options.

provider

str

Concrete playwright or camoufox provider.

Returns

Type

Description

PlaywrightNativeObjects

Native objects with explicit resource-ownership flags.

Raises

Exception

Description

BrowserConfigurationError

The requested combination is impossible.

BrowserStartupError

Optional imports or provider startup fail.

Examples

Launch after the backend validates its identity:

native = launcher.launch(config, options, provider="playwright")