mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-05-01 23:32:39 +00:00
feat: add crewai-tools library to workspace
- Migrate crewai-tools as standalone package in lib/tools - Configure UV workspace for monorepo structure - Move assets to repository root - Clean up duplicate README files - Focus pre-commit hooks on lib/crewai/src only
This commit is contained in:
43
lib/tools/src/crewai_tools/aws/bedrock/browser/utils.py
Normal file
43
lib/tools/src/crewai_tools/aws/bedrock/browser/utils.py
Normal file
@@ -0,0 +1,43 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Any, Union
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from playwright.async_api import Browser as AsyncBrowser
|
||||
from playwright.async_api import Page as AsyncPage
|
||||
from playwright.sync_api import Browser as SyncBrowser
|
||||
from playwright.sync_api import Page as SyncPage
|
||||
|
||||
|
||||
async def aget_current_page(browser: Union[AsyncBrowser, Any]) -> AsyncPage:
|
||||
"""
|
||||
Asynchronously get the current page of the browser.
|
||||
Args:
|
||||
browser: The browser (AsyncBrowser) to get the current page from.
|
||||
Returns:
|
||||
AsyncPage: The current page.
|
||||
"""
|
||||
if not browser.contexts:
|
||||
context = await browser.new_context()
|
||||
return await context.new_page()
|
||||
context = browser.contexts[0]
|
||||
if not context.pages:
|
||||
return await context.new_page()
|
||||
return context.pages[-1]
|
||||
|
||||
|
||||
def get_current_page(browser: Union[SyncBrowser, Any]) -> SyncPage:
|
||||
"""
|
||||
Get the current page of the browser.
|
||||
Args:
|
||||
browser: The browser to get the current page from.
|
||||
Returns:
|
||||
SyncPage: The current page.
|
||||
"""
|
||||
if not browser.contexts:
|
||||
context = browser.new_context()
|
||||
return context.new_page()
|
||||
context = browser.contexts[0]
|
||||
if not context.pages:
|
||||
return context.new_page()
|
||||
return context.pages[-1]
|
||||
Reference in New Issue
Block a user