mirror of
https://github.com/Tencent/BrowserSkill.git
synced 2026-09-10 13:01:23 +08:00
Every tool.observe moved the real cursor across the page to look for hover-only menus and tooltips. Measured against real Chrome, that cost a median of 2.5s and up to 4.7s per observation — 73% to 99% of total observe wall clock — and returned 3 hits across 12 pages. A positive control confirms the probes work; the yield on real pages simply does not justify putting them on the default path. observe now probes only when asked, via `probe_hover` (`--probe-hover`). Agents that know which element hides a menu should keep using `bsk hover <ref>`, which is both cheaper and precise. A held hover latch still suppresses probing, since probing would move the cursor off the element the caller is deliberately holding. Correctness fixes that apply whether or not probing is requested: - Hover probing ran between the DOM snapshot and the accessibility tree fetch, so a hover that opened a menu left one half of an observation describing the page before the change and the other half after it. Both chains now run after all capture is complete. - The overlay bypass toggled once per chain and swallowed restore failures, which could leave the agent overlay hidden for the rest of the tab's life. It is now reference counted across both chains, and a failed restore is reported instead of discarded. - Observations report whether they hovered the page and whether that revealed content the static tree lacks, so callers can judge how far the live page may have drifted from the returned snapshot. Probe budgets were checked at the top of the loop, so a candidate could start with 1ms remaining and still run a full settle window, overshooting by up to 634ms. Candidates are now admitted only if they fit. Raising MAX_HOVER_PROBE_MS to 2600 is part of that fix rather than a relaxation: 2000 was never the real ceiling, and enforcing it literally would have silently dropped a candidate the positive control depends on. Tooltip misses are cached too, with a shorter TTL than hits, so repeat observations of the same page no longer re-probe every unlabelled control from scratch.
102 lines
3.4 KiB
TypeScript
102 lines
3.4 KiB
TypeScript
import type { Rect, RenderedRef, VomResult } from "@browser-skill/vom";
|
|
import type { CdpTarget } from "@/browser-driver/frame-graph";
|
|
import { readRecordingDocumentIdentity } from "@/shared/recording-document-identity";
|
|
import type { CapturedSurfaceProbe } from "./capture";
|
|
import type { CapturedFrameDocument, FrameAxNode } from "./frame-capture";
|
|
|
|
/** Frame identity needed to resolve an `@eN` that lives in an iframe. */
|
|
export interface CaptureVomFrame {
|
|
frameId: string;
|
|
target: CdpTarget;
|
|
parentFrameId?: string;
|
|
ownerBackendNodeId?: number;
|
|
/** BrowserSkill-generated identity for the recording agent in this Document. */
|
|
recordingDocumentId?: string;
|
|
}
|
|
|
|
/** Allowlisted geometry used to match a recorded action to a rendered ref. */
|
|
export interface CaptureVomMatchNode {
|
|
frameId: string;
|
|
backendNodeId: number;
|
|
tag: string;
|
|
/** Top-level viewport-relative geometry. */
|
|
rect: Rect | null;
|
|
/** Frame-local viewport-relative geometry, when available. */
|
|
localRect?: Rect | null;
|
|
}
|
|
|
|
/**
|
|
* Raw AX/DOM trees are never returned. When `redactValues` is enabled by the
|
|
* caller, form values in `text` are masked as well.
|
|
*/
|
|
export interface CaptureVomObservationResult {
|
|
text: string;
|
|
refs: RenderedRef[];
|
|
truncated: boolean;
|
|
rootFrameId: string;
|
|
frames: CaptureVomFrame[];
|
|
matchNodes: CaptureVomMatchNode[];
|
|
surfaceProbes?: CapturedSurfaceProbe[];
|
|
/**
|
|
* Whether this observation actively hovered the page, and whether that
|
|
* revealed content the static tree does not contain. Lets callers judge how
|
|
* far the page may have drifted from the returned snapshot.
|
|
*/
|
|
hoverProbe?: HoverProbeReport;
|
|
}
|
|
|
|
export interface HoverProbeReport {
|
|
performed: boolean;
|
|
revealedContent: boolean;
|
|
}
|
|
|
|
function projectFrames(documents: CapturedFrameDocument<FrameAxNode>[]): CaptureVomFrame[] {
|
|
return documents.map((document) => {
|
|
let recordingDocumentId: string | undefined;
|
|
for (const node of document.domNodes) {
|
|
recordingDocumentId = readRecordingDocumentIdentity(node.attrs);
|
|
if (recordingDocumentId) break;
|
|
}
|
|
return {
|
|
frameId: document.frameId,
|
|
target: document.target,
|
|
...(document.parentFrameId ? { parentFrameId: document.parentFrameId } : {}),
|
|
...(document.ownerBackendNodeId !== undefined
|
|
? { ownerBackendNodeId: document.ownerBackendNodeId }
|
|
: {}),
|
|
...(recordingDocumentId ? { recordingDocumentId } : {}),
|
|
};
|
|
});
|
|
}
|
|
|
|
function projectMatchNodes(documents: CapturedFrameDocument<FrameAxNode>[]): CaptureVomMatchNode[] {
|
|
return documents.flatMap((document) =>
|
|
document.domNodes.map((node) => ({
|
|
frameId: document.frameId,
|
|
backendNodeId: node.backendNodeId,
|
|
tag: node.tag,
|
|
rect: node.rect,
|
|
...(node.localRect !== undefined ? { localRect: node.localRect } : {}),
|
|
})),
|
|
);
|
|
}
|
|
|
|
export function projectRecordSafeObservation(input: {
|
|
rootFrameId: string;
|
|
frameDocuments: CapturedFrameDocument<FrameAxNode>[];
|
|
rendered: VomResult;
|
|
surfaceProbes?: CapturedSurfaceProbe[];
|
|
hoverProbe?: HoverProbeReport;
|
|
}): CaptureVomObservationResult {
|
|
return {
|
|
text: input.rendered.text,
|
|
refs: input.rendered.refs,
|
|
truncated: input.rendered.truncated,
|
|
rootFrameId: input.rootFrameId,
|
|
frames: projectFrames(input.frameDocuments),
|
|
matchNodes: projectMatchNodes(input.frameDocuments),
|
|
surfaceProbes: input.surfaceProbes,
|
|
...(input.hoverProbe ? { hoverProbe: input.hoverProbe } : {}),
|
|
};
|
|
}
|