@@ -61,23 +61,16 @@ class AsyncDendrite(
61
61
AsyncDendrite is a class that manages a browser instance using Playwright, allowing
62
62
interactions with web pages using natural language.
63
63
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.
66
66
67
67
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.
73
69
browser_context (Optional[BrowserContext]): The current browser context, which may include cookies and other session data.
74
70
active_page_manager (Optional[PageManager]): The manager responsible for handling active pages within the browser context.
75
71
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.
81
74
"""
82
75
83
76
def __init__ (
@@ -94,10 +87,14 @@ def __init__(
94
87
Initialize AsyncDendrite with optional domain authentication.
95
88
96
89
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.
101
98
"""
102
99
self ._impl = self ._get_impl (remote_config )
103
100
self ._playwright_options = playwright_options
@@ -195,19 +192,23 @@ async def goto(
195
192
expected_page : str = "" ,
196
193
) -> AsyncPage :
197
194
"""
198
- Navigates to the specified URL, optionally in a new tab
195
+ Navigates to the specified URL, optionally in a new tab.
199
196
200
197
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).
205
205
206
206
Returns:
207
207
AsyncPage: The page object after navigation.
208
208
209
209
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.
211
212
"""
212
213
# Check if the URL has a protocol
213
214
if not re .match (r"^\w+://" , url ):
@@ -245,8 +246,13 @@ async def scroll_to_bottom(
245
246
"""
246
247
Scrolls to the bottom of the current page.
247
248
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.
250
256
"""
251
257
active_page = await self .get_active_page ()
252
258
await active_page .scroll_to_bottom (
@@ -305,10 +311,12 @@ async def add_cookies(self, cookies):
305
311
Adds cookies to the current browser context.
306
312
307
313
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.).
309
317
310
318
Raises:
311
- Exception : If the browser context is not initialized.
319
+ DendriteException : If the browser context is not initialized.
312
320
"""
313
321
if not self .browser_context :
314
322
raise DendriteException ("Browser context not initialized" )
@@ -446,8 +454,16 @@ async def save_auth(self, url: str) -> None:
446
454
"""
447
455
Save authentication state for a specific domain.
448
456
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
+
449
461
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.
451
467
"""
452
468
if not self .browser_context :
453
469
raise DendriteException ("Browser context not initialized" )
@@ -482,11 +498,15 @@ async def setup_auth(
482
498
message : str = "Please log in to the website. Once done, press Enter to continue..." ,
483
499
) -> None :
484
500
"""
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.
486
505
487
506
Args:
488
507
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.
490
510
"""
491
511
# Extract domain from URL
492
512
# domain = urlparse(url).netloc
0 commit comments