/** * BrowserSession — Playwright wrapper managing a singleton browser + page. * Auto-closes after idle timeout (5 minutes). * Supports live view streaming (JPEG frames) and direct interaction. */ import type { Page } from 'playwright'; import { BrowserActionLog } from './browser-action-log'; import { DeviceEmulation } from './device-presets'; export { FOCUS_REPORTING_SCRIPT, SET_FOCUSED_INPUT_VALUE_SCRIPT } from './page-scripts'; /** * Payload passed to Playwright's `FileChooser.setFiles`. * - `string[]`: absolute paths on the agent FS (workspace files chosen by the user). * - `Array<{name,mimeType,buffer}>`: in-memory file content uploaded from the web client * as base64. Playwright forwards the buffer directly to the browser via CDP, so no * temp files are needed and there is no race between file deletion and browser read. */ export type FileChooserPayload = string[] | Array<{ name: string; mimeType: string; buffer: Buffer; }>; /** * Payload emitted to the Web client when the focused input/textarea changes, * its value/selection changes, or focus leaves a reporting target. * * Mirrors the `browser_focus_changed` wire contract (rect and below). When * `focused` is false, the overlay is hidden and the remaining fields are * omitted. Coordinates in `rect` are getBoundingClientRect raw values * (CSS px, viewport-relative). */ export interface FocusChangePayload { /** Whether a reporting-target input/textarea is focused. false hides overlay. */ focused: boolean; /** getBoundingClientRect of the focused element (CSS px, viewport-relative). */ rect?: { x: number; y: number; width: number; height: number; }; /** Current value of the element. */ value?: string; selectionStart?: number; selectionEnd?: number; /** True when the element is a