# scraper2_hj3415/app/nfs/adapters/out/playwright/capabilities/_base.py
from __future__ import annotations

from logging_hj3415 import logger
from playwright.async_api import Page


class _PlaywrightBase:
    _page: Page

    def __init__(self, page: Page):
        self._page = page

    async def _wait_for_network_quiet(self, *, timeout_ms: int = 10_000) -> None:
        # networkidle은 사이트에 따라 영원히 안 올 수도 있어서 try로 감싸는 게 안전
        logger.debug("wait for network quiet")
        try:
            await self._page.wait_for_load_state("networkidle", timeout=timeout_ms)
        except Exception:
            # networkidle이 안 와도 다음 단계(앵커 wait)가 더 중요함
            return

    async def wait_attached(self, selector: str) -> None:
        raise NotImplementedError
