@mastra/agent-browser 0.2.2 → 0.3.0-alpha.1

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/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { BrowserConfig as BrowserConfig$1, ThreadManager, ThreadManagerConfig, ThreadSession, MastraBrowser, BrowserToolError, BrowserState, BrowserTabState, ScreencastOptions, ScreencastStream, MouseEventParams, KeyboardEventParams } from '@mastra/core/browser';
1
+ import { BrowserConfig as BrowserConfig$1, ThreadManager, ThreadManagerConfig, ThreadSession, BrowserState, MastraBrowser, BrowserToolError, BrowserTabState, ScreencastOptions, ScreencastStream, MouseEventParams, KeyboardEventParams } from '@mastra/core/browser';
2
2
  import { Tool } from '@mastra/core/tools';
3
3
  import { BrowserManager } from 'agent-browser';
4
4
  import { Page } from 'playwright-core';
@@ -54,6 +54,12 @@ declare const clickInputSchema: z.ZodObject<{
54
54
  Meta: "Meta";
55
55
  Shift: "Shift";
56
56
  }>>>;
57
+ waitUntil: z.ZodOptional<z.ZodEnum<{
58
+ load: "load";
59
+ domcontentloaded: "domcontentloaded";
60
+ networkidle: "networkidle";
61
+ }>>;
62
+ timeout: z.ZodOptional<z.ZodNumber>;
57
63
  }, z.core.$strip>;
58
64
  type ClickInput = z.output<typeof clickInputSchema>;
59
65
  /**
@@ -77,6 +83,12 @@ declare const pressInputSchema: z.ZodObject<{
77
83
  Meta: "Meta";
78
84
  Shift: "Shift";
79
85
  }>>>;
86
+ waitUntil: z.ZodOptional<z.ZodEnum<{
87
+ load: "load";
88
+ domcontentloaded: "domcontentloaded";
89
+ networkidle: "networkidle";
90
+ }>>;
91
+ timeout: z.ZodOptional<z.ZodNumber>;
80
92
  }, z.core.$strip>;
81
93
  type PressInput = z.output<typeof pressInputSchema>;
82
94
  /**
@@ -87,6 +99,12 @@ declare const selectInputSchema: z.ZodObject<{
87
99
  value: z.ZodOptional<z.ZodString>;
88
100
  label: z.ZodOptional<z.ZodString>;
89
101
  index: z.ZodOptional<z.ZodNumber>;
102
+ waitUntil: z.ZodOptional<z.ZodEnum<{
103
+ load: "load";
104
+ domcontentloaded: "domcontentloaded";
105
+ networkidle: "networkidle";
106
+ }>>;
107
+ timeout: z.ZodOptional<z.ZodNumber>;
90
108
  }, z.core.$strip>;
91
109
  type SelectInput = z.output<typeof selectInputSchema>;
92
110
  /**
@@ -213,6 +231,12 @@ declare const browserSchemas: {
213
231
  Meta: "Meta";
214
232
  Shift: "Shift";
215
233
  }>>>;
234
+ waitUntil: z.ZodOptional<z.ZodEnum<{
235
+ load: "load";
236
+ domcontentloaded: "domcontentloaded";
237
+ networkidle: "networkidle";
238
+ }>>;
239
+ timeout: z.ZodOptional<z.ZodNumber>;
216
240
  }, z.core.$strip>;
217
241
  readonly type: z.ZodObject<{
218
242
  ref: z.ZodString;
@@ -228,12 +252,24 @@ declare const browserSchemas: {
228
252
  Meta: "Meta";
229
253
  Shift: "Shift";
230
254
  }>>>;
255
+ waitUntil: z.ZodOptional<z.ZodEnum<{
256
+ load: "load";
257
+ domcontentloaded: "domcontentloaded";
258
+ networkidle: "networkidle";
259
+ }>>;
260
+ timeout: z.ZodOptional<z.ZodNumber>;
231
261
  }, z.core.$strip>;
232
262
  readonly select: z.ZodObject<{
233
263
  ref: z.ZodString;
234
264
  value: z.ZodOptional<z.ZodString>;
235
265
  label: z.ZodOptional<z.ZodString>;
236
266
  index: z.ZodOptional<z.ZodNumber>;
267
+ waitUntil: z.ZodOptional<z.ZodEnum<{
268
+ load: "load";
269
+ domcontentloaded: "domcontentloaded";
270
+ networkidle: "networkidle";
271
+ }>>;
272
+ timeout: z.ZodOptional<z.ZodNumber>;
237
273
  }, z.core.$strip>;
238
274
  readonly scroll: z.ZodObject<{
239
275
  direction: z.ZodEnum<{
@@ -376,6 +412,11 @@ interface AgentBrowserThreadManagerConfig extends ThreadManagerConfig {
376
412
  /** Callback when a new browser manager is created for a thread */
