From e76aabb3a4121bdd4f9966ac0ed1d3166caddea9 Mon Sep 17 00:00:00 2001 From: Michael <108142320+xthanhn91@users.noreply.github.com> Date: Sat, 28 Feb 2026 13:09:03 +0700 Subject: [PATCH] fix(browser): return MEDIA: path from screenshot instead of truncated base64 (#8) handleScreenshot returned a truncated base64 string (first 100 chars only), which meant the screenshot data was effectively lost and never delivered to channels (Telegram, Discord, etc.) via the media pipeline. The media pipeline in loop.go looks for "MEDIA:" prefix in tool results to collect files for channel delivery (e.g. sendPhoto on Telegram). Without this prefix, screenshots were silently discarded. Fix: save screenshot bytes to a temp file and return MEDIA:/path, matching the pattern used by create_image and tts tools. --- pkg/browser/tool.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg/browser/tool.go b/pkg/browser/tool.go index 53aa66d5..c6decebb 100644 --- a/pkg/browser/tool.go +++ b/pkg/browser/tool.go @@ -2,9 +2,11 @@ package browser import ( "context" - "encoding/base64" "encoding/json" "fmt" + "os" + "path/filepath" + "time" "github.com/nextlevelbuilder/goclaw/internal/tools" ) @@ -247,8 +249,13 @@ func (t *BrowserTool) handleScreenshot(ctx context.Context, args map[string]inte return tools.ErrorResult(fmt.Sprintf("screenshot failed: %v", err)) } - encoded := base64.StdEncoding.EncodeToString(data) - return tools.NewResult(fmt.Sprintf("Screenshot captured (%d bytes). Base64: %s", len(data), encoded[:min(100, len(encoded))])) + // Save to temp file so the media pipeline can deliver it (e.g. Telegram sendPhoto) + imagePath := filepath.Join(os.TempDir(), fmt.Sprintf("goclaw_screenshot_%d.png", time.Now().UnixNano())) + if err := os.WriteFile(imagePath, data, 0644); err != nil { + return tools.ErrorResult(fmt.Sprintf("failed to save screenshot: %v", err)) + } + + return &tools.Result{ForLLM: fmt.Sprintf("MEDIA:%s", imagePath)} } func (t *BrowserTool) handleNavigate(ctx context.Context, args map[string]interface{}) *tools.Result {