browser-pilot 0.0.10 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,9 +1,9 @@
1
1
  export { BatchExecutor, ValidationError, ValidationResult, addBatchToPage, validateSteps } from './actions.cjs';
2
- import { R as RequestPattern, a as RequestHandler, C as CaptureResult } from './types-CYw-7vx1.cjs';
3
- export { k as ActionOptions, l as ActionResult, A as ActionType, d as AudioChunk, e as AudioInput, f as AudioInputState, g as AudioOutput, B as BatchOptions, b as BatchResult, h as CaptureOptions, a3 as ClearCookiesOptions, m as ConsoleHandler, n as ConsoleMessage, o as ConsoleMessageType, Y as ContinueRequestOptions, a4 as Cookie, p as CustomSelectConfig, a5 as DeleteCookieOptions, O as DeviceDescriptor, Q as DeviceName, D as Dialog, q as DialogHandler, r as DialogType, s as Download, E as ElementInfo, t as ElementNotFoundError, u as EmulationState, v as ErrorHandler, Z as FailRequestOptions, F as FileInput, w as FillOptions, _ as FulfillRequestOptions, G as GeolocationOptions, I as InteractiveElement, $ as InterceptedRequest, N as NavigationError, x as NetworkIdleOptions, y as Page, z as PageError, H as PageSnapshot, P as PlayOptions, a0 as RequestActions, a1 as ResourceType, i as RoundTripOptions, j as RoundTripResult, a2 as RouteOptions, a6 as SetCookieOptions, J as SnapshotNode, S as Step, c as StepResult, K as SubmitOptions, T as TimeoutError, L as TypeOptions, U as UserAgentMetadata, M as UserAgentOptions, V as ViewportOptions, W as WaitForOptions, a7 as WaitOptions, a8 as WaitResult, a9 as WaitState, X as devices, aa as waitForAnyElement, ab as waitForElement, ac as waitForNavigation, ad as waitForNetworkIdle } from './types-CYw-7vx1.cjs';
2
+ import { R as RequestPattern, a as RequestHandler, C as CaptureResult } from './types-BOPu0OQZ.cjs';
3
+ export { k as ActionOptions, l as ActionResult, A as ActionType, d as AudioChunk, e as AudioInput, f as AudioInputState, g as AudioOutput, B as BatchOptions, b as BatchResult, h as CaptureOptions, a3 as ClearCookiesOptions, m as ConsoleHandler, n as ConsoleMessage, o as ConsoleMessageType, Y as ContinueRequestOptions, a4 as Cookie, p as CustomSelectConfig, a5 as DeleteCookieOptions, O as DeviceDescriptor, Q as DeviceName, D as Dialog, q as DialogHandler, r as DialogType, s as Download, E as ElementInfo, t as ElementNotFoundError, u as EmulationState, v as ErrorHandler, Z as FailRequestOptions, F as FileInput, w as FillOptions, _ as FulfillRequestOptions, G as GeolocationOptions, I as InteractiveElement, $ as InterceptedRequest, N as NavigationError, x as NetworkIdleOptions, y as Page, z as PageError, H as PageSnapshot, P as PlayOptions, a0 as RequestActions, a1 as ResourceType, i as RoundTripOptions, j as RoundTripResult, a2 as RouteOptions, a6 as SetCookieOptions, J as SnapshotNode, S as Step, c as StepResult, K as SubmitOptions, T as TimeoutError, L as TypeOptions, U as UserAgentMetadata, M as UserAgentOptions, V as ViewportOptions, W as WaitForOptions, a7 as WaitOptions, a8 as WaitResult, a9 as WaitState, X as devices, aa as waitForAnyElement, ab as waitForElement, ac as waitForNavigation, ad as waitForNetworkIdle } from './types-BOPu0OQZ.cjs';
4
4
  import { C as CDPClient } from './client-7Nqka5MV.cjs';
5
5
  export { a as CDPClientOptions, c as createCDPClient } from './client-7Nqka5MV.cjs';
6
- export { Browser, BrowserOptions, connect } from './browser.cjs';
6
+ export { Browser, BrowserOptions, PageOptions, connect } from './browser.cjs';
7
7
  export { CDPError } from './cdp.cjs';
8
8
  export { BrowserBaseProvider, BrowserlessProvider, GenericProvider, createProvider, discoverTargets, getBrowserWebSocketUrl } from './providers.cjs';
