@@ -61,23 +61,16 @@ class AsyncDendrite(
6161 AsyncDendrite is a class that manages a browser instance using Playwright, allowing
6262 interactions with web pages using natural language.
6363
64- This class handles initialization with API keys for Dendrite, OpenAI, and Anthropic, manages browser
65- contexts, and provides methods for navigation, authentication, and other browser-related tasks.
64+ This class handles initialization with configuration options, manages browser contexts,
65+ and provides methods for navigation, authentication, and other browser-related tasks.
6666
6767 Attributes:
68- id (UUID): The unique identifier for the AsyncDendrite instance.
69- auth_data (Optional[AuthSession]): The authentication session data for the browser.
70- dendrite_api_key (str): The API key for Dendrite, used for interactions with the Dendrite API.
71- playwright_options (dict): Options for configuring the Playwright browser instance.
72- playwright (Optional[Playwright]): The Playwright instance managing the browser.
68+ id (str): The unique identifier for the AsyncDendrite instance.
7369 browser_context (Optional[BrowserContext]): The current browser context, which may include cookies and other session data.
7470 active_page_manager (Optional[PageManager]): The manager responsible for handling active pages within the browser context.
7571 user_id (Optional[str]): The user ID associated with the browser session.
76- browser_api_client (BrowserAPIClient): The API client used for communicating with the Dendrite API.
77- api_config (APIConfig): The configuration for the language models, including API keys for OpenAI and Anthropic.
78-
79- Raises:
80- Exception: If any of the required API keys (Dendrite, OpenAI, Anthropic) are not provided or found in the environment variables.
72+ logic_engine (AsyncLogicEngine): The engine used for processing natural language interactions.
73+ closed (bool): Whether the browser instance has been closed.
8174 """
8275
8376 def __init__ (
@@ -94,10 +87,14 @@ def __init__(
9487 Initialize AsyncDendrite with optional domain authentication.
9588
9689 Args:
97- playwright_options: Options for configuring Playwright
98- remote_config: Remote browser provider configuration
99- config: Configuration object
100- auth: List of domains or single domain to load authentication state for
90+ playwright_options (dict): Options for configuring Playwright browser instance.
91+ Defaults to non-headless mode with stealth arguments.
92+ remote_config (Optional[Providers]): Remote browser provider configuration.
93+ Defaults to None for local browser.
94+ config (Optional[Config]): Configuration object for the instance.
95+ Defaults to a new Config instance.
96+ auth (Optional[Union[List[str], str]]): List of domains or single domain
97+ to load authentication state for. Defaults to None.
10198 """
10299 self ._impl = self ._get_impl (remote_config )
103100 self ._playwright_options = playwright_options
@@ -195,19 +192,23 @@ async def goto(
195192 expected_page : str = "" ,
196193 ) -> AsyncPage :
197194 """
198- Navigates to the specified URL, optionally in a new tab
195+ Navigates to the specified URL, optionally in a new tab.
199196
200197 Args:
201- url (str): The URL to navigate to.
202- new_tab (bool, optional): Whether to open the URL in a new tab. Defaults to False.
203- timeout (Optional[float], optional): The maximum time (in milliseconds) to wait for the page to load. Defaults to 15000.
204- expected_page (str, optional): A description of the expected page type for verification. Defaults to an empty string.
198+ url (str): The URL to navigate to. If no protocol is specified, https:// will be added.
199+ new_tab (bool): Whether to open the URL in a new tab. Defaults to False.
200+ timeout (Optional[float]): The maximum time in milliseconds to wait for navigation.
201+ Defaults to 15000ms. Navigation will continue even if timeout occurs.
202+ expected_page (str): A description of the expected page type for verification.
203+ If provided, will verify the loaded page matches the description.
204+ Defaults to empty string (no verification).
205205
206206 Returns:
207207 AsyncPage: The page object after navigation.
208208
209209 Raises:
210- Exception: If there is an error during navigation or if the expected page type is not found.
210+ IncorrectOutcomeError: If expected_page is provided and the loaded page
211+ doesn't match the expected description.
211212 """
212213 # Check if the URL has a protocol
213214 if not re .match (r"^\w+://" , url ):
@@ -245,8 +246,13 @@ async def scroll_to_bottom(
245246 """
246247 Scrolls to the bottom of the current page.
247248
248- Returns:
249- None
249+ Args:
250+ timeout (float): Maximum time in milliseconds to attempt scrolling.
251+ Defaults to 30000ms.
252+ scroll_increment (int): Number of pixels to scroll in each step.
253+ Defaults to 1000 pixels.
254+ no_progress_limit (int): Number of consecutive attempts with no progress
255+ before stopping. Defaults to 3 attempts.
250256 """
251257 active_page = await self .get_active_page ()
252258 await active_page .scroll_to_bottom (
@@ -305,10 +311,12 @@ async def add_cookies(self, cookies):
305311 Adds cookies to the current browser context.
306312
307313 Args:
308- cookies (List[Dict[str, Any]]): A list of cookies to be added to the browser context.
314+ cookies (List[Dict[str, Any]]): A list of cookie objects to be added.
315+ Each cookie should be a dictionary with standard cookie attributes
316+ (name, value, domain, etc.).
309317
310318 Raises:
311- Exception : If the browser context is not initialized.
319+ DendriteException : If the browser context is not initialized.
312320 """
313321 if not self .browser_context :
314322 raise DendriteException ("Browser context not initialized" )
@@ -446,8 +454,16 @@ async def save_auth(self, url: str) -> None:
446454 """
447455 Save authentication state for a specific domain.
448456
457+ This method captures and stores the current browser context's storage state
458+ (cookies and origin data) for the specified domain. The state can be later
459+ used to restore authentication.
460+
449461 Args:
450- domain (str): Domain to save authentication for (e.g., "github.com")
462+ url (str): URL or domain to save authentication for (e.g., "github.com"
463+ or "https://github.com"). The domain will be extracted from the URL.
464+
465+ Raises:
466+ DendriteException: If the browser context is not initialized.
451467 """
452468 if not self .browser_context :
453469 raise DendriteException ("Browser context not initialized" )
@@ -482,11 +498,15 @@ async def setup_auth(
482498 message : str = "Please log in to the website. Once done, press Enter to continue..." ,
483499 ) -> None :
484500 """
485- Set up authentication for a specific URL.
501+ Set up authentication for a specific URL by guiding the user through login.
502+
503+ This method opens a browser window, navigates to the specified URL, waits for
504+ the user to complete the login process, and then saves the authentication state.
486505
487506 Args:
488507 url (str): URL to navigate to for login
489- message (str): Message to show while waiting for user input
508+ message (str): Message to show while waiting for user to complete login.
509+ Defaults to standard login instruction message.
490510 """
491511 # Extract domain from URL
492512 # domain = urlparse(url).netloc
0 commit comments