Coverage for human_requests / human_browser.py: 71%
24 statements
« prev ^ index » next coverage.py v7.12.0, created at 2025-11-25 10:02 +0000
« prev ^ index » next coverage.py v7.12.0, created at 2025-11-25 10:02 +0000
1from __future__ import annotations
3from typing import Any, List, cast, override
5from playwright.async_api import Browser
7from .human_context import HumanContext
8from .human_page import HumanPage
11class HumanBrowser(Browser):
13 @staticmethod
14 def replace(playwright_browser: Browser) -> HumanBrowser:
15 playwright_browser.__class__ = HumanBrowser
16 return playwright_browser # type: ignore[return-value]
18 # ────── browser nav ──────
19 async def new_page(
20 self,
21 **kwargs: Any,
22 ) -> HumanPage:
23 page = await super().new_page(**kwargs)
24 HumanContext.replace(page.context)
25 return HumanPage.replace(page)
27 async def new_context(
28 self,
29 **kwargs: Any,
30 ) -> HumanContext:
31 ctx = await super().new_context(**kwargs)
32 return HumanContext.replace(ctx)
34 @property
35 @override
36 def contexts(self) -> List["HumanContext"]: # type: ignore[override]
37 ctxs = super().contexts
38 for c in ctxs:
39 HumanContext.replace(c)
40 return cast(List["HumanContext"], ctxs)