9
9
  export { b as ConnectOptions, C as CreateSessionOptions, P as Provider, a as ProviderSession } from './types--wXNHUwt.cjs';
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  export { BatchExecutor, ValidationError, ValidationResult, addBatchToPage, validateSteps } from './actions.js';
2
- import { R as RequestPattern, a as RequestHandler, C as CaptureResult } from './types-DOGsEYQa.js';
3
- export { k as ActionOptions, l as ActionResult, A as ActionType, d as AudioChunk, e as AudioInput, f as AudioInputState, g as AudioOutput, B as BatchOptions, b as BatchResult, h as CaptureOptions, a3 as ClearCookiesOptions, m as ConsoleHandler, n as ConsoleMessage, o as ConsoleMessageType, Y as ContinueRequestOptions, a4 as Cookie, p as CustomSelectConfig, a5 as DeleteCookieOptions, O as DeviceDescriptor, Q as DeviceName, D as Dialog, q as DialogHandler, r as DialogType, s as Download, E as ElementInfo, t as ElementNotFoundError, u as EmulationState, v as ErrorHandler, Z as FailRequestOptions, F as FileInput, w as FillOptions, _ as FulfillRequestOptions, G as GeolocationOptions, I as InteractiveElement, $ as InterceptedRequest, N as NavigationError, x as NetworkIdleOptions, y as Page, z as PageError, H as PageSnapshot, P as PlayOptions, a0 as RequestActions, a1 as ResourceType, i as RoundTripOptions, j as RoundTripResult, a2 as RouteOptions, a6 as SetCookieOptions, J as SnapshotNode, S as Step, c as StepResult, K as SubmitOptions, T as TimeoutError, L as TypeOptions, U as UserAgentMetadata, M as UserAgentOptions, V as ViewportOptions, W as WaitForOptions, a7 as WaitOptions, a8 as WaitResult, a9 as WaitState, X as devices, aa as waitForAnyElement, ab as waitForElement, ac as waitForNavigation, ad as waitForNetworkIdle } from './types-DOGsEYQa.js';
2
+ import { R as RequestPattern, a as RequestHandler, C as CaptureResult } from './types-j23Iqo2L.js';
3
+ export { k as ActionOptions, l as ActionResult, A as ActionType, d as AudioChunk, e as AudioInput, f as AudioInputState, g as AudioOutput, B as BatchOptions, b as BatchResult, h as CaptureOptions, a3 as ClearCookiesOptions, m as ConsoleHandler, n as ConsoleMessage, o as ConsoleMessageType, Y as ContinueRequestOptions, a4 as Cookie, p as CustomSelectConfig, a5 as DeleteCookieOptions, O as DeviceDescriptor, Q as DeviceName, D as Dialog, q as DialogHandler, r as DialogType, s as Download, E as ElementInfo, t as ElementNotFoundError, u as EmulationState, v as ErrorHandler, Z as FailRequestOptions, F as FileInput, w as FillOptions, _ as FulfillRequestOptions, G as GeolocationOptions, I as InteractiveElement, $ as InterceptedRequest, N as NavigationError, x as NetworkIdleOptions, y as Page, z as PageError, H as PageSnapshot, P as PlayOptions, a0 as RequestActions, a1 as ResourceType, i as RoundTripOptions, j as RoundTripResult, a2 as RouteOptions, a6 as SetCookieOptions, J as SnapshotNode, S as Step, c as StepResult, K as SubmitOptions, T as TimeoutError, L as TypeOptions, U as UserAgentMetadata, M as UserAgentOptions, V as ViewportOptions, W as WaitForOptions, a7 as WaitOptions, a8 as WaitResult, a9 as WaitState, X as devices, aa as waitForAnyElement, ab as waitForElement, ac as waitForNavigation, ad as waitForNetworkIdle } from './types-j23Iqo2L.js';
4
4
  import { C as CDPClient } from './client-7Nqka5MV.js';
5
5
  export { a as CDPClientOptions, c as createCDPClient } from './client-7Nqka5MV.js';
6
- export { Browser, BrowserOptions, connect } from './browser.js';
6
+ export { Browser, BrowserOptions, PageOptions, connect } from './browser.js';
7
7
  export { CDPError } from './cdp.js';
8
8
  export { BrowserBaseProvider, BrowserlessProvider, GenericProvider, createProvider, discoverTargets, getBrowserWebSocketUrl } from './providers.js';
9
9
  export { b as ConnectOptions, C as CreateSessionOptions, P as Provider, a as ProviderSession } from './types--wXNHUwt.js';
package/dist/index.mjs CHANGED
@@ -16,11 +16,10 @@ import {
16
16
  waitForElement,
17
17
  waitForNavigation,
18
18
  waitForNetworkIdle
19
- } from "./chunk-7OSR2CAE.mjs";
19
+ } from "./chunk-RUWAXHDX.mjs";
20
20
  import {
21
- CDPError,
22
21
  createCDPClient
23
- } from "./chunk-BCOZUKWS.mjs";
22
+ } from "./chunk-4MBSALQL.mjs";
24
23
  import {
25
24
  BrowserBaseProvider,
26
25
  BrowserlessProvider,
@@ -28,7 +27,7 @@ import {
28
27
  createProvider,
29
28
  discoverTargets,
30
29
  getBrowserWebSocketUrl
31
- } from "./chunk-R3PS4PCM.mjs";
30
+ } from "./chunk-BRAFQUMG.mjs";
32
31
  import {
33
32
  BatchExecutor,
34
33
  ElementNotFoundError,
@@ -36,7 +35,10 @@ import {
36
35
  TimeoutError,
37
36
  addBatchToPage,
38
37
  validateSteps
39
- } from "./chunk-KKW2SZLV.mjs";
38
+ } from "./chunk-NLIARNEE.mjs";
39
+ import {
40
+ CDPError
41
+ } from "./chunk-JXAUPHZM.mjs";
40
42
 
41
43
  // src/audio/flags.ts
