browserbase_screenshot
Capture browser screenshots to verify page state and locate elements when automated browser tools cannot provide needed visual information.
Instructions
Takes a screenshot of the current page. Use this tool to learn where you are on the page when controlling the browser with Stagehand. Only use this tool when the other tools are not sufficient to get the information you need.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | No | The name of the screenshot |
Implementation Reference
- src/tools/screenshot.ts:20-77 (handler)The main handler function that executes the screenshot logic: gets active page, takes screenshot, converts to base64, stores in resources, notifies server, and returns content with text and image.async function handleScreenshot( context: Context, params: ScreenshotInput, ): Promise<ToolResult> { const action = async (): Promise<ToolActionResult> => { try { const page = await context.getActivePage(); if (!page) { throw new Error("No active page available"); } const screenshotBuffer = await page.screenshot({ fullPage: false, }); // Convert buffer to base64 string and store in memory const screenshotBase64 = screenshotBuffer.toString("base64"); const name = params.name ? `screenshot-${params.name}-${new Date() .toISOString() .replace(/:/g, "-")}` : `screenshot-${new Date().toISOString().replace(/:/g, "-")}` + context.config.browserbaseProjectId; screenshots.set(name, screenshotBase64); // Notify the client that the resources changed const serverInstance = context.getServer(); if (serverInstance) { serverInstance.notification({ method: "notifications/resources/list_changed", }); } return { content: [ { type: "text", text: `Screenshot taken with name: ${name}`, }, { type: "image", data: screenshotBase64, mimeType: "image/png", }, ], }; } catch (error) { const errorMsg = error instanceof Error ? error.message : String(error); throw new Error(`Failed to take screenshot: ${errorMsg}`); } }; return { action, waitForNetwork: false, }; }
- src/tools/screenshot.ts:7-18 (schema)Defines the input schema using Zod (optional name parameter) and the tool schema including the name 'browserbase_screenshot', description, and input schema reference.const ScreenshotInputSchema = z.object({ name: z.string().optional().describe("The name of the screenshot"), }); type ScreenshotInput = z.infer<typeof ScreenshotInputSchema>; const screenshotSchema: ToolSchema<typeof ScreenshotInputSchema> = { name: "browserbase_screenshot", description: "Takes a screenshot of the current page. Use this tool to learn where you are on the page when controlling the browser with Stagehand. Only use this tool when the other tools are not sufficient to get the information you need.", inputSchema: ScreenshotInputSchema, };
- src/tools/screenshot.ts:79-85 (registration)Local registration of the tool by creating the Tool object with capability, schema, and handle function, then exporting as default.const screenshotTool: Tool<typeof ScreenshotInputSchema> = { capability: "core", schema: screenshotSchema, handle: handleScreenshot, }; export default screenshotTool;
- src/tools/index.ts:43-52 (registration)Central registration in the tools index file, where screenshotTool is included in the exported TOOLS array for use by the MCP server.export const TOOLS = [ ...multiSessionTools, ...sessionTools, navigateTool, actTool, extractTool, observeTool, screenshotTool, getUrlTool, ];