return context.pages[-1]
[docs]def create_async_playwright_browser(headless: bool = True) -> AsyncBrowser:
    """
    Create an async playwright browser.
    Args:
        headless: Whether to run the browser in headless mode. Defaults to True.
    Returns:
        AsyncBrowser: The playwright browser.
    """
    from playwright.async_api import async_playwright
    browser = run_async(async_playwright().start())
    return run_async(browser.chromium.launch(headless=headless))
[docs]def create_sync_playwright_browser(headless: bool = True) -> SyncBrowser:
    """
    Create a playwright browser.
    Args:
        headless: Whether to run the browser in headless mode. Defaults to True.
    Returns:
        SyncBrowser: The playwright browser.
    """
    from playwright.sync_api import sync_playwright
    browser = sync_playwright().start()
    return browser.chromium.launch(headless=headless)
T = TypeVar("T")
[docs]def run_async(coro: Coroutine[Any, Any, T]) -> T:
    """Run an async coroutine.
    Args:
        coro: The coroutine to run. Coroutine[Any, Any, T]
    Returns:
        T: The result of the coroutine.
    """
    event_loop = asyncio.get_event_loop()
    return event_loop.run_until_complete(coro)