42
44
  function getAudioChromeFlags(options) {
@@ -160,6 +160,34 @@ var BrowserlessProvider = class {
160
160
  };
161
161
 
162
162
  // src/providers/generic.ts
163
+ function sleep(ms) {
164
+ return new Promise((resolve) => setTimeout(resolve, ms));
165
+ }
166
+ async function fetchDevToolsJson(host, path, errorPrefix, options = {}) {
167
+ const protocol = host.includes("://") ? "" : "http://";
168
+ const attempts = options.attempts ?? 1;
169
+ let delayMs = options.initialDelayMs ?? 50;
170
+ const maxDelayMs = options.maxDelayMs ?? 250;
171
+ let lastError;
172
+ for (let attempt = 1; attempt <= attempts; attempt++) {
173
+ try {
174
+ const response = await fetch(`${protocol}${host}${path}`);
175
+ if (response.ok) {
176
+ return await response.json();
177
+ }
178
+ lastError = new Error(`${errorPrefix}: ${response.status}`);
179
+ } catch (error) {
180
+ lastError = new Error(
181
+ `${errorPrefix}: ${error instanceof Error ? error.message : String(error)}`
182
+ );
183
+ }
184
+ if (attempt < attempts) {
185
+ await sleep(delayMs);
186
+ delayMs = Math.min(delayMs * 2, maxDelayMs);
187
+ }
188
+ }
189
+ throw lastError ?? new Error(errorPrefix);
190
+ }
163
191
  var GenericProvider = class {
164
192
  name = "generic";
165
193
  wsUrl;
@@ -178,20 +206,14 @@ var GenericProvider = class {
178
206
  }
179
207
  };
180
208
  async function discoverTargets(host = "localhost:9222") {
181
- const protocol = host.includes("://") ? "" : "http://";
182
- const response = await fetch(`${protocol}${host}/json/list`);
183
- if (!response.ok) {
184
- throw new Error(`Failed to discover targets: ${response.status}`);
185
- }
186
- return await response.json();
209
+ return fetchDevToolsJson(host, "/json/list", "Failed to discover targets");
187
210
  }
188
211
  async function getBrowserWebSocketUrl(host = "localhost:9222") {
189
- const protocol = host.includes("://") ? "" : "http://";
190
- const response = await fetch(`${protocol}${host}/json/version`);
191
- if (!response.ok) {
192
- throw new Error(`Failed to get browser info: ${response.status}`);
193
- }
194
- const info = await response.json();
212
+ const info = await fetchDevToolsJson(host, "/json/version", "Failed to get browser info", {
213
+ attempts: 10,
214
+ initialDelayMs: 50,
215
+ maxDelayMs: 250
216
+ });
195
217
  return info.webSocketDebuggerUrl;
196
218
  }
197
219
 
@@ -5,7 +5,7 @@ import {
5
5
  createProvider,
6
6
  discoverTargets,
7
7
  getBrowserWebSocketUrl
8
- } from "./chunk-R3PS4PCM.mjs";
8
+ } from "./chunk-BRAFQUMG.mjs";
9
9
  export {
10
10
  BrowserBaseProvider,
11
11
  BrowserlessProvider,
@@ -224,7 +224,9 @@ interface WaitResult {
224
224
  waitedMs: number;
225
225
  }
226
226
  /**
227
- * Wait for an element to reach a specific state
227
+ * Wait for an element to reach a specific state.
228
+ * Uses fast-fail: if the element is not found on a static page (no DOM mutations),
229
+ * returns early instead of polling for the full timeout.
228
230
  */
229
231
  declare function waitForElement(cdp: CDPClient, selector: string, options?: WaitOptions): Promise<WaitResult>;
230
232
  /**
@@ -270,14 +272,16 @@ interface ActionOptions {
270
272
  optional?: boolean;
271
273
  }
272
274
  interface FillOptions extends ActionOptions {
273
- /** Clear existing content before filling */
274
- clear?: boolean;
275
275
  /** Trigger blur after filling (useful for React/Vue frameworks that update on blur) */
276
276
  blur?: boolean;
277
+ /** Verify value stuck after fill; falls back to char-by-char typing if not (default: true) */
278
+ verify?: boolean;
277
279
  }
278
280
  interface TypeOptions extends ActionOptions {
279
281
  /** Delay between keystrokes in ms */
280
282
  delay?: number;
283
+ /** Blur the element after typing */
284
+ blur?: boolean;
281
285
  }
