text stringlengths 0 59.1k |
|---|
} |
} |
// Export singleton accessor |
const automationController = BrowserAutomationController.getController(); |
// Compatibility wrapper for existing code |
export const sessionManager = { |
ensureStagehand: () => automationController.getBrowserClient(), |
close: () => automationController.terminate(), |
}; |
``` |
</details> |
Implementation: |
- Single browser session across tool calls |
- Automatic session expiration and reconnection handling |
- 10-minute inactivity cleanup |
- Singleton pattern prevents multiple instances |
- Resource leak prevention |
### BrowserBase Tools |
Five tools for web interaction: |
 |
#### Page Navigate Tool |
Loads websites and waits for content: |
<details> |
<summary>Show page-navigate.tool.ts</summary> |
```typescript |
import { createTool } from "@voltagent/core"; |
import { z } from "zod"; |
import { sessionManager } from "../../stagehand-manager"; |
export const pageNavigateTool = createTool({ |
name: "page_navigate", |
description: "Navigate to a specific URL using BrowserBase", |
parameters: z.object({ |
url: z.string().url().describe("The URL to navigate to"), |
waitUntil: z |
.enum(["load", "domcontentloaded", "networkidle"]) |
.optional() |
.default("networkidle") |
.describe("When to consider navigation complete"), |
}), |
execute: async ({ url, waitUntil }) => { |
try { |
const stagehand = await sessionManager.ensureStagehand(); |
const page = stagehand.page; |
await page.goto(url, { waitUntil }); |
const title = await page.title(); |
const currentUrl = page.url(); |
return { |
success: true, |
url: currentUrl, |
title, |
message: `Successfully navigated to ${url}`, |
}; |
} catch (error) { |
const errorMessage = error instanceof Error ? error.message : String(error); |
throw new Error(`Navigation failed: ${errorMessage}`); |
} |
}, |
}); |
``` |
</details> |
Features: |
- URL navigation with configurable wait strategies |
- Returns page title and final URL after redirects |
- Waits for full page load |
- Error handling for navigation failures |
- Default: `networkidle` wait strategy |
#### Page Extract Tool |
Extracts structured data from web pages: |
<details> |
<summary>Show page-extract.tool.ts</summary> |
```typescript |
import { createTool } from "@voltagent/core"; |
import { z } from "zod"; |
import { sessionManager } from "../../stagehand-manager"; |
export const pageExtractTool = createTool({ |
name: "page_extract", |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.