377
413
  onBrowserCreated?: (manager: BrowserManager, threadId: string) => void;
378
414
  }
415
+ /**
416
+ * Factory for custom thread managers (e.g. Firecrawl-hosted CDP per session).
417
+ * Defaults to {@link AgentBrowserThreadManager} when omitted.
418
+ */
419
+ type CreateAgentBrowserThreadManager = (config: AgentBrowserThreadManagerConfig) => AgentBrowserThreadManager;
379
420
  /**
380
421
  * Thread manager implementation for AgentBrowser.
381
422
  *
@@ -384,9 +425,9 @@ interface AgentBrowserThreadManagerConfig extends ThreadManagerConfig {
384
425
  * - 'thread': Each thread gets a dedicated browser manager instance
385
426
  */
386
427
  declare class AgentBrowserThreadManager extends ThreadManager<BrowserManager> {
387
- private readonly browserConfig;
428
+ protected readonly browserConfig: BrowserConfig;
388
429
  private readonly resolveCdpUrl?;
389
- private readonly onBrowserCreated?;
430
+ protected readonly onBrowserCreated?: (manager: BrowserManager, threadId: string) => void;
390
431
  constructor(config: AgentBrowserThreadManagerConfig);
391
432
  /**
392
433
  * Get the page for a specific thread, creating session if needed.
@@ -399,7 +440,7 @@ declare class AgentBrowserThreadManager extends ThreadManager<BrowserManager> {
399
440
  /**
400
441
  * Restore browser state (multiple tabs) to a browser manager.
401
442
  */
402
- private restoreBrowserState;
443
+ protected restoreBrowserState(manager: BrowserManager, state: BrowserState): Promise<void>;
403
444
  /**
404
445
  * Get the browser manager for a specific session.
405
446
  */
@@ -415,6 +456,10 @@ declare class AgentBrowserThreadManager extends ThreadManager<BrowserManager> {
415
456
  destroyAllSessions(): Promise<void>;
416
457
  }
417
458
 
459
+ /** AgentBrowser accepts an optional thread-manager factory (see {@link CreateAgentBrowserThreadManager}). */
460
+ type AgentBrowserConfig = BrowserConfig & {
461
+ createThreadManager?: CreateAgentBrowserThreadManager;
462
+ };
418
463
  /**
419
464
  * AgentBrowser - Browser automation using agent-browser (vercel-labs/agent-browser)
420
465
  *
@@ -422,8 +467,8 @@ declare class AgentBrowserThreadManager extends ThreadManager<BrowserManager> {
422
467
  */
423
468
  declare class AgentBrowser extends MastraBrowser {
424
469
  readonly id: string;
425
- readonly name = "AgentBrowser";
426
- readonly provider = "vercel-labs/agent-browser";
470
+ readonly name: string;
471
+ readonly provider: string;
427
472
  /** Shared browser manager instance (for 'shared' scope) - narrowed type from base class */
428
473
  protected sharedManager: BrowserManager | null;
429
474
  private defaultTimeout;
@@ -432,7 +477,7 @@ declare class AgentBrowser extends MastraBrowser {
432
477
  /** Thread manager - narrowed type from base class */
433
478
  protected threadManager: AgentBrowserThreadManager;
434
479
  private browserConfig;
435
- constructor(config?: BrowserConfig);
480
+ constructor(config?: AgentBrowserConfig);
436
481
  /**
437
482
  * Ensure browser is ready and thread session exists.
438
483
  * Creates a new page/context for the current thread if needed.
@@ -452,7 +497,7 @@ declare class AgentBrowser extends MastraBrowser {
452
497
  * Set up close event listeners for 'shared' scope browser.
453
498
  * This handles the case where the shared browser is closed externally.
454
499
  */
455
- private setupCloseListenerForSharedScope;
500
+ protected setupCloseListenerForSharedScope(manager: BrowserManager): void;
456
501
  protected doClose(): Promise<void>;
457
502
  /**
458
503
  * Check if the browser is still alive by verifying the page is connected.
@@ -652,4 +697,4 @@ declare function getBrowserPid(manager: BrowserManager): Promise<number | undefi
652
697
  */
653
698
  declare function createAgentBrowserTools(browser: AgentBrowser): Record<string, Tool<any, any>>;
654
699
 
655
- 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 };
700
+ export { AgentBrowser, type AgentBrowserConfig, type AgentBrowserSession, AgentBrowserThreadManager, type AgentBrowserThreadManagerConfig, BROWSER_TOOLS, type BackInput, type BrowserConfig, type BrowserToolName, type ClickInput, type CloseInput, type CreateAgentBrowserThreadManager, 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
@@ -1,4 +1,4 @@
1
- import { BrowserConfig as BrowserConfig$1, ThreadManager, ThreadManagerConfig, ThreadSession, MastraBrowser, BrowserToolError, BrowserState, BrowserTabState, ScreencastOptions, ScreencastStream, MouseEventParams, KeyboardEventParams } from '@mastra/core/browser';
1
+ import { BrowserConfig as BrowserConfig$1, ThreadManager, ThreadManagerConfig, ThreadSession, BrowserState, MastraBrowser, BrowserToolError, BrowserTabState, ScreencastOptions, ScreencastStream, MouseEventParams, KeyboardEventParams } from '@mastra/core/browser';
2
2
  import { Tool } from '@mastra/core/tools';
3
3
  import { BrowserManager } from 'agent-browser';
4
4
  import { Page } from 'playwright-core';
@@ -54,6 +54,12 @@ declare const clickInputSchema: z.ZodObject<{
54
54
  Meta: "Meta";
55
55
  Shift: "Shift";
56
56
  }>>>;
57
+ waitUntil: z.ZodOptional<z.ZodEnum<{
58
+ load: "load";
59
+ domcontentloaded: "domcontentloaded";
60
+ networkidle: "networkidle";
61
+ }>>;
62
+ timeout: z.ZodOptional<z.ZodNumber>;
57
63
  }, z.core.$strip>;
58
64
  type ClickInput = z.output<typeof clickInputSchema>;
59
65
  /**
@@ -77,6 +83,12 @@ declare const pressInputSchema: z.ZodObject<{
77
83
  Meta: "Meta";
78
84
  Shift: "Shift";
79
85
  }>>>;
86
+ waitUntil: z.ZodOptional<z.ZodEnum<{
87
+ load: "load";
88
+ domcontentloaded: "domcontentloaded";
89
+ networkidle: "networkidle";
90
+ }>>;
91
+ timeout: z.ZodOptional<z.ZodNumber>;
80
92
  }, z.core.$strip>;
81
93
  type PressInput = z.output<typeof pressInputSchema>;
82
94
  /**
@@ -87,6 +99,12 @@ declare const selectInputSchema: z.ZodObject<{
87
99
  value: z.ZodOptional<z.ZodString>;
88
100
  label: z.ZodOptional<z.ZodString>;
89
101
  index: z.ZodOptional<z.ZodNumber>;
102
+ waitUntil: z.ZodOptional<z.ZodEnum<{
103
+ load: "load";
104
+ domcontentloaded: "domcontentloaded";
105
+ networkidle: "networkidle";
106
+ }>>;
107
+ timeout: z.ZodOptional<z.ZodNumber>;
90
108
  }, z.core.$strip>;
91
109
  type SelectInput = z.output<typeof selectInputSchema>;
92
110
  /**
@@ -213,6 +231,12 @@ declare const browserSchemas: {
213
231
  Meta: "Meta";
214
232
  Shift: "Shift";
215
233
  }>>>;
234
+ waitUntil: z.ZodOptional<z.ZodEnum<{
235
+ load: "load";
236
+ domcontentloaded: "domcontentloaded";
237
+ networkidle: "networkidle";
238
+ }>>;
239
+ timeout: z.ZodOptional<z.ZodNumber>;
216
240
  }, z.core.$strip>;
217
241
  readonly type: z.ZodObject<{
218
242
  ref: z.ZodString;
@@ -228,12 +252,24 @@ declare const browserSchemas: {
228
252
  Meta: "Meta";
229
253
  Shift: "Shift";
230
254
  }>>>;
255
+ waitUntil: z.ZodOptional<z.ZodEnum<{
256
+ load: "load";
257
+ domcontentloaded: "domcontentloaded";
258
+ networkidle: "networkidle";
259
+ }>>;
260
+ timeout: z.ZodOptional<z.ZodNumber>;
231
261
  }, z.core.$strip>;
232
262
  readonly select: z.ZodObject<{
233
263
  ref: z.ZodString;
234
264
  value: z.ZodOptional<z.ZodString>;
235
265
  label: z.ZodOptional<z.ZodString>;
236
266
  index: z.ZodOptional<z.ZodNumber>;
267
+ waitUntil: z.ZodOptional<z.ZodEnum<{
268
+ load: "load";
269
+ domcontentloaded: "domcontentloaded";
270
+ networkidle: "networkidle";
271
+ }>>;
272
+ timeout: z.ZodOptional<z.ZodNumber>;
237
273
  }, z.core.$strip>;
238
274
  readonly scroll: z.ZodObject<{
239
275
  direction: z.ZodEnum<{
@@ -376,6 +412,11 @@ interface AgentBrowserThreadManagerConfig extends ThreadManagerConfig {
376
412
  /** Callback when a new browser manager is created for a thread */
377
413
  onBrowserCreated?: (manager: BrowserManager, threadId: string) => void;
378
414
  }
415
+ /**
416
+ * Factory for custom thread managers (e.g. Firecrawl-hosted CDP per session).
417
+ * Defaults to {@link AgentBrowserThreadManager} when omitted.
418
+ */
419
+ type CreateAgentBrowserThreadManager = (config: AgentBrowserThreadManagerConfig) => AgentBrowserThreadManager;
379
420
  /**
380
421
  * Thread manager implementation for AgentBrowser.
381
422
  *
@@ -384,9 +425,9 @@ interface AgentBrowserThreadManagerConfig extends ThreadManagerConfig {
384
425
  * - 'thread': Each thread gets a dedicated browser manager instance
385
426
  */
386
427
  declare class AgentBrowserThreadManager extends ThreadManager<BrowserManager> {
387
- private readonly browserConfig;
428
+ protected readonly browserConfig: BrowserConfig;
388
429
  private readonly resolveCdpUrl?;
389
- private readonly onBrowserCreated?;
430
+ protected readonly onBrowserCreated?: (manager: BrowserManager, threadId: string) => void;
390
431
  constructor(config: AgentBrowserThreadManagerConfig);
391
432
  /**
392
433
  * Get the page for a specific thread, creating session if needed.
@@ -399,7 +440,7 @@ declare class AgentBrowserThreadManager extends ThreadManager<BrowserManager> {
399
440
  /**
400
441
  * Restore browser state (multiple tabs) to a browser manager.
401
442
  */
402
- private restoreBrowserState;
443
+ protected restoreBrowserState(manager: BrowserManager, state: BrowserState): Promise<void>;
403
444
  /**
404
445
  * Get the browser manager for a specific session.
405
446
  */
@@ -415,6 +456,10 @@ declare class AgentBrowserThreadManager extends ThreadManager<BrowserManager> {
415
456
  destroyAllSessions(): Promise<void>;
416
457
  }
417
458
 
459
+ /** AgentBrowser accepts an optional thread-manager factory (see {@link CreateAgentBrowserThreadManager}). */
460
+ type AgentBrowserConfig = BrowserConfig & {
461
+ createThreadManager?: CreateAgentBrowserThreadManager;
462
+ };
418
463
  /**
419
464
  * AgentBrowser - Browser automation using agent-browser (vercel-labs/agent-browser)
420
465
  *
@@ -422,8 +467,8 @@ declare class AgentBrowserThreadManager extends ThreadManager<BrowserManager> {
422
467
  */
423
468
  declare class AgentBrowser extends MastraBrowser {
424
469
  readonly id: string;
425
- readonly name = "AgentBrowser";
426
- readonly provider = "vercel-labs/agent-browser";
470
+ readonly name: string;
471
+ readonly provider: string;
427
472
  /** Shared browser manager instance (for 'shared' scope) - narrowed type from base class */
428
473
  protected sharedManager: BrowserManager | null;
429
474
  private defaultTimeout;
@@ -432,7 +477,7 @@ declare class AgentBrowser extends MastraBrowser {
432
477
  /** Thread manager - narrowed type from base class */
433
478
  protected threadManager: AgentBrowserThreadManager;
434
479
  private browserConfig;
435
- constructor(config?: BrowserConfig);
480
+ constructor(config?: AgentBrowserConfig);
436
481
  /**
437
482
  * Ensure browser is ready and thread session exists.
438
483
  * Creates a new page/context for the current thread if needed.
@@ -452,7 +497,7 @@ declare class AgentBrowser extends MastraBrowser {
452
497
  * Set up close event listeners for 'shared' scope browser.
453
498
  * This handles the case where the shared browser is closed externally.
454
499
  */
455
- private setupCloseListenerForSharedScope;
500
+ protected setupCloseListenerForSharedScope(manager: BrowserManager): void;
456
501
  protected doClose(): Promise<void>;
457
502
  /**
458
503
  * Check if the browser is still alive by verifying the page is connected.
@@ -652,4 +697,4 @@ declare function getBrowserPid(manager: BrowserManager): Promise<number | undefi
652
697
  */
653
698
  declare function createAgentBrowserTools(browser: AgentBrowser): Record<string, Tool<any, any>>;
654
699
 
655
- 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 };
700
+ export { AgentBrowser, type AgentBrowserConfig, type AgentBrowserSession, AgentBrowserThreadManager, type AgentBrowserThreadManagerConfig, BROWSER_TOOLS, type BackInput, type BrowserConfig, type BrowserToolName, type ClickInput, type CloseInput, type CreateAgentBrowserThreadManager, 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.js CHANGED
@@ -1,4 +1,4 @@
1
- import { MastraBrowser, DEFAULT_THREAD_ID, ScreencastStreamImpl, ThreadManager } from '@mastra/core/browser';
1
+ import { ThreadManager, MastraBrowser, DEFAULT_THREAD_ID, ScreencastStreamImpl } from '@mastra/core/browser';
2
2
  import { BrowserManager } from 'agent-browser';
3
3
  import { createTool } from '@mastra/core/tools';
4
4
  import { z } from 'zod';
@@ -139,7 +139,9 @@ var clickInputSchema = z.object({
139
139
  ref: z.string().describe("Element ref from snapshot (e.g., @e5)"),
140
140
  button: z.enum(["left", "right", "middle"]).optional().describe("Mouse button (default: left)"),
141
141
  clickCount: z.number().optional().describe("Number of clicks (default: 1, use 2 for double-click)"),
142
- modifiers: z.array(z.enum(["Alt", "Control", "Meta", "Shift"])).optional().describe("Modifier keys to hold")
142
+ modifiers: z.array(z.enum(["Alt", "Control", "Meta", "Shift"])).optional().describe("Modifier keys to hold"),
143
+ waitUntil: z.enum(["load", "domcontentloaded", "networkidle"]).optional().describe("If the click triggers a navigation, wait for this page load state before returning"),
144
+ timeout: z.number().nonnegative().optional().describe("Timeout in milliseconds for the click and optional waitUntil")
143
145
  });
144
146
  var typeInputSchema = z.object({
145
147
  ref: z.string().describe("Element ref from snapshot"),
@@ -149,13 +151,17 @@ var typeInputSchema = z.object({
149
151
  });
150
152
  var pressInputSchema = z.object({
151
153
  key: z.string().describe("Key to press (e.g., Enter, Tab, Escape, Control+a)"),
152
- modifiers: z.array(z.enum(["Alt", "Control", "Meta", "Shift"])).optional().describe("Modifier keys to hold")
154
+ modifiers: z.array(z.enum(["Alt", "Control", "Meta", "Shift"])).optional().describe("Modifier keys to hold"),
155
+ waitUntil: z.enum(["load", "domcontentloaded", "networkidle"]).optional().describe("If the key press triggers a navigation, wait for this page load state before returning"),
156
+ timeout: z.number().nonnegative().optional().describe("Timeout in milliseconds for the optional waitUntil")
153
157
  });
154
158
  var selectInputSchema = z.object({
155
159
  ref: z.string().describe("Select element ref from snapshot"),
156
160
  value: z.string().optional().describe("Option value to select"),
157
161
  label: z.string().optional().describe("Option label to select"),
158
- index: z.number().int().min(0).optional().describe("Option index to select (0-based)")
162
+ index: z.number().int().min(0).optional().describe("Option index to select (0-based)"),
163
+ waitUntil: z.enum(["load", "domcontentloaded", "networkidle"]).optional().describe("If the selection triggers a navigation, wait for this page load state before returning"),
164
+ timeout: z.number().nonnegative().optional().describe("Timeout in milliseconds for the selection and optional waitUntil")
159
165
  }).superRefine((data, ctx) => {
160
166
  if (data.value === void 0 && data.label === void 0 && data.index === void 0) {
161
167
  ctx.addIssue({
@@ -291,7 +297,7 @@ function createBackTool(browser) {
291
297
  function createClickTool(browser) {
292
298
  return createTool({
293
299
  id: BROWSER_TOOLS.CLICK,
294
- description: "Click an element using its ref from a snapshot. Use clickCount: 2 for double-click.",
300
+ description: "Click an element using its ref from a snapshot. Use clickCount: 2 for double-click. Pass waitUntil when the click triggers navigation so the page settles before the next snapshot.",
295
301
  inputSchema: clickInputSchema,
296
302
  execute: async (input, { agent }) => {
297
303
  const threadId = agent?.threadId;
@@ -388,7 +394,7 @@ function createHoverTool(browser) {
388
394
  function createPressTool(browser) {
389
395
  return createTool({
390
396
  id: BROWSER_TOOLS.PRESS,
391
- description: "Press a keyboard key (e.g., Enter, Tab, Escape, Control+a).",
397
+ description: "Press a keyboard key (e.g., Enter, Tab, Escape, Control+a). Pass waitUntil when the keypress triggers navigation (e.g., Enter to submit a form) so the page settles before the next snapshot.",
392
398
  inputSchema: pressInputSchema,
393
399
  execute: async (input, { agent }) => {
394
400
  const threadId = agent?.threadId;
@@ -446,7 +452,7 @@ function createScrollTool(browser) {
446
452
  function createSelectTool(browser) {
447
453
  return createTool({
448
454
  id: BROWSER_TOOLS.SELECT,
449
- description: "Select an option from a dropdown by value, label, or index.",
455
+ description: "Select an option from a dropdown by value, label, or index. Pass waitUntil when the selection triggers navigation so the page settles before the next snapshot.",
450
456
  inputSchema: selectInputSchema,
451
457
  execute: async (input, { agent }) => {
452
458
  const threadId = agent?.threadId;
@@ -574,7 +580,7 @@ var AgentBrowser = class extends MastraBrowser {
574
580
  this.defaultTimeout = config.timeout;
575
581
  }
576
582
  const effectiveScope = config.cdpUrl ? config.scope ?? "shared" : config.scope ?? "thread";
577
- this.threadManager = new AgentBrowserThreadManager({
583
+ const threadManagerConfig = {
578
584
  scope: effectiveScope,
579
585
  browserConfig: { ...config, headless: this.headless },
580
586
  resolveCdpUrl: this.resolveCdpUrl.bind(this),
@@ -587,7 +593,9 @@ var AgentBrowser = class extends MastraBrowser {
587
593
  onBrowserCreated: (manager, threadId) => {
588
594
  this.setupCloseListenerForThread(manager, threadId);
589
595
  }
590
- });
596
+ };
597
+ const createTm = config.createThreadManager ?? ((opts) => new AgentBrowserThreadManager(opts));
598
+ this.threadManager = createTm(threadManagerConfig);
591
599
  }
592
600
  // ---------------------------------------------------------------------------
593
601
  // Thread Scope (delegated to ThreadManager)
@@ -1087,12 +1095,15 @@ var AgentBrowser = class extends MastraBrowser {
1087
1095
  "Take a new snapshot to see the current page state and get fresh refs."
1088
1096
  );
1089
1097
  }
1098
+ const timeout = input.timeout ?? this.defaultTimeout;
1099
+ const navigation = input.waitUntil ? page.waitForNavigation({ waitUntil: input.waitUntil, timeout }) : void 0;
1090
1100
  await locator.click({
1091
1101
  button: input.button ?? "left",
1092
1102
  clickCount: input.clickCount ?? 1,
1093
1103
  modifiers: input.modifiers,
1094
- timeout: this.defaultTimeout
1104
+ timeout
1095
1105
  });
1106
+ await navigation;
1096
1107
  return {
1097
1108
  success: true,
1098
1109
  url: page.url(),
@@ -1161,7 +1172,10 @@ var AgentBrowser = class extends MastraBrowser {
1161
1172
  async press(input, threadId) {
1162
1173
  try {
1163
1174
  const page = await this.getPage(threadId);
1175
+ const timeout = input.timeout ?? this.defaultTimeout;
1176
+ const navigation = input.waitUntil ? page.waitForNavigation({ waitUntil: input.waitUntil, timeout }) : void 0;
1164
1177
  await page.keyboard.press(input.key);
1178
+ await navigation;
1165
1179
  return {
1166
1180
  success: true,
1167
1181
  url: page.url(),
@@ -1189,9 +1203,10 @@ var AgentBrowser = class extends MastraBrowser {
1189
1203
  if (input.value) selectValue.value = input.value;
1190
1204
  if (input.label) selectValue.label = input.label;
1191
1205
  if (input.index !== void 0) selectValue.index = input.index;
1192
- const selected = await locator.selectOption(selectValue, {
1193
- timeout: this.defaultTimeout
1194
- });
1206
+ const timeout = input.timeout ?? this.defaultTimeout;
1207
+ const navigation = input.waitUntil ? page.waitForNavigation({ waitUntil: input.waitUntil, timeout }) : void 0;
1208
+ const selected = await locator.selectOption(selectValue, { timeout });
1209
+ await navigation;
1195
1210
  return {
1196
1211
  success: true,
1197
1212
  selected,
@@ -1684,6 +1699,6 @@ var AgentBrowser = class extends MastraBrowser {
1684
1699
  }
1685
1700
  };
1686
1701
 
1687
- export { AgentBrowser, BROWSER_TOOLS, backInputSchema, browserSchemas, clickInputSchema, closeInputSchema, createAgentBrowserTools, dialogInputSchema, dragInputSchema, evaluateInputSchema, getBrowserPid, gotoInputSchema, hoverInputSchema, pressInputSchema, scrollInputSchema, selectInputSchema, snapshotInputSchema, tabsInputSchema, typeInputSchema, waitInputSchema };
1702
+ export { AgentBrowser, AgentBrowserThreadManager, BROWSER_TOOLS, backInputSchema, browserSchemas, clickInputSchema, closeInputSchema, createAgentBrowserTools, dialogInputSchema, dragInputSchema, evaluateInputSchema, getBrowserPid, gotoInputSchema, hoverInputSchema, pressInputSchema, scrollInputSchema, selectInputSchema, snapshotInputSchema, tabsInputSchema, typeInputSchema, waitInputSchema };
1688
1703
  //# sourceMappingURL=index.js.map
1689
1704
  //# sourceMappingURL=index.js.map