Overview
Concrete DOM-based element locator for background mode that performs element interactions via chrome.scripting.executeScript without requiring debugger attachment.
Description
The DomLocator class implements element interactions for background mode automation. Instead of using CDP, it injects a function via `chrome.scripting.executeScript` that locates elements by a data-UID attribute (injected during DOM snapshot collection) and performs the requested action (click, fill, hover, bounding-box, value, editor-value). All methods return a `DomActionResponse<T>` with `success`, optional `error`, and optional `data`, providing a uniform error contract without throwing.
Usage
- Click: `const result = await new DomLocator(tabId).click(uid)`
- Fill: `await new DomLocator(tabId).fill(uid, { value: "text" })`
- Get value: `const { data } = await new DomLocator(tabId).value(uid)`
Code Reference
Source Location
- Repository: AIPex
- File: packages/browser-runtime/src/automation/dom-locator.ts
- Lines: L47-80 (class methods), L76-110+ (executeInPage), L1-45 (types)
Signature
export class DomLocator {
constructor(private tabId: number)
async click(uid: string, options?: ClickOptions): Promise<DomActionResponse>
async fill(uid: string, options: FillOptions): Promise<DomActionResponse>
async hover(uid: string, options?: HoverOptions): Promise<DomActionResponse>
async boundingBox(uid: string): Promise<DomActionResponse<BoundingBox | null>>
async value(uid: string): Promise<DomActionResponse<string | null>>
async editorValue(uid: string): Promise<DomActionResponse<string | null>>
}
interface DomActionResponse<T = void> {
success: boolean;
error?: string;
data?: T;
}
interface FillOptions {
value: string;
commit?: boolean;
highlight?: boolean;
scroll?: boolean;
}
Import
import { DomLocator } from "@aipexstudio/browser-runtime";
I/O Contract
Inputs
| Name |
Type |
Required |
Description
|
| uid |
string |
Yes |
Element UID from DOM snapshot
|
| options.value |
string |
Yes (fill) |
Text to type
|
| options |
FillOptions\|HoverOptions |
No |
Action options (highlight, scroll, commit)
|
Outputs
| Name |
Type |
Description
|
| returns |
DomActionResponse<T> |
{ success, error?, data? }
|
Usage Examples
Background Mode Click
import { DomLocator } from "@aipexstudio/browser-runtime";
const locator = new DomLocator(tabId);
const result = await locator.click("abc123");
if (!result.success) {
console.error("Click failed:", result.error);
}
Fill Input Field
const locator = new DomLocator(tabId);
const result = await locator.fill("uid_input_1", {
value: "user@example.com",
commit: true,
});
Related Pages
Implements Principle
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.