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:AIPexStudio AIPex ElementCaptureService

From Leeroopedia
Knowledge Sources
Domains Browser_Automation, Human_Computer_Interaction
Last Updated 2026-10-24 12:00 GMT

Overview

Concrete singleton service that captures user clicks on page elements, collecting element metadata, selectors, and screenshots for the monitor-operation intervention type.

Description

The ElementCaptureService class enables the monitor-operation intervention by listening for user clicks on a target page. It validates the tab (rejects restricted pages like chrome://), sends a "start-capture" message to the content script, listens for click events via `chrome.runtime.onMessage`, and collects element metadata including selector, tagName, text content, and attributes. It also captures a cropped screenshot of the clicked element using `captureVisibleTabWithElementCrop`. The service is a singleton that enforces one capture session at a time.

Usage

  • Start capture: `await ElementCaptureService.getInstance().startCapture({ tabId }, callback)`
  • Callback receives `ElementCaptureEvent` with element details and screenshot.

Code Reference

Source Location

  • Repository: AIPex
  • File: packages/browser-runtime/src/intervention/element-capture.ts
  • Lines: L17-80 (class, startCapture), L309 (file end)
  • Support: packages/browser-runtime/src/tools/screenshot-helpers.ts (captureVisibleTabWithElementCrop)

Signature

export class ElementCaptureService {
  static getInstance(): ElementCaptureService
  async startCapture(
    options: ElementCaptureOptions,
    callback: (event: ElementCaptureEvent) => void
  ): Promise<void>
  stopCapture(): void
}

interface ElementCaptureOptions {
  tabId: number;
}

interface ElementCaptureEvent {
  selector: string;
  tagName: string;
  text?: string;
  id?: string;
  classes?: string[];
  attributes?: Record<string, string>;
  screenshot?: string;  // base64 data URL
}

Import

import { ElementCaptureService } from "@aipexstudio/browser-runtime";

I/O Contract

Inputs

Name Type Required Description
options.tabId number Yes Target tab to capture clicks from
callback (event) => void Yes Called when user clicks an element

Outputs

Name Type Description
callback event ElementCaptureEvent Element selector, tagName, text, attributes, screenshot

Usage Examples

Monitor User Clicks

import { ElementCaptureService } from "@aipexstudio/browser-runtime";

const captureService = ElementCaptureService.getInstance();

await captureService.startCapture({ tabId: activeTabId }, (event) => {
  console.log("User clicked:", event.tagName, event.text);
  console.log("Selector:", event.selector);
  if (event.screenshot) {
    showElementPreview(event.screenshot);
  }
});

// Stop capturing when done:
captureService.stopCapture();

Related Pages

Implements Principle

Uses Heuristics

Requires Environment

Page Connections

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