Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:A9T9 RPA searchImageInExtension

From Leeroopedia
Knowledge Sources
Domains Computer_Vision, WASM
Last Updated 2026-10-22 00:00 GMT

Overview

Concrete tool for in-extension template matching using a Rust vision-core WASM worker, provided by the Ui.Vision vision2 adaptor.

Description

The searchImageInExtension function (`src/services/vision2/adaptor.ts`) performs template matching entirely within the extension using a WebAssembly module compiled from a Rust vision-core. It runs in a dedicated Web Worker (`/lib/vision2/worker.js`) to avoid blocking the UI thread. The WASM engine uses zero-mean normalized cross-correlation (NCC) with a DPI-prior scale band (`patternScale`), which prevents flat regions from false-positive matching and handles moderate size variations.

The `postSearchJob` function manages the worker lifecycle: it lazily creates and initializes the worker, posts search jobs, and returns results via a promise keyed by job ID. The `toFindResult` function converts raw worker match rectangles into `ConvertResultItem` objects with viewport/page/offset coordinates scaled by the inverse of `scaleDownRatio`.

Green/pink box patterns (relative visual search) are NOT supported by this engine — such macros stay on the legacy kantusearch engine.

Usage

Call `searchImageInExtension` when the search scope is browser (in-extension WASM matching). It is normally called by the vision2 router, not directly.

Code Reference

Source Location

  • Repository: A9T9/RPA
  • File: src/services/vision2/adaptor.ts
  • Lines: L1-L60 (postSearchJob, getWorker, toFindResult), L165-L220 (searchImageInExtension)

Signature

export function searchImageInExtension(
  req: SearchImageInExtensionRequest
): Promise<ConvertResultItem[]>

interface SearchImageInExtensionRequest {
  targetImageUrl: string,      // Screenshot data URI
  patternImageUrl: string,     // Pattern image data URI
  searchAreaRect?: Rect,       // Optional crop region
  scaleDownRatio: number,      // Scale factor (1/dpiRatio)
  patternScale: number,        // Pattern scaling prior
  minSimilarity: number,       // Confidence threshold
  allowSizeVariation: boolean,
  pageOffset: { x: number, y: number },
  viewportOffset: { x: number, y: number }
}

Import

import { searchImageInExtension } from '@/services/vision2/adaptor'

I/O Contract

Inputs

Name Type Required Description
targetImageUrl string Yes Screenshot data URI (the scene to search in)
patternImageUrl string Yes Pattern image data URI (the template)
searchAreaRect Rect No Crop region within the screenshot
scaleDownRatio number Yes Scale factor for coordinate normalization
minSimilarity number Yes Confidence threshold (0.1-1.0)

Outputs

Name Type Description
results ConvertResultItem[] Match results with offsetLeft/Top, viewportLeft/Top, pageLeft/Top, width, height, score

Usage Examples

Run a Template Match

import { searchImageInExtension } from '@/services/vision2/adaptor'

const results = await searchImageInExtension({
  targetImageUrl: screenshotDataURI,
  patternImageUrl: patternDataURI,
  scaleDownRatio: 1.0,
  patternScale: 1.0,
  minSimilarity: 0.8,
  allowSizeVariation: false,
  pageOffset: { x: 0, y: 0 },
  viewportOffset: { x: 0, y: 0 }
})

const best = results[0]
if (best) {
  console.log(`Match at viewport (${best.matched.viewportLeft}, ${best.matched.viewportTop}) score=${best.matched.score}`)
}

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment