Implementation:A9T9 RPA CaptureScreenshotService
| Knowledge Sources | |
|---|---|
| Domains | Browser_Automation, Screenshot_Capture |
| Last Updated | 2026-10-22 00:00 GMT |
Overview
Concrete tool for capturing browser tab screenshots with DPI-aware scaling and rate limiting, provided by the Ui.Vision screenshot capture service.
Description
The CaptureScreenshotService class (`src/common/capture_screenshot.ts`) wraps Chrome's `chrome.tabs.captureVisibleTab` API with rate limiting (Chrome allows a maximum of 2 captures per second — the service spaces captures accordingly with a safety margin) and DPI-aware scaling. It is the screenshot source for both the image search pipeline and the OCR text recognition pipeline.
Key methods:
- `captureScreen`: captures the visible tab and returns a PNG data URI, with optional DPI ratio scaling
- `captureFullScreen`: captures a full-page screenshot via scroll-and-stitch
- `saveScreen` / `saveFullScreen`: capture and persist to screenshot storage
- `getScreenshotRatio`: computes the DPI ratio between the captured image and the viewport
- `scaleDataURI`: scales a screenshot data URI by a given ratio
The DPI ratio is critical: image search and OCR coordinates must be normalized between image pixels (device resolution) and CSS pixels (viewport coordinates) for correct click targeting.
Usage
Use this service when you need to capture a screenshot of the visible browser tab for image search, OCR, or visual verification. The service handles Chrome's rate limit automatically.
Code Reference
Source Location
- Repository: A9T9/RPA
- File: src/common/capture_screenshot.ts
- Lines: L17-L27 (getScreenshotRatio), L28-L52 (scaleDataURI), L70-L468 (CaptureScreenshotService class)
Signature
export class CaptureScreenshotService {
constructor(params: CaptureScreenshotServiceParams)
captureScreen(
tabId: number,
devicePixelRatio: number,
presetScreenshotRatio?: number | ((ratio: number) => void)
): Promise<string>
captureFullScreen(
tabId: number,
clientAPI?: CaptureClientAPI,
options?: { blob: boolean }
): Promise<string>
saveScreen(
storage: IStandardStorage & IWithLinkStorage,
tabId: number,
fileName: string,
devicePixelRatio: number
): Promise<{ url: string, fileName: string }>
}
export function getScreenshotRatio(
dataURI: string,
tabId: number,
devicePixelRatio: number
): Promise<number>
export function scaleDataURI(dataURI: string, scale: number): Promise<string>
Import
import {
CaptureScreenshotService,
getScreenshotRatio,
scaleDataURI
} from '@/common/capture_screenshot'
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| tabId | number | Yes | Target tab ID |
| devicePixelRatio | number | Yes | Device pixel ratio for DPI normalization |
| options.format | string | No | Capture format (default 'png') |
Outputs
| Name | Type | Description |
|---|---|---|
| dataURI | string | PNG data URI of the captured screenshot |
| screenshotRatio | number | DPI ratio between captured pixels and viewport |
Usage Examples
Capture the Visible Tab
import { CaptureScreenshotService } from '@/common/capture_screenshot'
const service = new CaptureScreenshotService({
captureVisibleTab: (windowId, options) => chrome.tabs.captureVisibleTab(windowId, options)
})
const dataURI = await service.captureScreen(tabId, window.devicePixelRatio)
// dataURI is a PNG data URI ready for image search or OCR
Capture with DPI Ratio
import { getScreenshotRatio, scaleDataURI } from '@/common/capture_screenshot'
const ratio = await getScreenshotRatio(dataURI, tabId, window.devicePixelRatio)
const scaledURI = await scaleDataURI(dataURI, ratio)