import type { CdpProtocolClient } from "../core/cdp/protocol.js"; import { RefTable } from "./refs.js"; import { type SnapshotDiff, type SnapshotOptions, type SnapshotResult } from "./snapshot.js"; import { type ActionStep } from "./actions.js"; import { type ExtractOptions, type ExtractResult, type ScreenshotOptions, type ScreenshotResult, type ViewportMetrics } from "./read.js"; import { type DialogPolicy, type ObservationSnapshot, type ObservedConsole, type ObservedRequest } from "./observe.js"; import { type FindMatch } from "./find.js"; import { type WaitCondition, type WaitResult } from "./wait.js"; import { type SessionPolicyOptions, type SessionState } from "./policy.js"; import { InputState, type ClickOptions, type MouseButton } from "./input.js"; import type { Point } from "./types.js"; export interface TabHandle { tabId: string; targetId: string; cdpSessionId: string; url: string; refs: RefTable; input: InputState; lastSnapshot?: string; lastScreenshotHash?: string; } export interface AgentSessionOptions { /** Isolate each tab in its own browser context. Default true. */ isolateTabs?: boolean; navigationTimeoutMs?: number; /** Per-CDP-command ceiling. A stalled upstream must never wedge a session. */ commandTimeoutMs?: number; /** How javascript dialogs are answered so a prompt can never freeze the page. */ dialogPolicy?: DialogPolicy; observationLimit?: number; /** Capture the page's own console.* calls. Off by default: it needs * `Runtime.enable`, which bot detectors look for. */ pageConsole?: boolean; policy?: SessionPolicyOptions; /** Track tabs a page opens (links with target=_blank, window.open) as session tabs. */ adoptPopups?: boolean; /** Refuse to close the session's last tab. */ keepLastTab?: boolean; /** Let downloads proceed, saved to this folder on the browser's machine. Denied by default. */ downloadPath?: string; } export interface ReadPageOptions { /** visible (default): what is on screen, including text; interactive: only * controls; all: the whole page. */ filter?: "visible" | "interactive" | "all"; depth?: number; /** Read only the part of the page inside this element. */ ref?: string; maxChars?: number; } export interface ReadPageResult { text: string; truncated: boolean; } export interface TabInfo { tabId: string; url: string; title: string; active: boolean; } export interface ActOptions { tabId?: string; stopOnError?: boolean; settleMs?: number; actionabilityTimeoutMs?: number; snapshot?: SnapshotOptions; } export interface ActResult { ok: boolean; stepsRun: number; failedStep?: { index: number; step: ActionStep; error: string; }; changed: SnapshotDiff; url: string; session: SessionState; warning?: string; } export interface NavigateResult { tabId: string; url: string; title: string; snapshot: SnapshotResult; session: SessionState; warning?: string; } /** One agent session bound to a browser-level CDP connection. Owns its tabs and * their element reference tables; nothing is shared between sessions. */ export declare class AgentSession { private readonly cdp; private readonly opts; private readonly tabs; private activeTabId; private nextTabNumber; private closed; private readonly observations; private readonly policy; private expiredReason; private listenersAttached; private discovery?; private viewportSize?; private readonly adoptions; private readonly popupsAwaitingUrl; constructor(cdp: CdpProtocolClient, opts?: AgentSessionOptions); get state(): SessionState; get expired(): "idle" | "hard-cap" | null; get tabIds(): string[]; /** A tab by id, or the active tab when no id is given. */ tab(tabId?: string): TabHandle | null; get activeTab(): TabHandle | null; openTab(url?: string): Promise; private registerTarget; private ensureDiscovery; private adoptPopup; /** Waits until tabs the page just opened are attached and listed. */ settleTabs(): Promise; /** Every tab in the session with its current title and address. */ tabInventory(): Promise; /** Makes a tab the active one and brings it to the front so it renders. */ activateTab(tabId: string): Promise; navigate(url: string, tabId?: string): Promise; /** Loads a url and waits for it, without building a snapshot. */ goto(url: string, tabId?: string): Promise<{ tabId: string; url: string; title: string; }>; /** Runs steps in order against one tab, waits for the page to settle, and * returns only what changed. Stops at the first failing step by default. */ act(steps: ActionStep[], opts?: ActOptions): Promise; /** Goes back or forward in the tab's history, or reloads it. */ history(direction: "back" | "forward" | "reload", tabId?: string): Promise<{ url: string; title: string; }>; clickAt(point: Point, opts?: ClickOptions, tabId?: string): Promise; mouseMove(point: Point, tabId?: string): Promise; /** Presses a mouse button and keeps it held until {@link mouseUp}. */ mouseDown(point?: Point, button?: MouseButton, tabId?: string): Promise; mouseUp(point?: Point, button?: MouseButton, tabId?: string): Promise; drag(from: Point, to: Point, tabId?: string): Promise; /** Scrolls by pixel deltas at a point, so the element under it scrolls. */ wheel(point: Point, deltaX: number, deltaY: number, tabId?: string): Promise; /** Presses one chord given as parts (["Control", "c"]) or a space-separated * sequence of chords ("ctrl+a Delete"). */ pressKeys(keys: string | string[], repeat?: number, tabId?: string): Promise; /** Types text at whatever has focus, as if pasted. */ typeText(text: string, tabId?: string): Promise; /** Holds a key down until {@link keyUp}; later input sees it as a held modifier. */ keyDown(name: string, tabId?: string): Promise; keyUp(name: string, tabId?: string): Promise; /** Releases every held button and key in a tab. */ releaseInput(tabId?: string): Promise; /** Waits until the page stops changing (at most `ms`), resetting refs if it navigated. */ waitForSettle(ms?: number, tabId?: string): Promise; snapshot(opts?: SnapshotOptions, tabId?: string): Promise; /** The page as an indented outline of controls, headings and text, with refs * that every action accepts. Refs already handed out keep their ids. */ readPage(opts?: ReadPageOptions, tabId?: string): Promise; /** Elements matching a plain-language description, best first, by shared words. */ find(query: string, tabId?: string): Promise; /** Console output and network requests recorded after `cursor`, with the cursor to pass next time. */ readLogs(cursor?: number): { console: ObservedConsole[]; requests: ObservedRequest[]; cursor: number; }; /** Page content as text, markdown or a link list. */ extract(opts?: ExtractOptions, tabId?: string): Promise; /** Fixes the page size the tab renders at, in CSS pixels. `deviceScaleFactor` * defaults to 1 so screenshot pixels and input coordinates are the same unit. */ setViewport(size: { width: number; height: number; deviceScaleFactor?: number; }, tabId?: string): Promise; /** The visible area as the page reports it now, which may differ from what was asked for. */ viewport(tabId?: string): Promise; /** Screenshot, JPEG unless asked otherwise. With `skipIfUnchanged` an identical image is reported, not resent. */ screenshot(opts?: ScreenshotOptions, tabId?: string): Promise; waitFor(condition: WaitCondition, tabId?: string): Promise; /** Runs an expression in the page and returns its value. */ evaluate(expression: string, tabId?: string): Promise; /** Console output, failed requests, downloads, dialogs and popup tabs seen so far. */ observed(afterMs?: number): ObservationSnapshot; setDialogPolicy(policy: DialogPolicy): void; closeTab(tabId: string): Promise; selectTab(tabId: string): TabHandle; /** Closes this session's tabs. Never closes the upstream browser: it may be * shared with other sessions and other clients. */ close(): Promise; private withInput; /** Runs a command that starts a page load and waits for the load to finish, * including pages restored from the back-forward cache. */ private loadingVia; private requireTab; private macBrowser?; private isMacBrowser; private sendKeepalive; private expire; private attachObservers; private ownsTarget; private sender; private settle; private send; private assertOpen; private waitForLoad; private currentUrl; private currentTitle; } //# sourceMappingURL=session.d.ts.map