Skip to content

fix: prevent screenshot --annotate from hanging on complex pages#659

Open
juliobrasa wants to merge 1 commit intovercel-labs:mainfrom
juliobrasa:fix/annotate-screenshot-hang
Open

fix: prevent screenshot --annotate from hanging on complex pages#659
juliobrasa wants to merge 1 commit intovercel-labs:mainfrom
juliobrasa:fix/annotate-screenshot-hang

Conversation

@juliobrasa
Copy link

Summary

On pages with many interactive elements, screenshot --annotate fires hundreds of boundingBox() calls simultaneously via Promise.all, saturating Chrome's CDP connection and causing timeouts/hangs (confirmed on both macOS and Linux).

Root cause

Object.entries(refs) on a complex page can yield 200+ entries. Calling locator.boundingBox() for all of them in a single Promise.all overwhelms the CDP websocket connection, causing Chrome to become unresponsive.

Fix

  • Process elements in batches of 20 instead of all at once
  • Add a 1-second timeout per element — elements that time out are skipped rather than blocking the entire operation
  • No change to output format or annotation quality

Before

$ agent-browser screenshot --annotate  # complex page
# Hangs indefinitely, Chrome CPU spikes to 100%

After

$ agent-browser screenshot --annotate  # complex page
# Completes in seconds, some slow elements may be skipped

Test plan

  • TypeScript compiles without errors
  • Prettier passes (pre-commit hook)
  • Manual test on simple page (example.com) — all annotations present
  • Manual test on complex page (e.g. GitHub dashboard) — completes without hanging

Closes #509

🤖 Generated with Claude Code

On pages with many interactive elements, `screenshot --annotate` would
fire hundreds of `boundingBox()` calls simultaneously via `Promise.all`,
saturating Chrome's CDP connection and causing timeouts/hangs.

Fix: process elements in batches of 20 with a 1-second timeout per
element. Elements that time out are skipped (treated as null) rather
than blocking the entire operation.

Closes vercel-labs#509

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel
Copy link
Contributor

vercel bot commented Mar 6, 2026

Someone is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Screenshots with --annotate hang

1 participant