This package provides a set of tools that allow Claude to control a headless Chrome browser from Go. The tools are built using the chromedp library.
browser_navigate - Navigate to a URL and wait for the page to loadbrowser_eval - Evaluate JavaScript in the browser contextbrowser_screenshot - Take a screenshot of the page or a specific element// Create a context ctx := context.Background() // Register browser tools and get a cleanup function tools, cleanup := browse.RegisterBrowserTools(ctx) defer cleanup() // Important: always call cleanup to release browser resources // Add tools to your agent for _, tool := range tools { agent.AddTool(tool) }
chromedp package handles launching and controlling the browserAll tools follow a standard JSON input/output format. For example:
Navigate Tool Input:
{ "url": "https://example.com" }
Navigate Tool Output (success):
{ "status": "success" }
Tool Output (error):
{ "status": "error", "error": "Error message" }
// Example of using the navigate tool directly navTool := tools[0] // Get browser_navigate tool input := map[string]string{"url": "https://example.com"} inputJSON, _ := json.Marshal(input) // Call the tool result, err := navTool.Run(ctx, json.RawMessage(inputJSON)) if err != nil { log.Fatalf("Error: %v", err) } fmt.Println(result)
The browser screenshot tool has been modified to save screenshots to a temporary directory and identify them by ID, rather than returning base64-encoded data directly. This improves efficiency by:
/tmp/sketch-screenshots/ with a unique UUID filename/screenshot/{id} endpointAgent calls the screenshot tool:
{ "id": "tool_call_123", "name": "browser_screenshot", "params": {} }
Tool response:
{ "id": "tool_call_123", "result": { "id": "550e8400-e29b-41d4-a716-446655440000" } }
The screenshot is then accessible at: /screenshot/550e8400-e29b-41d4-a716-446655440000