mirror of
https://github.com/vxcontrol/pentagi.git
synced 2026-07-20 23:57:11 -04:00
[GH-ISSUE #149] [Bug]: Browser tool discards successfully-fetched page content when screenshot fails #66
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @abcd123-xyz on GitHub (Feb 26, 2026).
Original GitHub issue: https://github.com/vxcontrol/pentagi/issues/149
Originally assigned to: @asdek on GitHub.
Affected Component
Core Services (Frontend UI/Backend API), AI Agents (Researcher/Developer/...)
Describe the bug
Summary
In
backend/pkg/tools/browser.go, theContentMD,ContentHTML, andLinksmethods run two concurrent operations: fetching page content and capturing a screenshot. If the screenshot request fails for any reason (scraper service unavailable, rate-limited, timeout, returned image too small), the function returns an error even though the page content was successfully retrieved, discarding the content entirely.The AI agent then receives:
…instead of the page content. The agent interprets this as the URL being unreachable and either retries, uses a fallback approach, or reports failure — all while the content was sitting in memory and then thrown away.
Root Cause
The screenshot is a non-critical side-effect — its only purpose is to write a PNG file to disk and log it via
b.scp.PutScreenshot. The caller (wrapCommandResult) already ignores the return value ofPutScreenshotwith_, _ = b.scp.PutScreenshot(...). This means the screenshot result is already treated as optional at the call-site, yet the function that produces it can abort the entire operation.Screenshot failures can occur due to:
callScraperclient has a hard 65-second timeout for all requests)minImgContentSize = 2048bytes — any minimal/styled-less page triggers this)writeScreenshotToFileAll of these are common in normal operation, especially during active penetration testing where the scraper service may be under load or targets may serve unusual responses.
Impact
markdown,html, andlinksare all broken by this.Steps to Reproduce
Steps to Reproduce
SCRAPER_PUBLIC_URLpointing to an unreachable address)./markdownendpoint.Alternatively, any URL that responds to content requests but returns a screenshot smaller than 2 KB (e.g., a short API response page) will trigger this in a fully-functional setup.
Expected Behavior
The browser tool should return the successfully-fetched content regardless of whether the screenshot succeeds. Screenshot failure should be logged as a warning and the operation should continue with an empty
screenshotName.Suggested Fix
The same fix should be applied to
ContentHTMLandLinks.System Configuration
System Configuration
Scraper service (Docker —
docker-compose.yml)vxcontrol/scraper:latest443/tcpSCRAPER_LISTEN_IP(default127.0.0.1):SCRAPER_LISTEN_PORT(default9443)MAX_CONCURRENT_SESSIONSLOCAL_SCRAPER_MAX_CONCURRENT_SESSIONS(default10)USERNAMELOCAL_SCRAPER_USERNAME(defaultsomeuser)PASSWORDLOCAL_SCRAPER_PASSWORD(defaultsomepass)shm_size: 2gBackend environment variables (
config.go)SCRAPER_PUBLIC_URLscPubURL)SCRAPER_PRIVATE_URL.htb,.local,.lan, etc.) (fed asscPrvURL)URL selection logic in
resolveUrl(): private URL is preferred when the hostname matches any local zone suffix; public URL is used otherwise. Either can fall back to the other if one is unset.Browser tool constants (
browser.go)minMdContentSize50bytesminHtmlContentSize300bytesminImgContentSize2048bytes65secondscallScraperrequest (both content fetch and screenshot)The
minImgContentSize = 2048threshold is a practical trigger for this bug: any URL that returns a short or CSS-less page (API endpoints, minimal status pages, login redirects) will produce a screenshot smaller than 2 KB and causegetScreenshotto return an error, discarding valid content even when content fetch succeeded.Logs and Artifacts
No response
Screenshots or Recordings
No response
Verification
@asdek commented on GitHub (Mar 2, 2026):
thank you for the Issue, it was added by #150