@mastra/agent-browser 0.1.0-alpha.0 → 0.2.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -0
- package/README.md +138 -0
- package/dist/index.cjs +122 -219
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +58 -85
- package/dist/index.d.ts +58 -85
- package/dist/index.js +122 -220
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
package/dist/index.d.cts
CHANGED
|
@@ -283,14 +283,32 @@ declare const browserSchemas: {
|
|
|
283
283
|
}, z.core.$strip>;
|
|
284
284
|
};
|
|
285
285
|
|
|
286
|
+
/**
|
|
287
|
+
* AgentBrowser-specific configuration extensions.
|
|
288
|
+
*/
|
|
289
|
+
interface AgentBrowserConfigExtensions {
|
|
290
|
+
/**
|
|
291
|
+
* Path to a Playwright storage state file (JSON) containing cookies and localStorage.
|
|
292
|
+
* This is a lighter-weight alternative to `profile` — it only persists
|
|
293
|
+
* authentication state, not the full browser profile.
|
|
294
|
+
*
|
|
295
|
+
* You can export storage state from a Playwright session and reuse it later.
|
|
296
|
+
*
|
|
297
|
+
* @example
|
|
298
|
+
* ```ts
|
|
299
|
+
* { storageState: './auth-state.json' }
|
|
300
|
+
* ```
|
|
301
|
+
*/
|
|
302
|
+
storageState?: string;
|
|
303
|
+
}
|
|
286
304
|
/**
|
|
287
305
|
* Configuration options for AgentBrowser.
|
|
288
|
-
*
|
|
306
|
+
* Extends the base BrowserConfig with agent-browser specific options.
|
|
289
307
|
*/
|
|
290
|
-
type BrowserConfig = BrowserConfig$1;
|
|
308
|
+
type BrowserConfig = BrowserConfig$1 & AgentBrowserConfigExtensions;
|
|
291
309
|
|
|
292
310
|
/**
|
|
293
|
-
* AgentBrowserThreadManager - Thread
|
|
311
|
+
* AgentBrowserThreadManager - Thread scope management for AgentBrowser
|
|
294
312
|
*
|
|
295
313
|
* Manages thread-scoped browser sessions using agent-browser's
|
|
296
314
|
* BrowserManager capabilities (newWindow, switchTo, closeTab).
|
|
@@ -322,25 +340,14 @@ interface AgentBrowserThreadManagerConfig extends ThreadManagerConfig {
|
|
|
322
340
|
* - 'thread': Each thread gets a dedicated browser manager instance
|
|
323
341
|
*/
|
|
324
342
|
declare class AgentBrowserThreadManager extends ThreadManager<BrowserManager> {
|
|
325
|
-
private sharedManager;
|
|
326
343
|
private readonly browserConfig;
|
|
327
344
|
private readonly resolveCdpUrl?;
|
|
328
345
|
private readonly onBrowserCreated?;
|
|
329
|
-
/** Map of thread ID to dedicated browser manager (for 'thread' scope) */
|
|
330
|
-
private readonly threadBrowsers;
|
|
331
346
|
constructor(config: AgentBrowserThreadManagerConfig);
|
|
332
347
|
/**
|
|
333
|
-
*
|
|
334
|
-
*/
|
|
335
|
-
setSharedManager(manager: BrowserManager): void;
|
|
336
|
-
/**
|
|
337
|
-
* Clear the shared browser manager (called when browser disconnects).
|
|
338
|
-
*/
|
|
339
|
-
clearSharedManager(): void;
|
|
340
|
-
/**
|
|
341
|
-
* Get the shared browser manager.
|
|
348
|
+
* Get the page for a specific thread, creating session if needed.
|
|
342
349
|
*/
|
|
343
|
-
|
|
350
|
+
getPageForThread(threadId?: string): Promise<Page>;
|
|
344
351
|
/**
|
|
345
352
|
* Create a new session for a thread.
|
|
346
353
|
*/
|
|
@@ -349,12 +356,6 @@ declare class AgentBrowserThreadManager extends ThreadManager<BrowserManager> {
|
|
|
349
356
|
* Restore browser state (multiple tabs) to a browser manager.
|
|
350
357
|
*/
|
|
351
358
|
private restoreBrowserState;
|
|
352
|
-
/**
|
|
353
|
-
* Switch to an existing session.
|
|
354
|
-
* For 'thread' scope, no switching needed - each thread has its own manager.
|
|
355
|
-
* For 'shared' scope, nothing to switch.
|
|
356
|
-
*/
|
|
357
|
-
protected switchToSession(_session: AgentBrowserSession): Promise<void>;
|
|
358
359
|
/**
|
|
359
360
|
* Get the browser manager for a specific session.
|
|
360
361
|
*/
|
|
@@ -365,29 +366,9 @@ declare class AgentBrowserThreadManager extends ThreadManager<BrowserManager> {
|
|
|
365
366
|
protected doDestroySession(session: AgentBrowserSession): Promise<void>;
|
|
366
367
|
/**
|
|
367
368
|
* Destroy all sessions (called during browser close).
|
|
369
|
+
* doDestroySession handles closing individual browser managers.
|
|
368
370
|
*/
|
|
369
371
|
destroyAllSessions(): Promise<void>;
|
|
370
|
-
/**
|
|
371
|
-
* Check if any thread browsers are still running.
|
|
372
|
-
*/
|
|
373
|
-
hasActiveThreadBrowsers(): boolean;
|
|
374
|
-
/**
|
|
375
|
-
* Get the browser manager for an existing thread session without creating a new one.
|
|
376
|
-
* Returns null if no session exists for the thread.
|
|
377
|
-
*/
|
|
378
|
-
getExistingManagerForThread(threadId: string): BrowserManager | null;
|
|
379
|
-
/**
|
|
380
|
-
* Clear all session tracking without closing browsers.
|
|
381
|
-
* Used when browsers have been externally closed and we just need to reset state.
|
|
382
|
-
*/
|
|
383
|
-
clearAllSessions(): void;
|
|
384
|
-
/**
|
|
385
|
-
* Clear a specific thread's session without closing the browser.
|
|
386
|
-
* Used when a thread's browser has been externally closed.
|
|
387
|
-
* Preserves the browser state for potential restoration.
|
|
388
|
-
* @param threadId - The thread ID to clear
|
|
389
|
-
*/
|
|
390
|
-
clearSession(threadId: string): void;
|
|
391
372
|
}
|
|
392
373
|
|
|
393
374
|
/**
|
|
@@ -399,13 +380,11 @@ declare class AgentBrowser extends MastraBrowser {
|
|
|
399
380
|
readonly id: string;
|
|
400
381
|
readonly name = "AgentBrowser";
|
|
401
382
|
readonly provider = "vercel-labs/agent-browser";
|
|
402
|
-
/**
|
|
403
|
-
|
|
383
|
+
/** Shared browser manager instance (for 'shared' scope) - narrowed type from base class */
|
|
384
|
+
protected sharedManager: BrowserManager | null;
|
|
404
385
|
private defaultTimeout;
|
|
405
|
-
/**
|
|
406
|
-
private
|
|
407
|
-
/** Default key for shared scope */
|
|
408
|
-
private static readonly SHARED_STREAM_KEY;
|
|
386
|
+
/** Pending PID lookups — awaited in disconnect handlers to avoid racing. */
|
|
387
|
+
private pidLookups;
|
|
409
388
|
/** Thread manager - narrowed type from base class */
|
|
410
389
|
protected threadManager: AgentBrowserThreadManager;
|
|
411
390
|
constructor(config?: BrowserConfig);
|
|
@@ -413,32 +392,22 @@ declare class AgentBrowser extends MastraBrowser {
|
|
|
413
392
|
* Ensure browser is ready and thread session exists.
|
|
414
393
|
* Creates a new page/context for the current thread if needed.
|
|
415
394
|
*
|
|
416
|
-
* For '
|
|
395
|
+
* For 'thread' scope, we need to create the thread session BEFORE
|
|
417
396
|
* calling super.ensureReady() because the base class's ensureReady() will
|
|
418
397
|
* call checkBrowserAlive(), which needs at least one thread browser to exist.
|
|
419
398
|
*/
|
|
420
399
|
ensureReady(): Promise<void>;
|
|
421
400
|
/**
|
|
422
401
|
* Get the browser manager for the current thread.
|
|
423
|
-
* Delegates to ThreadManager for
|
|
402
|
+
* Delegates to ThreadManager for scope handling.
|
|
424
403
|
*/
|
|
425
404
|
getManagerForThread(threadId?: string): Promise<BrowserManager>;
|
|
426
|
-
/**
|
|
427
|
-
* Get the page for a specific thread.
|
|
428
|
-
* For thread-isolated modes, ensures we're on the correct context/page.
|
|
429
|
-
*/
|
|
430
|
-
getPageForThread(threadId?: string): Promise<Page>;
|
|
431
|
-
/**
|
|
432
|
-
* Close a specific thread's browser session.
|
|
433
|
-
* Delegates to ThreadManager and notifies registered callbacks.
|
|
434
|
-
*/
|
|
435
|
-
closeThreadSession(threadId: string): Promise<void>;
|
|
436
405
|
protected doLaunch(): Promise<void>;
|
|
437
406
|
/**
|
|
438
|
-
* Set up close event listeners for '
|
|
407
|
+
* Set up close event listeners for 'shared' scope browser.
|
|
439
408
|
* This handles the case where the shared browser is closed externally.
|
|
440
409
|
*/
|
|
441
|
-
private
|
|
410
|
+
private setupCloseListenerForSharedScope;
|
|
442
411
|
protected doClose(): Promise<void>;
|
|
443
412
|
/**
|
|
444
413
|
* Check if the browser is still alive by verifying the page is connected.
|
|
@@ -458,21 +427,15 @@ declare class AgentBrowser extends MastraBrowser {
|
|
|
458
427
|
*/
|
|
459
428
|
private getPage;
|
|
460
429
|
/**
|
|
461
|
-
*
|
|
462
|
-
*
|
|
463
|
-
* For 'shared' scope, notifies all callbacks.
|
|
430
|
+
* Get the active page for a thread (implements abstract method from base class).
|
|
431
|
+
* Returns null if no page is available, unlike getPage which throws.
|
|
464
432
|
*/
|
|
465
|
-
|
|
433
|
+
protected getActivePage(threadId?: string): Promise<Page | null>;
|
|
466
434
|
/**
|
|
467
435
|
* Set up close event listener for a thread's browser manager.
|
|
468
436
|
* This handles the case where a thread's browser is closed externally.
|
|
469
437
|
*/
|
|
470
438
|
private setupCloseListenerForThread;
|
|
471
|
-
/**
|
|
472
|
-
* Handle browser disconnection for a specific thread.
|
|
473
|
-
* Called when a thread's browser is closed externally.
|
|
474
|
-
*/
|
|
475
|
-
private handleThreadBrowserDisconnected;
|
|
476
439
|
/**
|
|
477
440
|
* Create an error response from an exception.
|
|
478
441
|
* Extends base class to add agent-browser specific error handling.
|
|
@@ -494,6 +457,11 @@ declare class AgentBrowser extends MastraBrowser {
|
|
|
494
457
|
* Get the current browser state (all tabs and active tab index).
|
|
495
458
|
*/
|
|
496
459
|
getBrowserState(threadId?: string): Promise<BrowserState | null>;
|
|
460
|
+
/**
|
|
461
|
+
* Get browser state for a thread (implements abstract method from base class).
|
|
462
|
+
* Sync version that uses existing manager lookup without creating sessions.
|
|
463
|
+
*/
|
|
464
|
+
protected getBrowserStateForThread(threadId?: string): BrowserState | null;
|
|
497
465
|
/**
|
|
498
466
|
* Get browser state from a specific manager instance.
|
|
499
467
|
*/
|
|
@@ -507,10 +475,13 @@ declare class AgentBrowser extends MastraBrowser {
|
|
|
507
475
|
*/
|
|
508
476
|
getActiveTabIndex(threadId?: string): Promise<number>;
|
|
509
477
|
/**
|
|
510
|
-
*
|
|
511
|
-
*
|
|
478
|
+
* Export the current browser session's storage state (cookies, localStorage) to a JSON file.
|
|
479
|
+
* This can later be loaded via the `storageState` config option to restore the session.
|
|
480
|
+
*
|
|
481
|
+
* @param path - File path to save the storage state JSON
|
|
482
|
+
* @param threadId - Optional thread ID (defaults to current thread)
|
|
512
483
|
*/
|
|
513
|
-
|
|
484
|
+
exportStorageState(path: string, threadId?: string): Promise<void>;
|
|
514
485
|
goto(input: GotoInput, threadId?: string): Promise<{
|
|
515
486
|
success: true;
|
|
516
487
|
url: string;
|
|
@@ -602,20 +573,22 @@ declare class AgentBrowser extends MastraBrowser {
|
|
|
602
573
|
success: true;
|
|
603
574
|
hint: string;
|
|
604
575
|
} | BrowserToolError>;
|
|
605
|
-
/**
|
|
606
|
-
* Get the stream key for a thread (or shared key for shared scope).
|
|
607
|
-
*/
|
|
608
|
-
private getStreamKey;
|
|
609
|
-
/**
|
|
610
|
-
* Trigger a screencast reconnect after tab changes.
|
|
611
|
-
* Called internally when tabs are switched or closed.
|
|
612
|
-
*/
|
|
613
|
-
private reconnectScreencast;
|
|
614
576
|
startScreencast(_options?: ScreencastOptions): Promise<ScreencastStream>;
|
|
615
577
|
injectMouseEvent(event: MouseEventParams, threadId?: string): Promise<void>;
|
|
616
578
|
injectKeyboardEvent(event: KeyboardEventParams, threadId?: string): Promise<void>;
|
|
617
579
|
}
|
|
618
580
|
|
|
581
|
+
/**
|
|
582
|
+
* Get the browser process PID from a BrowserManager instance via CDP.
|
|
583
|
+
*
|
|
584
|
+
* Playwright doesn't expose the browser process PID directly, so we use CDP's
|
|
585
|
+
* SystemInfo.getProcessInfo to get it. This works for both regular browser
|
|
586
|
+
* launches and persistent contexts (profiles).
|
|
587
|
+
*
|
|
588
|
+
* Returns undefined if the PID can't be retrieved (e.g., browser not running).
|
|
589
|
+
*/
|
|
590
|
+
declare function getBrowserPid(manager: BrowserManager): Promise<number | undefined>;
|
|
591
|
+
|
|
619
592
|
/**
|
|
620
593
|
* Browser Tool Constants
|
|
621
594
|
*/
|
|
@@ -651,4 +624,4 @@ type BrowserToolName = (typeof BROWSER_TOOLS)[keyof typeof BROWSER_TOOLS];
|
|
|
651
624
|
*/
|
|
652
625
|
declare function createAgentBrowserTools(browser: AgentBrowser): Record<string, Tool<any, any>>;
|
|
653
626
|
|
|
654
|
-
export { AgentBrowser, BROWSER_TOOLS, type BackInput, type BrowserConfig, type BrowserToolName, type ClickInput, type CloseInput, type DialogInput, type DragInput, type EvaluateInput, type GotoInput, type HoverInput, type PressInput, type ScrollInput, type SelectInput, type SnapshotInput, type TabsInput, type TypeInput, type WaitInput, backInputSchema, browserSchemas, clickInputSchema, closeInputSchema, createAgentBrowserTools, dialogInputSchema, dragInputSchema, evaluateInputSchema, gotoInputSchema, hoverInputSchema, pressInputSchema, scrollInputSchema, selectInputSchema, snapshotInputSchema, tabsInputSchema, typeInputSchema, waitInputSchema };
|
|
627
|
+
export { AgentBrowser, BROWSER_TOOLS, type BackInput, type BrowserConfig, type BrowserToolName, type ClickInput, type CloseInput, type DialogInput, type DragInput, type EvaluateInput, type GotoInput, type HoverInput, type PressInput, type ScrollInput, type SelectInput, type SnapshotInput, type TabsInput, type TypeInput, type WaitInput, backInputSchema, browserSchemas, clickInputSchema, closeInputSchema, createAgentBrowserTools, dialogInputSchema, dragInputSchema, evaluateInputSchema, getBrowserPid, gotoInputSchema, hoverInputSchema, pressInputSchema, scrollInputSchema, selectInputSchema, snapshotInputSchema, tabsInputSchema, typeInputSchema, waitInputSchema };
|
package/dist/index.d.ts
CHANGED
|
@@ -283,14 +283,32 @@ declare const browserSchemas: {
|
|
|
283
283
|
}, z.core.$strip>;
|
|
284
284
|
};
|
|
285
285
|
|
|
286
|
+
/**
|
|
287
|
+
* AgentBrowser-specific configuration extensions.
|
|
288
|
+
*/
|
|
289
|
+
interface AgentBrowserConfigExtensions {
|
|
290
|
+
/**
|
|
291
|
+
* Path to a Playwright storage state file (JSON) containing cookies and localStorage.
|
|
292
|
+
* This is a lighter-weight alternative to `profile` — it only persists
|
|
293
|
+
* authentication state, not the full browser profile.
|
|
294
|
+
*
|
|
295
|
+
* You can export storage state from a Playwright session and reuse it later.
|
|
296
|
+
*
|
|
297
|
+
* @example
|
|
298
|
+
* ```ts
|
|
299
|
+
* { storageState: './auth-state.json' }
|
|
300
|
+
* ```
|
|
301
|
+
*/
|
|
302
|
+
storageState?: string;
|
|
303
|
+
}
|
|
286
304
|
/**
|
|
287
305
|
* Configuration options for AgentBrowser.
|
|
288
|
-
*
|
|
306
|
+
* Extends the base BrowserConfig with agent-browser specific options.
|
|
289
307
|
*/
|
|
290
|
-
type BrowserConfig = BrowserConfig$1;
|
|
308
|
+
type BrowserConfig = BrowserConfig$1 & AgentBrowserConfigExtensions;
|
|
291
309
|
|
|
292
310
|
/**
|
|
293
|
-
* AgentBrowserThreadManager - Thread
|
|
311
|
+
* AgentBrowserThreadManager - Thread scope management for AgentBrowser
|
|
294
312
|
*
|
|
295
313
|
* Manages thread-scoped browser sessions using agent-browser's
|
|
296
314
|
* BrowserManager capabilities (newWindow, switchTo, closeTab).
|
|
@@ -322,25 +340,14 @@ interface AgentBrowserThreadManagerConfig extends ThreadManagerConfig {
|
|
|
322
340
|
* - 'thread': Each thread gets a dedicated browser manager instance
|
|
323
341
|
*/
|
|
324
342
|
declare class AgentBrowserThreadManager extends ThreadManager<BrowserManager> {
|
|
325
|
-
private sharedManager;
|
|
326
343
|
private readonly browserConfig;
|
|
327
344
|
private readonly resolveCdpUrl?;
|
|
328
345
|
private readonly onBrowserCreated?;
|
|
329
|
-
/** Map of thread ID to dedicated browser manager (for 'thread' scope) */
|
|
330
|
-
private readonly threadBrowsers;
|
|
331
346
|
constructor(config: AgentBrowserThreadManagerConfig);
|
|
332
347
|
/**
|
|
333
|
-
*
|
|
334
|
-
*/
|
|
335
|
-
setSharedManager(manager: BrowserManager): void;
|
|
336
|
-
/**
|
|
337
|
-
* Clear the shared browser manager (called when browser disconnects).
|
|
338
|
-
*/
|
|
339
|
-
clearSharedManager(): void;
|
|
340
|
-
/**
|
|
341
|
-
* Get the shared browser manager.
|
|
348
|
+
* Get the page for a specific thread, creating session if needed.
|
|
342
349
|
*/
|
|
343
|
-
|
|
350
|
+
getPageForThread(threadId?: string): Promise<Page>;
|
|
344
351
|
/**
|
|
345
352
|
* Create a new session for a thread.
|
|
346
353
|
*/
|
|
@@ -349,12 +356,6 @@ declare class AgentBrowserThreadManager extends ThreadManager<BrowserManager> {
|
|
|
349
356
|
* Restore browser state (multiple tabs) to a browser manager.
|
|
350
357
|
*/
|
|
351
358
|
private restoreBrowserState;
|
|
352
|
-
/**
|
|
353
|
-
* Switch to an existing session.
|
|
354
|
-
* For 'thread' scope, no switching needed - each thread has its own manager.
|
|
355
|
-
* For 'shared' scope, nothing to switch.
|
|
356
|
-
*/
|
|
357
|
-
protected switchToSession(_session: AgentBrowserSession): Promise<void>;
|
|
358
359
|
/**
|
|
359
360
|
* Get the browser manager for a specific session.
|
|
360
361
|
*/
|
|
@@ -365,29 +366,9 @@ declare class AgentBrowserThreadManager extends ThreadManager<BrowserManager> {
|
|
|
365
366
|
protected doDestroySession(session: AgentBrowserSession): Promise<void>;
|
|
366
367
|
/**
|
|
367
368
|
* Destroy all sessions (called during browser close).
|
|
369
|
+
* doDestroySession handles closing individual browser managers.
|
|
368
370
|
*/
|
|
369
371
|
destroyAllSessions(): Promise<void>;
|
|
370
|
-
/**
|
|
371
|
-
* Check if any thread browsers are still running.
|
|
372
|
-
*/
|
|
373
|
-
hasActiveThreadBrowsers(): boolean;
|
|
374
|
-
/**
|
|
375
|
-
* Get the browser manager for an existing thread session without creating a new one.
|
|
376
|
-
* Returns null if no session exists for the thread.
|
|
377
|
-
*/
|
|
378
|
-
getExistingManagerForThread(threadId: string): BrowserManager | null;
|
|
379
|
-
/**
|
|
380
|
-
* Clear all session tracking without closing browsers.
|
|
381
|
-
* Used when browsers have been externally closed and we just need to reset state.
|
|
382
|
-
*/
|
|
383
|
-
clearAllSessions(): void;
|
|
384
|
-
/**
|
|
385
|
-
* Clear a specific thread's session without closing the browser.
|
|
386
|
-
* Used when a thread's browser has been externally closed.
|
|
387
|
-
* Preserves the browser state for potential restoration.
|
|
388
|
-
* @param threadId - The thread ID to clear
|
|
389
|
-
*/
|
|
390
|
-
clearSession(threadId: string): void;
|
|
391
372
|
}
|
|
392
373
|
|
|
393
374
|
/**
|
|
@@ -399,13 +380,11 @@ declare class AgentBrowser extends MastraBrowser {
|
|
|
399
380
|
readonly id: string;
|
|
400
381
|
readonly name = "AgentBrowser";
|
|
401
382
|
readonly provider = "vercel-labs/agent-browser";
|
|
402
|
-
/**
|
|
403
|
-
|
|
383
|
+
/** Shared browser manager instance (for 'shared' scope) - narrowed type from base class */
|
|
384
|
+
protected sharedManager: BrowserManager | null;
|
|
404
385
|
private defaultTimeout;
|
|
405
|
-
/**
|
|
406
|
-
private
|
|
407
|
-
/** Default key for shared scope */
|
|
408
|
-
private static readonly SHARED_STREAM_KEY;
|
|
386
|
+
/** Pending PID lookups — awaited in disconnect handlers to avoid racing. */
|
|
387
|
+
private pidLookups;
|
|
409
388
|
/** Thread manager - narrowed type from base class */
|
|
410
389
|
protected threadManager: AgentBrowserThreadManager;
|
|
411
390
|
constructor(config?: BrowserConfig);
|
|
@@ -413,32 +392,22 @@ declare class AgentBrowser extends MastraBrowser {
|
|
|
413
392
|
* Ensure browser is ready and thread session exists.
|
|
414
393
|
* Creates a new page/context for the current thread if needed.
|
|
415
394
|
*
|
|
416
|
-
* For '
|
|
395
|
+
* For 'thread' scope, we need to create the thread session BEFORE
|
|
417
396
|
* calling super.ensureReady() because the base class's ensureReady() will
|
|
418
397
|
* call checkBrowserAlive(), which needs at least one thread browser to exist.
|
|
419
398
|
*/
|
|
420
399
|
ensureReady(): Promise<void>;
|
|
421
400
|
/**
|
|
422
401
|
* Get the browser manager for the current thread.
|
|
423
|
-
* Delegates to ThreadManager for
|
|
402
|
+
* Delegates to ThreadManager for scope handling.
|
|
424
403
|
*/
|
|
425
404
|
getManagerForThread(threadId?: string): Promise<BrowserManager>;
|
|
426
|
-
/**
|
|
427
|
-
* Get the page for a specific thread.
|
|
428
|
-
* For thread-isolated modes, ensures we're on the correct context/page.
|
|
429
|
-
*/
|
|
430
|
-
getPageForThread(threadId?: string): Promise<Page>;
|
|
431
|
-
/**
|
|
432
|
-
* Close a specific thread's browser session.
|
|
433
|
-
* Delegates to ThreadManager and notifies registered callbacks.
|
|
434
|
-
*/
|
|
435
|
-
closeThreadSession(threadId: string): Promise<void>;
|
|
436
405
|
protected doLaunch(): Promise<void>;
|
|
437
406
|
/**
|
|
438
|
-
* Set up close event listeners for '
|
|
407
|
+
* Set up close event listeners for 'shared' scope browser.
|
|
439
408
|
* This handles the case where the shared browser is closed externally.
|
|
440
409
|
*/
|
|
441
|
-
private
|
|
410
|
+
private setupCloseListenerForSharedScope;
|
|
442
411
|
protected doClose(): Promise<void>;
|
|
443
412
|
/**
|
|
444
413
|
* Check if the browser is still alive by verifying the page is connected.
|
|
@@ -458,21 +427,15 @@ declare class AgentBrowser extends MastraBrowser {
|
|
|
458
427
|
*/
|
|
459
428
|
private getPage;
|
|
460
429
|
/**
|
|
461
|
-
*
|
|
462
|
-
*
|
|
463
|
-
* For 'shared' scope, notifies all callbacks.
|
|
430
|
+
* Get the active page for a thread (implements abstract method from base class).
|
|
431
|
+
* Returns null if no page is available, unlike getPage which throws.
|
|
464
432
|
*/
|
|
465
|
-
|
|
433
|
+
protected getActivePage(threadId?: string): Promise<Page | null>;
|
|
466
434
|
/**
|
|
467
435
|
* Set up close event listener for a thread's browser manager.
|
|
468
436
|
* This handles the case where a thread's browser is closed externally.
|
|
469
437
|
*/
|
|
470
438
|
private setupCloseListenerForThread;
|
|
471
|
-
/**
|
|
472
|
-
* Handle browser disconnection for a specific thread.
|
|
473
|
-
* Called when a thread's browser is closed externally.
|
|
474
|
-
*/
|
|
475
|
-
private handleThreadBrowserDisconnected;
|
|
476
439
|
/**
|
|
477
440
|
* Create an error response from an exception.
|
|
478
441
|
* Extends base class to add agent-browser specific error handling.
|
|
@@ -494,6 +457,11 @@ declare class AgentBrowser extends MastraBrowser {
|
|
|
494
457
|
* Get the current browser state (all tabs and active tab index).
|
|
495
458
|
*/
|
|
496
459
|
getBrowserState(threadId?: string): Promise<BrowserState | null>;
|
|
460
|
+
/**
|
|
461
|
+
* Get browser state for a thread (implements abstract method from base class).
|
|
462
|
+
* Sync version that uses existing manager lookup without creating sessions.
|
|
463
|
+
*/
|
|
464
|
+
protected getBrowserStateForThread(threadId?: string): BrowserState | null;
|
|
497
465
|
/**
|
|
498
466
|
* Get browser state from a specific manager instance.
|
|
499
467
|
*/
|
|
@@ -507,10 +475,13 @@ declare class AgentBrowser extends MastraBrowser {
|
|
|
507
475
|
*/
|
|
508
476
|
getActiveTabIndex(threadId?: string): Promise<number>;
|
|
509
477
|
/**
|
|
510
|
-
*
|
|
511
|
-
*
|
|
478
|
+
* Export the current browser session's storage state (cookies, localStorage) to a JSON file.
|
|
479
|
+
* This can later be loaded via the `storageState` config option to restore the session.
|
|
480
|
+
*
|
|
481
|
+
* @param path - File path to save the storage state JSON
|
|
482
|
+
* @param threadId - Optional thread ID (defaults to current thread)
|
|
512
483
|
*/
|
|
513
|
-
|
|
484
|
+
exportStorageState(path: string, threadId?: string): Promise<void>;
|
|
514
485
|
goto(input: GotoInput, threadId?: string): Promise<{
|
|
515
486
|
success: true;
|
|
516
487
|
url: string;
|
|
@@ -602,20 +573,22 @@ declare class AgentBrowser extends MastraBrowser {
|
|
|
602
573
|
success: true;
|
|
603
574
|
hint: string;
|
|
604
575
|
} | BrowserToolError>;
|
|
605
|
-
/**
|
|
606
|
-
* Get the stream key for a thread (or shared key for shared scope).
|
|
607
|
-
*/
|
|
608
|
-
private getStreamKey;
|
|
609
|
-
/**
|
|
610
|
-
* Trigger a screencast reconnect after tab changes.
|
|
611
|
-
* Called internally when tabs are switched or closed.
|
|
612
|
-
*/
|
|
613
|
-
private reconnectScreencast;
|
|
614
576
|
startScreencast(_options?: ScreencastOptions): Promise<ScreencastStream>;
|
|
615
577
|
injectMouseEvent(event: MouseEventParams, threadId?: string): Promise<void>;
|
|
616
578
|
injectKeyboardEvent(event: KeyboardEventParams, threadId?: string): Promise<void>;
|
|
617
579
|
}
|
|
618
580
|
|
|
581
|
+
/**
|
|
582
|
+
* Get the browser process PID from a BrowserManager instance via CDP.
|
|
583
|
+
*
|
|
584
|
+
* Playwright doesn't expose the browser process PID directly, so we use CDP's
|
|
585
|
+
* SystemInfo.getProcessInfo to get it. This works for both regular browser
|
|
586
|
+
* launches and persistent contexts (profiles).
|
|
587
|
+
*
|
|
588
|
+
* Returns undefined if the PID can't be retrieved (e.g., browser not running).
|
|
589
|
+
*/
|
|
590
|
+
declare function getBrowserPid(manager: BrowserManager): Promise<number | undefined>;
|
|
591
|
+
|
|
619
592
|
/**
|
|
620
593
|
* Browser Tool Constants
|
|
621
594
|
*/
|
|
@@ -651,4 +624,4 @@ type BrowserToolName = (typeof BROWSER_TOOLS)[keyof typeof BROWSER_TOOLS];
|
|
|
651
624
|
*/
|
|
652
625
|
declare function createAgentBrowserTools(browser: AgentBrowser): Record<string, Tool<any, any>>;
|
|
653
626
|
|
|
654
|
-
export { AgentBrowser, BROWSER_TOOLS, type BackInput, type BrowserConfig, type BrowserToolName, type ClickInput, type CloseInput, type DialogInput, type DragInput, type EvaluateInput, type GotoInput, type HoverInput, type PressInput, type ScrollInput, type SelectInput, type SnapshotInput, type TabsInput, type TypeInput, type WaitInput, backInputSchema, browserSchemas, clickInputSchema, closeInputSchema, createAgentBrowserTools, dialogInputSchema, dragInputSchema, evaluateInputSchema, gotoInputSchema, hoverInputSchema, pressInputSchema, scrollInputSchema, selectInputSchema, snapshotInputSchema, tabsInputSchema, typeInputSchema, waitInputSchema };
|
|
627
|
+
export { AgentBrowser, BROWSER_TOOLS, type BackInput, type BrowserConfig, type BrowserToolName, type ClickInput, type CloseInput, type DialogInput, type DragInput, type EvaluateInput, type GotoInput, type HoverInput, type PressInput, type ScrollInput, type SelectInput, type SnapshotInput, type TabsInput, type TypeInput, type WaitInput, backInputSchema, browserSchemas, clickInputSchema, closeInputSchema, createAgentBrowserTools, dialogInputSchema, dragInputSchema, evaluateInputSchema, getBrowserPid, gotoInputSchema, hoverInputSchema, pressInputSchema, scrollInputSchema, selectInputSchema, snapshotInputSchema, tabsInputSchema, typeInputSchema, waitInputSchema };
|