refactor(browser): route get_browser_state_with_recovery screenshot through ScreenshotEvent#43
Draft
caffeinum wants to merge 1 commit into
Draft
Conversation
…hrough ScreenshotEvent Replaces the inline remove_highlights + direct page.screenshot bypass in get_browser_state_with_recovery with a ScreenshotEvent dispatch. ScreenshotWatchdog already handles the highlight strip centrally, so this collapses two strip sites into one and lets the watchdog handle bypass paths the same way it handles the normal path. CDP-based screenshot (via take_screenshot) replaces the playwright page.screenshot call, matching the canonical screenshot path used elsewhere in the session. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
Author
|
Cross-link: this PR is the centralized bbox-strip port mentioned as a follow-up in #42's "Out of scope" section. It also closes a latent bug where the Smoke-tested locally with real Chromium against wikipedia.org (94 interactive elements, |
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
BrowserSession.get_browser_state_with_recoverycurrently callspage.screenshot()directly wheninclude_screenshot=true, bypassingScreenshotWatchdog. This means:ScreenshotWatchdog.on_ScreenshotEventalready strips highlights viaremove_highlights()before capture, but the direct path skips the watchdog entirely. Action-overlay bboxes/labels can occlude trailing characters of credentials, copy buttons, and other text — we've seen the agent hallucinate truncations (e.g. reade2b_*cfase2b_*c) when overlays cover the right edge of a value.page.screenshot()is used instead of CDP. Other callers (screenshotaction, observation refreshes) already route throughtake_screenshot()which usesPage.captureScreenshotvia CDP. The direct path is the odd one out.Fix
Replace the inline
page.screenshot()call with aScreenshotEventdispatch:ScreenshotWatchdoghandles the strip and the CDP capture. Net diff: -26/+11 lines.Reference: Python upstream
Python
browser-usesolves the strip centrally inbrowser_use/browser/watchdogs/screenshot_watchdog.py:55-62—remove_highlights()runs inside the screenshot pipeline so every screenshot path is covered. This PR makes the TS port consistent with that design: one screenshot codepath, one strip site.Test plan
npx tsc --noEmitpasseshighlight_elements: true+include_screenshot: true→ full-page PNG returned, no overlays visible, 94 interactive elements indexed.Behavioral diff vs the direct path
take_screenshot()short-circuits onabout:blank/chrome://newtab/to a 4-pixel placeholder string; the old direct path would have captured a real (tiny black) screenshot. This is consistent with how the other callers oftake_screenshot()already behave.🤖 Generated with Claude Code