Add browse tool support.
I reviewed some MCPs (using OpenAI's deep research to help), and it
helped me choose chromedp as the relevant library and helped me come up
with an interface. This commit adds chrome to the Docker image which is
kind of big. (I've noticed that it's smaller on Ubuntu, where it doesn't
pull in X11.) go-playwright was a library contender as well.
Implement browser automation tooling using chromedp
This implementation adds browser automation capabilities to the system via the chromedp library,
enabling Claude to interact with web content effectively.
Key features include:
1. Core browser automation functionality:
- Created new browsertools package in claudetool/browser
- Implemented tools for navigating, clicking, typing, waiting for elements,
getting text, evaluating JavaScript, taking screenshots, and scrolling
- Added lazy browser initialization that defers until first use
- Integrated with the agent to expose these tools to Claude
2. Screenshot handling and display:
- Implemented screenshot storage with UUID-based IDs in /tmp/sketch-screenshots
- Added endpoint to serve screenshots via /screenshot/{id}
- Created dedicated UI component for displaying screenshots
- Ensured proper responsive design with loading states and error handling
- Fixed URL paths for proper rehomed URL support
- Modified tool calls component to auto-expand screenshot results
3. Error handling and reliability:
- Added graceful error handling for browser initialization failures
- Implemented proper cleanup of browser resources
The browser automation tools provide a powerful way for Claude to interact with web content,
making it possible to scrape data, test web applications, and automate web-based tasks.
Co-Authored-By: sketch <hello@sketch.dev>
diff --git a/claudetool/browse/register.go b/claudetool/browse/register.go
new file mode 100644
index 0000000..a540c8f
--- /dev/null
+++ b/claudetool/browse/register.go
@@ -0,0 +1,28 @@
+package browse
+
+import (
+ "context"
+ "log"
+
+ "sketch.dev/llm"
+)
+
+// RegisterBrowserTools initializes the browser tools and returns all the tools
+// ready to be added to an agent. It also returns a cleanup function that should
+// be called when done to properly close the browser.
+func RegisterBrowserTools(ctx context.Context) ([]*llm.Tool, func()) {
+ browserTools := NewBrowseTools(ctx)
+
+ // Initialize the browser
+ if err := browserTools.Initialize(); err != nil {
+ log.Printf("Warning: Failed to initialize browser: %v", err)
+ }
+
+ // Return all tools and a cleanup function
+ return browserTools.GetAllTools(), func() {
+ browserTools.Close()
+ }
+}
+
+// Tool is an alias for llm.Tool to make the documentation clearer
+type Tool = llm.Tool