Heuristic:A9T9 RPA CaptureVisibleTab Rate Limiting
| Knowledge Sources | |
|---|---|
| Domains | Optimization, Browser_Automation |
| Last Updated | 2026-10-22 17:48 GMT |
Overview
Chrome enforces a ~2 captureVisibleTab calls/second per-extension rate limit; a shared throttle with module-level state prevents MAX_CAPTURE_VISIBLE_TAB_CALLS_PER_SECOND errors across all service instances.
Description
Chrome limits chrome.tabs.captureVisibleTab to approximately 2 calls per second per extension. Multiple CaptureScreenshotService instances are created across the app (in index.js, run_command.ts, and helper.ts builds one per capture call). With instance-local state, each instance starts with a fresh budget and parallel or back-to-back captures burst past the quota. The fix: module-level shared variables (sharedNextSlotAt, sharedLastWarnAt) that serialize all capture calls across every service instance, spacing them at 1000/MAX + 100ms apart.
Usage
Use this heuristic whenever multiple parts of the extension take screenshots concurrently — vision search retry loops, full-page capture stitching, OCR capture, or the AI agent's screenshot tool. The shared throttle is built into CaptureScreenshotService and is always active.
The Insight (Rule of Thumb)
- Action: Use module-level (not instance-level) shared state for the next-available capture slot.
- Value: Interval =
Math.ceil(1000 / MAX_CAPTURE_VISIBLE_TAB_CALLS_PER_SECOND) + 100ms (≈600ms between captures at MAX=2). - Trade-off: Adds up to ~600ms delay per capture; vision retry loops that need rapid re-capture are throttled to ~1.6/sec.
- Compatibility: Reads
chrome.tabs.MAX_CAPTURE_VISIBLE_TAB_CALLS_PER_SECONDwhen available; defaults to 2. - Warning: Fires
onThrottleWaitcallback (rate-limited to once per 5s) when a capture waits >200ms, so the UI can warn the user.
Reasoning
The earlier throttle used MAX * 1000 + 100 (2.1s between captures), which over-throttled vision retry loops ~4x. The corrected formula 1000/MAX + 100 (≈600ms) stays just under the quota while allowing ~1.6 captures/sec — enough for vision retry loops without hitting the limit. The 100ms safety margin accounts for timing jitter.
The onThrottleWait callback is rate-limited itself (5s between warnings) to avoid flooding the UI with throttle notices during vision loops. Logging must never break capture (wrapped in try/catch).