282
286
  interface SubmitOptions extends ActionOptions {
283
287
  /** How to submit: 'enter' | 'click' | 'enter+click' */
@@ -705,8 +709,12 @@ declare class Page {
705
709
  private frameExecutionContexts;
706
710
  /** Current frame's execution context ID (null = main frame default) */
707
711
  private currentFrameContextId;
712
+ /** Frame selector if context acquisition failed (cross-origin/sandboxed) */
713
+ private brokenFrame;
708
714
  /** Last matched selector from findElement (for selectorUsed tracking) */
709
715
  private _lastMatchedSelector;
716
+ /** Last snapshot for stale ref recovery */
717
+ private lastSnapshot?;
710
718
  /** Audio input controller (lazy-initialized) */
711
719
  private _audioInput?;
712
720
  /** Audio output controller (lazy-initialized) */
@@ -730,6 +738,7 @@ declare class Page {
730
738
  * Initialize the page (enable required CDP domains)
731
739
  */
732
740
  init(): Promise<void>;
741
+ private installEventListenerTracker;
733
742
  /**
734
743
  * Navigate to a URL
735
744
  */
@@ -757,8 +766,9 @@ declare class Page {
757
766
  /**
758
767
  * Click an element (supports multi-selector)
759
768
  *
760
- * Uses CDP mouse events for regular elements. For form submit buttons,
761
- * uses dispatchEvent to reliably trigger form submission in headless Chrome.
769
+ * Uses CDP mouse events (mouseMoved + mousePressed + mouseReleased) to
770
+ * simulate a real click. Real mouse events on submit buttons naturally
771
+ * trigger native form submission — no JS dispatch needed.
762
772
  */
763
773
  click(selector: string | string[], options?: ActionOptions): Promise<boolean>;
764
774
  /**
@@ -767,6 +777,10 @@ declare class Page {
767
777
  fill(selector: string | string[], value: string, options?: FillOptions): Promise<boolean>;
768
778
  /**
769
779
  * Type text character by character (for autocomplete fields, etc.)
780
+ *
781
+ * Uses proper keyDown/rawKeyDown distinction with US keyboard layout.
782
+ * Printable chars use 'keyDown' with text, non-text keys use 'rawKeyDown',
783
+ * and non-layout chars (emoji, CJK) fall back to Input.insertText.
770
784
  */
771
785
  type(selector: string | string[], text: string, options?: TypeOptions): Promise<boolean>;
772
786
  /**
@@ -779,11 +793,13 @@ declare class Page {
779
793
  */
780
794
  private selectCustom;
781
795
  /**
782
- * Check a checkbox or radio button
796
+ * Check a checkbox or radio button using real mouse click.
797
+ * No-op if already checked. Verifies state changed after click.
783
798
  */
784
799
  check(selector: string | string[], options?: ActionOptions): Promise<boolean>;
785
800
  /**
786
- * Uncheck a checkbox
801
+ * Uncheck a checkbox using real mouse click.
802
+ * No-op if already unchecked. Radio buttons can't be unchecked (returns true).
787
803
  */
788
804
  uncheck(selector: string | string[], options?: ActionOptions): Promise<boolean>;
789
805
  /**
@@ -799,9 +815,15 @@ declare class Page {
799
815
  */
800
816
  submit(selector: string | string[], options?: SubmitOptions): Promise<boolean>;
801
817
  /**
802
- * Press a key
818
+ * Press a key, optionally with modifier keys held down
819
+ */
820
+ press(key: string, options?: {
821
+ modifiers?: Array<'Control' | 'Shift' | 'Alt' | 'Meta'>;
822
+ }): Promise<void>;
823
+ /**
824
+ * Execute a keyboard shortcut (e.g. "Control+a", "Meta+Shift+z")
803
825
  */
804
- press(key: string): Promise<void>;
826
+ shortcut(combo: string): Promise<void>;
805
827
  /**
806
828
  * Focus an element
807
829
  */
@@ -864,6 +886,17 @@ declare class Page {
864
886
  * Set files on a file input
865
887
  */
866
888
  setInputFiles(selector: string | string[], files: FileInput[], options?: ActionOptions): Promise<boolean>;
889
+ private getNativeSelectMetadata;
890
+ private readNativeSelectValues;
891
+ private selectValuesMatch;
892
+ private applyNativeSelectByKeyboard;
893
+ private applyNativeSelectFallback;
894
+ private selectEditableContent;
895
+ private clearEditableSelection;
896
+ private readEditableValue;
897
+ private typeEditableFallback;
898
+ private applyRecordedSelectFallback;
899
+ private invokeRecordedEventListeners;
867
900
  /**
868
901
  * Wait for a download to complete, triggered by an action
869
902
  */
@@ -1074,17 +1107,31 @@ declare class Page {
1074
1107
  */
1075
1108
  private evaluateInFrame;
1076
1109
  /**
1077
- * Scroll an element into view
1110
+ * Scroll an element into view, with fallback to center-scroll if clipped by fixed headers
1078
1111
  */
1079
1112
  private scrollIntoView;
1113
+ /**
1114
+ * Check if element is within the visible viewport
1115
+ */
1116
+ private isInViewport;
1080
1117
  /**
1081
1118
  * Get element box model (position and dimensions)
1082
1119
  */
1083
1120
  private getBoxModel;
1084
1121
  /**
1085
- * Click an element by node ID
1122
+ * Click an element by node ID using Playwright's 3-event sequence:
1123
+ * mouseMoved → mousePressed → mouseReleased (sequential).
1124
+ * Uses DOM.getContentQuads for accurate coordinates (handles CSS transforms).
1125
+ * Falls back to JS this.click() if CDP mouse dispatch fails.
1086
1126
  */
1087
1127
  private clickElement;
1128
+ /**
1129
+ * Resolve a nodeId to a Remote Object ID for use with Runtime.callFunctionOn
1130
+ */
1131
+ private resolveObjectId;
1132
+ private dispatchKeyDefinition;
1133
+ private dispatchKey;
1134
+ private dispatchKeyWithModifiers;
1088
1135
  /**
1089
1136
  * Audio input controller (fake microphone).
1090
1137
  * Lazy-initialized on first access.
@@ -1120,13 +1167,22 @@ declare class Page {
1120
1167
  * ```
1121
1168
  */
1122
1169
  audioRoundTrip(options: RoundTripOptions): Promise<RoundTripResult>;
1170
+ /**
1171
+ * Wait for a DOM mutation in the current frame (used for detecting client-side form handling)
1172
+ */
1173
+ private waitForDOMMutation;
1174
+ /**
1175
+ * Wait for a frame execution context via Runtime.executionContextCreated event
1176
+ */
1177
+ private waitForFrameContext;
1123
1178
  }
1124
1179
 
1125
1180
  /**
1126
1181
  * Action/Step types for batch execution
1127
1182
  */
1128
1183
 
1129
- type ActionType = 'goto' | 'click' | 'fill' | 'type' | 'select' | 'check' | 'uncheck' | 'submit' | 'press' | 'focus' | 'hover' | 'scroll' | 'wait' | 'snapshot' | 'screenshot' | 'evaluate' | 'text' | 'switchFrame' | 'switchToMain';
1184
+ type FailureReason = 'missing' | 'hidden' | 'covered' | 'disabled' | 'readonly' | 'detached' | 'replaced' | 'notEditable' | 'timeout' | 'navigation' | 'cdpError' | 'unknown';
1185
+ type ActionType = 'goto' | 'click' | 'fill' | 'type' | 'select' | 'check' | 'uncheck' | 'submit' | 'press' | 'shortcut' | 'focus' | 'hover' | 'scroll' | 'wait' | 'snapshot' | 'screenshot' | 'evaluate' | 'text' | 'switchFrame' | 'switchToMain' | 'assertVisible' | 'assertExists' | 'assertText' | 'assertUrl' | 'assertValue';
1130
1186
  interface Step {
1131
1187
  /** Action type */
1132
1188
  action: ActionType;
@@ -1138,6 +1194,10 @@ interface Step {
1138
1194
  value?: string | string[];
1139
1195
  /** Key for press action */
1140
1196
  key?: string;
1197
+ /** Key combo for shortcut action (e.g. "Control+a", "Meta+Shift+z") */
1198
+ combo?: string;
1199
+ /** Modifier keys for press action */
1200
+ modifiers?: Array<'Control' | 'Shift' | 'Alt' | 'Meta'>;
1141
1201
  /** What to wait for (wait action) */
1142
1202
  waitFor?: 'visible' | 'hidden' | 'attached' | 'detached' | 'navigation' | 'networkIdle';
1143
1203
  /** Step-specific timeout override (ms) */
@@ -1146,14 +1206,12 @@ interface Step {
1146
1206
  optional?: boolean;
1147
1207
  /** Submit method */
1148
1208
  method?: 'enter' | 'click' | 'enter+click';
1149
- /** Clear input before filling */
1150
- clear?: boolean;
1151
1209
  /** Trigger blur after filling (for React/Vue frameworks) */
1152
1210
  blur?: boolean;
1153
1211
  /** Delay between keystrokes for type action */
1154
1212
  delay?: number;
1155
- /** Wait for navigation after click action completes */
1156
- waitForNavigation?: boolean;
1213
+ /** Wait mode after click/submit: true, false, or 'auto' for submit heuristics */
1214
+ waitForNavigation?: boolean | 'auto';
1157
1215
  /** Custom select: trigger selector */
1158
1216
  trigger?: string | string[];
1159
1217
  /** Custom select: option selector */
@@ -1171,6 +1229,12 @@ interface Step {
1171
1229
  format?: 'png' | 'jpeg' | 'webp';
1172
1230
  quality?: number;
1173
1231
  fullPage?: boolean;
1232
+ /** Expected value for assertion steps (substring match for assertText, exact for assertValue/assertUrl) */
1233
+ expect?: string;
1234
+ /** Retry count for assertion or action steps (default: 0 = no retry) */
1235
+ retry?: number;
1236
+ /** Delay between retries in ms (default: 500) */
1237
+ retryDelay?: number;
1174
1238
  }
1175
1239
  interface BatchOptions {
1176
1240
  /** Default timeout for all steps (ms) */
@@ -1204,6 +1268,16 @@ interface StepResult {
1204
1268
  text?: string;
1205
1269
  /** Failure hints when element not found */
1206
1270
  hints?: FailureHint[];
1271
+ /** Structured failure classification */
1272
+ failureReason?: FailureReason;
1273
+ /** Element covering the target (when failureReason is 'covered') */
1274
+ coveringElement?: {
1275
+ tag: string;
1276
+ id?: string;
1277
+ className?: string;
1278
+ };
1279
+ /** AI-friendly suggestion for what to try next */
1280
+ suggestion?: string;
1207
1281
  }
1208
1282
  interface BatchResult {
1209
1283
  /** Whether all steps succeeded */
@@ -1216,4 +1290,4 @@ interface BatchResult {
1216
1290
  totalDurationMs: number;
1217
1291
  }
1218
1292
 
1219
- export { type InterceptedRequest as $, type ActionType as A, type BatchOptions as B, type CaptureResult as C, type Dialog as D, type ElementInfo as E, type FileInput as F, type GeolocationOptions as G, type PageSnapshot as H, type InteractiveElement as I, type SnapshotNode as J, type SubmitOptions as K, type TypeOptions as L, type UserAgentOptions as M, NavigationError as N, type DeviceDescriptor as O, type PlayOptions as P, type DeviceName as Q, type RequestPattern as R, type Step as S, TimeoutError as T, type UserAgentMetadata as U, type ViewportOptions as V, type WaitForOptions as W, devices as X, type ContinueRequestOptions as Y, type FailRequestOptions as Z, type FulfillRequestOptions as _, type RequestHandler as a, type RequestActions as a0, type ResourceType as a1, type RouteOptions as a2, type ClearCookiesOptions as a3, type Cookie as a4, type DeleteCookieOptions as a5, type SetCookieOptions as a6, type WaitOptions as a7, type WaitResult as a8, type WaitState as a9, waitForAnyElement as aa, waitForElement as ab, waitForNavigation as ac, waitForNetworkIdle as ad, type FailureHint as ae, type BatchResult as b, type StepResult as c, type AudioChunk as d, AudioInput as e, type AudioInputState as f, AudioOutput as g, type CaptureOptions as h, type RoundTripOptions as i, type RoundTripResult as j, type ActionOptions as k, type ActionResult as l, type ConsoleHandler as m, type ConsoleMessage as n, type ConsoleMessageType as o, type CustomSelectConfig as p, type DialogHandler as q, type DialogType as r, type Download as s, ElementNotFoundError as t, type EmulationState as u, type ErrorHandler as v, type FillOptions as w, type NetworkIdleOptions as x, Page as y, type PageError as z };
1293
+ export { type InterceptedRequest as $, type ActionType as A, type BatchOptions as B, type CaptureResult as C, type Dialog as D, type ElementInfo as E, type FileInput as F, type GeolocationOptions as G, type PageSnapshot as H, type InteractiveElement as I, type SnapshotNode as J, type SubmitOptions as K, type TypeOptions as L, type UserAgentOptions as M, NavigationError as N, type DeviceDescriptor as O, type PlayOptions as P, type DeviceName as Q, type RequestPattern as R, type Step as S, TimeoutError as T, type UserAgentMetadata as U, type ViewportOptions as V, type WaitForOptions as W, devices as X, type ContinueRequestOptions as Y, type FailRequestOptions as Z, type FulfillRequestOptions as _, type RequestHandler as a, type RequestActions as a0, type ResourceType as a1, type RouteOptions as a2, type ClearCookiesOptions as a3, type Cookie as a4, type DeleteCookieOptions as a5, type SetCookieOptions as a6, type WaitOptions as a7, type WaitResult as a8, type WaitState as a9, waitForAnyElement as aa, waitForElement as ab, waitForNavigation as ac, waitForNetworkIdle as ad, type FailureHint as ae, type FailureReason as af, type BatchResult as b, type StepResult as c, type AudioChunk as d, AudioInput as e, type AudioInputState as f, AudioOutput as g, type CaptureOptions as h, type RoundTripOptions as i, type RoundTripResult as j, type ActionOptions as k, type ActionResult as l, type ConsoleHandler as m, type ConsoleMessage as n, type ConsoleMessageType as o, type CustomSelectConfig as p, type DialogHandler as q, type DialogType as r, type Download as s, ElementNotFoundError as t, type EmulationState as u, type ErrorHandler as v, type FillOptions as w, type NetworkIdleOptions as x, Page as y, type PageError as z };
@@ -224,7 +224,9 @@ interface WaitResult {
224
224
  waitedMs: number;
225
225
  }
226
226
  /**
227
- * Wait for an element to reach a specific state
227
+ * Wait for an element to reach a specific state.
228
+ * Uses fast-fail: if the element is not found on a static page (no DOM mutations),
229
+ * returns early instead of polling for the full timeout.
228
230
  */
229
231
  declare function waitForElement(cdp: CDPClient, selector: string, options?: WaitOptions): Promise<WaitResult>;
230
232
  /**
@@ -270,14 +272,16 @@ interface ActionOptions {
270
272
  optional?: boolean;
271
273
  }
272
274
  interface FillOptions extends ActionOptions {
273
- /** Clear existing content before filling */
274
- clear?: boolean;
275
275
  /** Trigger blur after filling (useful for React/Vue frameworks that update on blur) */
276
276
  blur?: boolean;
277
+ /** Verify value stuck after fill; falls back to char-by-char typing if not (default: true) */
278
+ verify?: boolean;
277
279
  }
278
280
  interface TypeOptions extends ActionOptions {
279
281
  /** Delay between keystrokes in ms */
280
282
  delay?: number;
283
+ /** Blur the element after typing */
284
+ blur?: boolean;
281
285
  }
282
286
  interface SubmitOptions extends ActionOptions {
283
287
  /** How to submit: 'enter' | 'click' | 'enter+click' */
@@ -705,8 +709,12 @@ declare class Page {
705
709
  private frameExecutionContexts;
706
710
  /** Current frame's execution context ID (null = main frame default) */
707
711
  private currentFrameContextId;
712
+ /** Frame selector if context acquisition failed (cross-origin/sandboxed) */
713
+ private brokenFrame;
708
714
  /** Last matched selector from findElement (for selectorUsed tracking) */
709
715
  private _lastMatchedSelector;
716
+ /** Last snapshot for stale ref recovery */
717
+ private lastSnapshot?;
710
718
  /** Audio input controller (lazy-initialized) */
711
719
  private _audioInput?;
712
720
  /** Audio output controller (lazy-initialized) */
@@ -730,6 +738,7 @@ declare class Page {
730
738
  * Initialize the page (enable required CDP domains)
731
739
  */
732
740
  init(): Promise<void>;
741
+ private installEventListenerTracker;
733
742
  /**
734
743
  * Navigate to a URL
735
744
  */
@@ -757,8 +766,9 @@ declare class Page {
757
766
  /**
758
767
  * Click an element (supports multi-selector)
759
768
  *
760
- * Uses CDP mouse events for regular elements. For form submit buttons,
761
- * uses dispatchEvent to reliably trigger form submission in headless Chrome.
769
+ * Uses CDP mouse events (mouseMoved + mousePressed + mouseReleased) to
770
+ * simulate a real click. Real mouse events on submit buttons naturally
771
+ * trigger native form submission — no JS dispatch needed.
762
772
  */
763
773
  click(selector: string | string[], options?: ActionOptions): Promise<boolean>;
764
774
  /**
@@ -767,6 +777,10 @@ declare class Page {
767
777
  fill(selector: string | string[], value: string, options?: FillOptions): Promise<boolean>;
768
778
  /**
769
779
  * Type text character by character (for autocomplete fields, etc.)
780
+ *
781
+ * Uses proper keyDown/rawKeyDown distinction with US keyboard layout.
782
+ * Printable chars use 'keyDown' with text, non-text keys use 'rawKeyDown',
783
+ * and non-layout chars (emoji, CJK) fall back to Input.insertText.
770
784
  */
771
785
  type(selector: string | string[], text: string, options?: TypeOptions): Promise<boolean>;
772
786
  /**
@@ -779,11 +793,13 @@ declare class Page {
779
793
  */
780
794
  private selectCustom;
781
795
  /**
782
- * Check a checkbox or radio button
796
+ * Check a checkbox or radio button using real mouse click.
797
+ * No-op if already checked. Verifies state changed after click.
783
798
  */
784
799
  check(selector: string | string[], options?: ActionOptions): Promise<boolean>;
785
800
  /**
786
- * Uncheck a checkbox
801
+ * Uncheck a checkbox using real mouse click.
802
+ * No-op if already unchecked. Radio buttons can't be unchecked (returns true).
787
803
  */
788
804
  uncheck(selector: string | string[], options?: ActionOptions): Promise<boolean>;
789
805
  /**
@@ -799,9 +815,15 @@ declare class Page {
799
815
  */
800
816
  submit(selector: string | string[], options?: SubmitOptions): Promise<boolean>;
801
817
  /**
802
- * Press a key
818
+ * Press a key, optionally with modifier keys held down
819
+ */
820
+ press(key: string, options?: {
821
+ modifiers?: Array<'Control' | 'Shift' | 'Alt' | 'Meta'>;
822
+ }): Promise<void>;
823
+ /**
824
+ * Execute a keyboard shortcut (e.g. "Control+a", "Meta+Shift+z")
803
825
  */
804
- press(key: string): Promise<void>;
826
+ shortcut(combo: string): Promise<void>;
805
827
  /**
806
828
  * Focus an element
807
829
  */
@@ -864,6 +886,17 @@ declare class Page {
864
886
  * Set files on a file input
865
887
  */
866
888
  setInputFiles(selector: string | string[], files: FileInput[], options?: ActionOptions): Promise<boolean>;
889
+ private getNativeSelectMetadata;
890
+ private readNativeSelectValues;
891
+ private selectValuesMatch;
892
+ private applyNativeSelectByKeyboard;
893
+ private applyNativeSelectFallback;
894
+ private selectEditableContent;
895
+ private clearEditableSelection;
896
+ private readEditableValue;
897
+ private typeEditableFallback;
898
+ private applyRecordedSelectFallback;
899
+ private invokeRecordedEventListeners;
867
900
  /**
868
901
  * Wait for a download to complete, triggered by an action
869
902
  */
@@ -1074,17 +1107,31 @@ declare class Page {
1074
1107
  */
1075
1108
  private evaluateInFrame;
1076
1109
  /**
1077
- * Scroll an element into view
1110
+ * Scroll an element into view, with fallback to center-scroll if clipped by fixed headers
1078
1111
  */
1079
1112
  private scrollIntoView;
1113
+ /**
1114
+ * Check if element is within the visible viewport
1115
+ */
1116
+ private isInViewport;
1080
1117
  /**
1081
1118
  * Get element box model (position and dimensions)
1082
1119
  */
1083
1120
  private getBoxModel;
1084
1121
  /**
1085
- * Click an element by node ID
1122
+ * Click an element by node ID using Playwright's 3-event sequence:
1123
+ * mouseMoved → mousePressed → mouseReleased (sequential).
1124
+ * Uses DOM.getContentQuads for accurate coordinates (handles CSS transforms).
1125
+ * Falls back to JS this.click() if CDP mouse dispatch fails.
1086
1126
  */
1087
1127
  private clickElement;
1128
+ /**
1129
+ * Resolve a nodeId to a Remote Object ID for use with Runtime.callFunctionOn
1130
+ */
1131
+ private resolveObjectId;
1132
+ private dispatchKeyDefinition;
1133
+ private dispatchKey;
1134
+ private dispatchKeyWithModifiers;
1088
1135
  /**
1089
1136
  * Audio input controller (fake microphone).
1090
1137
  * Lazy-initialized on first access.
@@ -1120,13 +1167,22 @@ declare class Page {
1120
1167
  * ```
1121
1168
  */
1122
1169
  audioRoundTrip(options: RoundTripOptions): Promise<RoundTripResult>;
1170
+ /**
1171
+ * Wait for a DOM mutation in the current frame (used for detecting client-side form handling)
1172
+ */
1173
+ private waitForDOMMutation;
1174
+ /**
1175
+ * Wait for a frame execution context via Runtime.executionContextCreated event
1176
+ */
1177
+ private waitForFrameContext;
1123
1178
  }
1124
1179
 
1125
1180
  /**
1126
1181
  * Action/Step types for batch execution
1127
1182
  */
1128
1183
 
1129
- type ActionType = 'goto' | 'click' | 'fill' | 'type' | 'select' | 'check' | 'uncheck' | 'submit' | 'press' | 'focus' | 'hover' | 'scroll' | 'wait' | 'snapshot' | 'screenshot' | 'evaluate' | 'text' | 'switchFrame' | 'switchToMain';
1184
+ type FailureReason = 'missing' | 'hidden' | 'covered' | 'disabled' | 'readonly' | 'detached' | 'replaced' | 'notEditable' | 'timeout' | 'navigation' | 'cdpError' | 'unknown';
1185
+ type ActionType = 'goto' | 'click' | 'fill' | 'type' | 'select' | 'check' | 'uncheck' | 'submit' | 'press' | 'shortcut' | 'focus' | 'hover' | 'scroll' | 'wait' | 'snapshot' | 'screenshot' | 'evaluate' | 'text' | 'switchFrame' | 'switchToMain' | 'assertVisible' | 'assertExists' | 'assertText' | 'assertUrl' | 'assertValue';
1130
1186
  interface Step {
1131
1187
  /** Action type */
1132
1188
  action: ActionType;
@@ -1138,6 +1194,10 @@ interface Step {
1138
1194
  value?: string | string[];
1139
1195
  /** Key for press action */
1140
1196
  key?: string;
1197
+ /** Key combo for shortcut action (e.g. "Control+a", "Meta+Shift+z") */
1198
+ combo?: string;
1199
+ /** Modifier keys for press action */
1200
+ modifiers?: Array<'Control' | 'Shift' | 'Alt' | 'Meta'>;
1141
1201
  /** What to wait for (wait action) */
1142
1202
  waitFor?: 'visible' | 'hidden' | 'attached' | 'detached' | 'navigation' | 'networkIdle';
1143
1203
  /** Step-specific timeout override (ms) */
@@ -1146,14 +1206,12 @@ interface Step {
1146
1206
  optional?: boolean;
1147
1207
  /** Submit method */
1148
1208
  method?: 'enter' | 'click' | 'enter+click';
1149
- /** Clear input before filling */
1150
- clear?: boolean;
1151
1209
  /** Trigger blur after filling (for React/Vue frameworks) */
1152
1210
  blur?: boolean;
1153
1211
  /** Delay between keystrokes for type action */
1154
1212
  delay?: number;
1155
- /** Wait for navigation after click action completes */
1156
- waitForNavigation?: boolean;
1213
+ /** Wait mode after click/submit: true, false, or 'auto' for submit heuristics */
1214
+ waitForNavigation?: boolean | 'auto';
1157
1215
  /** Custom select: trigger selector */
1158
1216
  trigger?: string | string[];
1159
1217
  /** Custom select: option selector */
@@ -1171,6 +1229,12 @@ interface Step {
1171
1229
  format?: 'png' | 'jpeg' | 'webp';
1172
1230
  quality?: number;
1173
1231
  fullPage?: boolean;
1232
+ /** Expected value for assertion steps (substring match for assertText, exact for assertValue/assertUrl) */
1233
+ expect?: string;
1234
+ /** Retry count for assertion or action steps (default: 0 = no retry) */
1235
+ retry?: number;
1236
+ /** Delay between retries in ms (default: 500) */
1237
+ retryDelay?: number;
1174
1238
  }
1175
1239
  interface BatchOptions {
1176
1240
  /** Default timeout for all steps (ms) */
@@ -1204,6 +1268,16 @@ interface StepResult {
1204
1268
  text?: string;
1205
1269
  /** Failure hints when element not found */
1206
1270
  hints?: FailureHint[];
1271
+ /** Structured failure classification */
1272
+ failureReason?: FailureReason;
1273
+ /** Element covering the target (when failureReason is 'covered') */
1274
+ coveringElement?: {
1275
+ tag: string;
1276
+ id?: string;
1277
+ className?: string;
1278
+ };
1279
+ /** AI-friendly suggestion for what to try next */
1280
+ suggestion?: string;
1207
1281
  }
1208
1282
  interface BatchResult {
1209
1283
  /** Whether all steps succeeded */
@@ -1216,4 +1290,4 @@ interface BatchResult {
1216
1290
  totalDurationMs: number;
1217
1291
  }
1218
1292
 
1219
- export { type InterceptedRequest as $, type ActionType as A, type BatchOptions as B, type CaptureResult as C, type Dialog as D, type ElementInfo as E, type FileInput as F, type GeolocationOptions as G, type PageSnapshot as H, type InteractiveElement as I, type SnapshotNode as J, type SubmitOptions as K, type TypeOptions as L, type UserAgentOptions as M, NavigationError as N, type DeviceDescriptor as O, type PlayOptions as P, type DeviceName as Q, type RequestPattern as R, type Step as S, TimeoutError as T, type UserAgentMetadata as U, type ViewportOptions as V, type WaitForOptions as W, devices as X, type ContinueRequestOptions as Y, type FailRequestOptions as Z, type FulfillRequestOptions as _, type RequestHandler as a, type RequestActions as a0, type ResourceType as a1, type RouteOptions as a2, type ClearCookiesOptions as a3, type Cookie as a4, type DeleteCookieOptions as a5, type SetCookieOptions as a6, type WaitOptions as a7, type WaitResult as a8, type WaitState as a9, waitForAnyElement as aa, waitForElement as ab, waitForNavigation as ac, waitForNetworkIdle as ad, type FailureHint as ae, type BatchResult as b, type StepResult as c, type AudioChunk as d, AudioInput as e, type AudioInputState as f, AudioOutput as g, type CaptureOptions as h, type RoundTripOptions as i, type RoundTripResult as j, type ActionOptions as k, type ActionResult as l, type ConsoleHandler as m, type ConsoleMessage as n, type ConsoleMessageType as o, type CustomSelectConfig as p, type DialogHandler as q, type DialogType as r, type Download as s, ElementNotFoundError as t, type EmulationState as u, type ErrorHandler as v, type FillOptions as w, type NetworkIdleOptions as x, Page as y, type PageError as z };
1293
+ export { type InterceptedRequest as $, type ActionType as A, type BatchOptions as B, type CaptureResult as C, type Dialog as D, type ElementInfo as E, type FileInput as F, type GeolocationOptions as G, type PageSnapshot as H, type InteractiveElement as I, type SnapshotNode as J, type SubmitOptions as K, type TypeOptions as L, type UserAgentOptions as M, NavigationError as N, type DeviceDescriptor as O, type PlayOptions as P, type DeviceName as Q, type RequestPattern as R, type Step as S, TimeoutError as T, type UserAgentMetadata as U, type ViewportOptions as V, type WaitForOptions as W, devices as X, type ContinueRequestOptions as Y, type FailRequestOptions as Z, type FulfillRequestOptions as _, type RequestHandler as a, type RequestActions as a0, type ResourceType as a1, type RouteOptions as a2, type ClearCookiesOptions as a3, type Cookie as a4, type DeleteCookieOptions as a5, type SetCookieOptions as a6, type WaitOptions as a7, type WaitResult as a8, type WaitState as a9, waitForAnyElement as aa, waitForElement as ab, waitForNavigation as ac, waitForNetworkIdle as ad, type FailureHint as ae, type FailureReason as af, type BatchResult as b, type StepResult as c, type AudioChunk as d, AudioInput as e, type AudioInputState as f, AudioOutput as g, type CaptureOptions as h, type RoundTripOptions as i, type RoundTripResult as j, type ActionOptions as k, type ActionResult as l, type ConsoleHandler as m, type ConsoleMessage as n, type ConsoleMessageType as o, type CustomSelectConfig as p, type DialogHandler as q, type DialogType as r, type Download as s, ElementNotFoundError as t, type EmulationState as u, type ErrorHandler as v, type FillOptions as w, type NetworkIdleOptions as x, Page as y, type PageError as z };