browser-pilot 0.0.1

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.
@@ -0,0 +1,925 @@
1
+ import { C as CDPClient } from './client-7Nqka5MV.js';
2
+
3
+ /**
4
+ * Wait strategy implementations
5
+ */
6
+
7
+ type WaitState = 'visible' | 'hidden' | 'attached' | 'detached';
8
+ interface WaitOptions {
9
+ /** State to wait for */
10
+ state?: WaitState;
11
+ /** Timeout in milliseconds */
12
+ timeout?: number;
13
+ /** Polling interval in milliseconds */
14
+ pollInterval?: number;
15
+ /** Execution context ID for iframe evaluation */
16
+ contextId?: number;
17
+ }
18
+ interface WaitResult {
19
+ success: boolean;
20
+ waitedMs: number;
21
+ }
22
+ /**
23
+ * Wait for an element to reach a specific state
24
+ */
25
+ declare function waitForElement(cdp: CDPClient, selector: string, options?: WaitOptions): Promise<WaitResult>;
26
+ /**
27
+ * Wait for any of the given selectors to match
28
+ * Returns the selector that matched first
29
+ */
30
+ declare function waitForAnyElement(cdp: CDPClient, selectors: string[], options?: WaitOptions): Promise<{
31
+ success: boolean;
32
+ selector?: string;
33
+ waitedMs: number;
34
+ }>;
35
+ interface NavigationOptions {
36
+ /** Timeout in milliseconds */
37
+ timeout?: number;
38
+ /** Include same-document navigation (pushState, anchors) */
39
+ allowSameDocument?: boolean;
40
+ }
41
+ /**
42
+ * Wait for navigation to complete using multi-signal detection
43
+ * Listens for:
44
+ * - Page.loadEventFired: Full page load
45
+ * - Page.frameNavigated: Frame navigation (includes history.back/forward)
46
+ * - Page.navigatedWithinDocument: Same-document navigation (pushState, anchors)
47
+ * Also polls for URL changes as a fallback
48
+ */
49
+ declare function waitForNavigation(cdp: CDPClient, options?: NavigationOptions): Promise<WaitResult>;
50
+ /**
51
+ * Wait for network to be idle (no requests in flight for a given duration)
52
+ */
53
+ declare function waitForNetworkIdle(cdp: CDPClient, options?: {
54
+ timeout?: number;
55
+ idleTime?: number;
56
+ }): Promise<WaitResult>;
57
+
58
+ /**
59
+ * Browser and Page type definitions
60
+ */
61
+
62
+ interface ActionOptions {
63
+ /** Timeout in milliseconds */
64
+ timeout?: number;
65
+ /** Don't throw on failure, return false instead */
66
+ optional?: boolean;
67
+ }
68
+ interface FillOptions extends ActionOptions {
69
+ /** Clear existing content before filling */
70
+ clear?: boolean;
71
+ }
72
+ interface TypeOptions extends ActionOptions {
73
+ /** Delay between keystrokes in ms */
74
+ delay?: number;
75
+ }
76
+ interface SubmitOptions extends ActionOptions {
77
+ /** How to submit: 'enter' | 'click' | 'enter+click' */
78
+ method?: 'enter' | 'click' | 'enter+click';
79
+ /**
80
+ * Wait for navigation after submit:
81
+ * - 'auto' (default): Race navigation detection vs short delay for client-side forms
82
+ * - true: Always wait for full navigation
83
+ * - false: Return immediately without waiting
84
+ */
85
+ waitForNavigation?: boolean | 'auto';
86
+ }
87
+ interface WaitForOptions extends ActionOptions {
88
+ /** State to wait for */
89
+ state?: WaitState;
90
+ /** Polling interval in ms */
91
+ pollInterval?: number;
92
+ }
93
+ interface NetworkIdleOptions extends ActionOptions {
94
+ /** Time with no requests before considered idle */
95
+ idleTime?: number;
96
+ }
97
+ interface CustomSelectConfig {
98
+ /** Selector for the dropdown trigger */
99
+ trigger: string | string[];
100
+ /** Selector pattern for options */
101
+ option: string | string[];
102
+ /** Value to select */
103
+ value: string;
104
+ /** How to match the value */
105
+ match?: 'text' | 'value' | 'contains';
106
+ }
107
+ interface FileInput {
108
+ /** File name */
109
+ name: string;
110
+ /** MIME type */
111
+ mimeType: string;
112
+ /** File content as base64 or ArrayBuffer */
113
+ buffer: ArrayBuffer | string;
114
+ }
115
+ interface Download {
116
+ /** Downloaded file name */
117
+ filename: string;
118
+ /** Path to downloaded file (if available) */
119
+ path?: string;
120
+ /** Get file content as ArrayBuffer */
121
+ content(): Promise<ArrayBuffer>;
122
+ }
123
+ interface ElementInfo {
124
+ /** Node ID in the DOM */
125
+ nodeId: number;
126
+ /** Backend node ID */
127
+ backendNodeId: number;
128
+ /** Selector that matched */
129
+ selector: string;
130
+ /** Time spent waiting for element */
131
+ waitedMs: number;
132
+ }
133
+ interface ActionResult {
134
+ /** Whether the action succeeded */
135
+ success: boolean;
136
+ /** Time taken in ms */
137
+ durationMs: number;
138
+ /** Selector used (if multiple provided) */
139
+ selectorUsed?: string;
140
+ /** Selectors that failed (if multiple provided) */
141
+ failedSelectors?: Array<{
142
+ selector: string;
143
+ reason: string;
144
+ }>;
145
+ }
146
+ interface PageSnapshot {
147
+ /** Current URL */
148
+ url: string;
149
+ /** Page title */
150
+ title: string;
151
+ /** Snapshot timestamp */
152
+ timestamp: string;
153
+ /** Accessibility tree nodes */
154
+ accessibilityTree: SnapshotNode[];
155
+ /** Interactive elements for quick reference */
156
+ interactiveElements: InteractiveElement[];
157
+ /** Text representation of the page */
158
+ text: string;
159
+ }
160
+ interface SnapshotNode {
161
+ /** Accessibility role */
162
+ role: string;
163
+ /** Accessible name */
164
+ name?: string;
165
+ /** Current value */
166
+ value?: string;
167
+ /** Element reference (e.g., "e1", "e2") */
168
+ ref: string;
169
+ /** Child nodes */
170
+ children?: SnapshotNode[];
171
+ /** Whether the element is disabled */
172
+ disabled?: boolean;
173
+ /** Whether the element is checked (for checkboxes) */
174
+ checked?: boolean;
175
+ /** Additional properties */
176
+ properties?: Record<string, unknown>;
177
+ }
178
+ interface InteractiveElement {
179
+ /** Element reference */
180
+ ref: string;
181
+ /** Accessibility role */
182
+ role: string;
183
+ /** Accessible name */
184
+ name: string;
185
+ /** CSS selector to target this element */
186
+ selector: string;
187
+ /** Whether the element is disabled */
188
+ disabled?: boolean;
189
+ }
190
+ declare class ElementNotFoundError extends Error {
191
+ selectors: string[];
192
+ constructor(selectors: string | string[]);
193
+ }
194
+ declare class TimeoutError extends Error {
195
+ constructor(message?: string);
196
+ }
197
+ declare class NavigationError extends Error {
198
+ constructor(message: string);
199
+ }
200
+ interface ViewportOptions {
201
+ /** Viewport width in pixels */
202
+ width: number;
203
+ /** Viewport height in pixels */
204
+ height: number;
205
+ /** Device scale factor (default: 1) */
206
+ deviceScaleFactor?: number;
207
+ /** Whether to emulate mobile (default: false) */
208
+ isMobile?: boolean;
209
+ /** Whether the meta viewport tag should be accounted for (default: false) */
210
+ hasTouch?: boolean;
211
+ /** Whether to emulate landscape orientation (default: false) */
212
+ isLandscape?: boolean;
213
+ }
214
+ interface GeolocationOptions {
215
+ /** Latitude in degrees */
216
+ latitude: number;
217
+ /** Longitude in degrees */
218
+ longitude: number;
219
+ /** Accuracy in meters (default: 1) */
220
+ accuracy?: number;
221
+ }
222
+ interface UserAgentOptions {
223
+ /** User agent string */
224
+ userAgent: string;
225
+ /** Accept-Language header value */
226
+ acceptLanguage?: string;
227
+ /** Platform override (e.g., "Win32", "MacIntel") */
228
+ platform?: string;
229
+ /** User agent metadata for Client Hints */
230
+ userAgentMetadata?: UserAgentMetadata;
231
+ }
232
+ interface UserAgentMetadata {
233
+ brands?: Array<{
234
+ brand: string;
235
+ version: string;
236
+ }>;
237
+ fullVersionList?: Array<{
238
+ brand: string;
239
+ version: string;
240
+ }>;
241
+ fullVersion?: string;
242
+ platform?: string;
243
+ platformVersion?: string;
244
+ architecture?: string;
245
+ model?: string;
246
+ mobile?: boolean;
247
+ bitness?: string;
248
+ wow64?: boolean;
249
+ }
250
+ interface EmulationState {
251
+ viewport?: ViewportOptions;
252
+ userAgent?: UserAgentOptions;
253
+ geolocation?: GeolocationOptions;
254
+ timezone?: string;
255
+ locale?: string;
256
+ }
257
+ type ConsoleMessageType = 'log' | 'debug' | 'info' | 'error' | 'warning' | 'dir' | 'dirxml' | 'table' | 'trace' | 'clear' | 'startGroup' | 'startGroupCollapsed' | 'endGroup' | 'assert' | 'profile' | 'profileEnd' | 'count' | 'timeEnd';
258
+ interface ConsoleMessage {
259
+ /** Message type */
260
+ type: ConsoleMessageType;
261
+ /** Message text */
262
+ text: string;
263
+ /** Arguments passed to console method */
264
+ args: unknown[];
265
+ /** Source URL */
266
+ url?: string;
267
+ /** Line number */
268
+ lineNumber?: number;
269
+ /** Column number */
270
+ columnNumber?: number;
271
+ /** Stack trace if available */
272
+ stackTrace?: string[];
273
+ /** Timestamp */
274
+ timestamp: number;
275
+ }
276
+ interface PageError {
277
+ /** Error message */
278
+ message: string;
279
+ /** Source URL */
280
+ url?: string;
281
+ /** Line number */
282
+ lineNumber?: number;
283
+ /** Column number */
284
+ columnNumber?: number;
285
+ /** Stack trace */
286
+ stackTrace?: string[];
287
+ /** Timestamp */
288
+ timestamp: number;
289
+ }
290
+ type DialogType = 'alert' | 'confirm' | 'prompt' | 'beforeunload';
291
+ interface Dialog {
292
+ /** Dialog type */
293
+ type: DialogType;
294
+ /** Dialog message */
295
+ message: string;
296
+ /** Default value for prompt dialogs */
297
+ defaultValue?: string;
298
+ /** Accept the dialog (click OK) */
299
+ accept(promptText?: string): Promise<void>;
300
+ /** Dismiss the dialog (click Cancel) */
301
+ dismiss(): Promise<void>;
302
+ }
303
+ type ConsoleHandler = (message: ConsoleMessage) => void;
304
+ type ErrorHandler = (error: PageError) => void;
305
+ type DialogHandler = (dialog: Dialog) => void | Promise<void>;
306
+
307
+ /**
308
+ * Device presets for common emulation scenarios
309
+ */
310
+
311
+ interface DeviceDescriptor {
312
+ name: string;
313
+ viewport: ViewportOptions;
314
+ userAgent: UserAgentOptions;
315
+ }
316
+ declare const devices: Record<string, DeviceDescriptor>;
317
+ type DeviceName = keyof typeof devices;
318
+
319
+ /**
320
+ * Network interception types
321
+ */
322
+ type ResourceType = 'Document' | 'Stylesheet' | 'Image' | 'Media' | 'Font' | 'Script' | 'TextTrack' | 'XHR' | 'Fetch' | 'Prefetch' | 'EventSource' | 'WebSocket' | 'Manifest' | 'SignedExchange' | 'Ping' | 'CSPViolationReport' | 'Preflight' | 'Other';
323
+ interface RequestPattern {
324
+ /** URL pattern (glob or regex string) */
325
+ urlPattern?: string;
326
+ /** Resource type to match */
327
+ resourceType?: ResourceType;
328
+ /** Request stage to intercept */
329
+ requestStage?: 'Request' | 'Response';
330
+ }
331
+ interface InterceptedRequest {
332
+ /** Unique request ID */
333
+ requestId: string;
334
+ /** Request URL */
335
+ url: string;
336
+ /** HTTP method */
337
+ method: string;
338
+ /** Request headers */
339
+ headers: Record<string, string>;
340
+ /** POST data if present */
341
+ postData?: string;
342
+ /** Resource type */
343
+ resourceType: ResourceType;
344
+ /** Frame ID that initiated the request */
345
+ frameId: string;
346
+ /** Whether this is a navigation request */
347
+ isNavigationRequest: boolean;
348
+ /** Response status (only if intercepting response) */
349
+ responseStatusCode?: number;
350
+ /** Response headers (only if intercepting response) */
351
+ responseHeaders?: Record<string, string>;
352
+ }
353
+ interface ContinueRequestOptions {
354
+ /** Override URL */
355
+ url?: string;
356
+ /** Override method */
357
+ method?: string;
358
+ /** Override headers */
359
+ headers?: Record<string, string>;
360
+ /** Override POST data */
361
+ postData?: string;
362
+ }
363
+ interface FulfillRequestOptions {
364
+ /** Response status code */
365
+ status: number;
366
+ /** Response headers */
367
+ headers?: Record<string, string>;
368
+ /** Response body (string or base64 for binary) */
369
+ body?: string;
370
+ /** Whether body is base64 encoded */
371
+ isBase64Encoded?: boolean;
372
+ }
373
+ interface FailRequestOptions {
374
+ /** Error reason */
375
+ reason: 'Failed' | 'Aborted' | 'TimedOut' | 'AccessDenied' | 'ConnectionClosed' | 'ConnectionReset' | 'ConnectionRefused' | 'ConnectionAborted' | 'ConnectionFailed' | 'NameNotResolved' | 'InternetDisconnected' | 'AddressUnreachable' | 'BlockedByClient' | 'BlockedByResponse';
376
+ }
377
+ type RequestHandler = (request: InterceptedRequest, actions: RequestActions) => void | Promise<void>;
378
+ interface RequestActions {
379
+ /** Continue request, optionally modifying it */
380
+ continue(options?: ContinueRequestOptions): Promise<void>;
381
+ /** Fulfill request with custom response */
382
+ fulfill(options: FulfillRequestOptions): Promise<void>;
383
+ /** Fail/abort the request */
384
+ fail(options?: FailRequestOptions): Promise<void>;
385
+ }
386
+ interface RouteOptions {
387
+ /** Response status code */
388
+ status?: number;
389
+ /** Response headers */
390
+ headers?: Record<string, string>;
391
+ /** Response body */
392
+ body?: string | object;
393
+ /** Content type (auto-sets header) */
394
+ contentType?: string;
395
+ }
396
+
397
+ /**
398
+ * Cookie and storage types
399
+ */
400
+ interface Cookie {
401
+ /** Cookie name */
402
+ name: string;
403
+ /** Cookie value */
404
+ value: string;
405
+ /** Cookie domain */
406
+ domain: string;
407
+ /** Cookie path */
408
+ path: string;
409
+ /** Expiration timestamp (Unix epoch in seconds) */
410
+ expires: number;
411
+ /** Size in bytes */
412
+ size: number;
413
+ /** HTTP only flag */
414
+ httpOnly: boolean;
415
+ /** Secure flag */
416
+ secure: boolean;
417
+ /** Session cookie flag */
418
+ session: boolean;
419
+ /** SameSite attribute */
420
+ sameSite: 'Strict' | 'Lax' | 'None';
421
+ /** Priority */
422
+ priority: 'Low' | 'Medium' | 'High';
423
+ /** Source scheme */
424
+ sourceScheme: 'Unset' | 'NonSecure' | 'Secure';
425
+ }
426
+ interface SetCookieOptions {
427
+ /** Cookie name */
428
+ name: string;
429
+ /** Cookie value */
430
+ value: string;
431
+ /** Cookie domain (optional, defaults to current page domain) */
432
+ domain?: string;
433
+ /** Cookie path (default: "/") */
434
+ path?: string;
435
+ /** Expiration timestamp or Date */
436
+ expires?: number | Date;
437
+ /** HTTP only flag */
438
+ httpOnly?: boolean;
439
+ /** Secure flag */
440
+ secure?: boolean;
441
+ /** SameSite attribute */
442
+ sameSite?: 'Strict' | 'Lax' | 'None';
443
+ /** URL to associate cookie with (alternative to domain+path) */
444
+ url?: string;
445
+ }
446
+ interface DeleteCookieOptions {
447
+ /** Cookie name */
448
+ name: string;
449
+ /** Cookie domain */
450
+ domain?: string;
451
+ /** Cookie path */
452
+ path?: string;
453
+ /** URL to scope cookie deletion */
454
+ url?: string;
455
+ }
456
+ interface ClearCookiesOptions {
457
+ /** Clear only for specific domain */
458
+ domain?: string;
459
+ }
460
+
461
+ /**
462
+ * Page class - provides high-level browser automation API
463
+ */
464
+
465
+ declare class Page {
466
+ private cdp;
467
+ private rootNodeId;
468
+ private batchExecutor;
469
+ private emulationState;
470
+ private interceptor;
471
+ private consoleHandlers;
472
+ private errorHandlers;
473
+ private dialogHandler;
474
+ private consoleEnabled;
475
+ /** Map of ref (e.g., "e4") to backendNodeId for ref-based selectors */
476
+ private refMap;
477
+ /** Current frame context (null = main frame) */
478
+ private currentFrame;
479
+ /** Stored frame document node IDs for context switching */
480
+ private frameContexts;
481
+ /** Map of frameId → executionContextId for JS evaluation in frames */
482
+ private frameExecutionContexts;
483
+ /** Current frame's execution context ID (null = main frame default) */
484
+ private currentFrameContextId;
485
+ constructor(cdp: CDPClient);
486
+ /**
487
+ * Initialize the page (enable required CDP domains)
488
+ */
489
+ init(): Promise<void>;
490
+ /**
491
+ * Navigate to a URL
492
+ */
493
+ goto(url: string, options?: ActionOptions): Promise<void>;
494
+ /**
495
+ * Get the current URL
496
+ */
497
+ url(): Promise<string>;
498
+ /**
499
+ * Get the page title
500
+ */
501
+ title(): Promise<string>;
502
+ /**
503
+ * Reload the page
504
+ */
505
+ reload(options?: ActionOptions): Promise<void>;
506
+ /**
507
+ * Go back in history
508
+ */
509
+ goBack(options?: ActionOptions): Promise<void>;
510
+ /**
511
+ * Go forward in history
512
+ */
513
+ goForward(options?: ActionOptions): Promise<void>;
514
+ /**
515
+ * Click an element (supports multi-selector)
516
+ *
517
+ * Uses CDP mouse events for regular elements. For form submit buttons,
518
+ * uses dispatchEvent to reliably trigger form submission in headless Chrome.
519
+ */
520
+ click(selector: string | string[], options?: ActionOptions): Promise<boolean>;
521
+ /**
522
+ * Fill an input field (clears first by default)
523
+ */
524
+ fill(selector: string | string[], value: string, options?: FillOptions): Promise<boolean>;
525
+ /**
526
+ * Type text character by character (for autocomplete fields, etc.)
527
+ */
528
+ type(selector: string | string[], text: string, options?: TypeOptions): Promise<boolean>;
529
+ /**
530
+ * Select option(s) from a native select element
531
+ */
532
+ select(selector: string | string[], value: string | string[], options?: ActionOptions): Promise<boolean>;
533
+ select(config: CustomSelectConfig, options?: ActionOptions): Promise<boolean>;
534
+ /**
535
+ * Handle custom (non-native) select/dropdown components
536
+ */
537
+ private selectCustom;
538
+ /**
539
+ * Check a checkbox or radio button
540
+ */
541
+ check(selector: string | string[], options?: ActionOptions): Promise<boolean>;
542
+ /**
543
+ * Uncheck a checkbox
544
+ */
545
+ uncheck(selector: string | string[], options?: ActionOptions): Promise<boolean>;
546
+ /**
547
+ * Submit a form (tries Enter key first, then click)
548
+ *
549
+ * Navigation waiting behavior:
550
+ * - 'auto' (default): Attempt to detect navigation for 1 second, then assume client-side handling
551
+ * - true: Wait for full navigation (traditional forms)
552
+ * - false: Return immediately (AJAX forms where you'll wait for something else)
553
+ */
554
+ submit(selector: string | string[], options?: SubmitOptions): Promise<boolean>;
555
+ /**
556
+ * Press a key
557
+ */
558
+ press(key: string): Promise<void>;
559
+ /**
560
+ * Focus an element
561
+ */
562
+ focus(selector: string | string[], options?: ActionOptions): Promise<boolean>;
563
+ /**
564
+ * Hover over an element
565
+ */
566
+ hover(selector: string | string[], options?: ActionOptions): Promise<boolean>;
567
+ /**
568
+ * Scroll an element into view (or scroll to coordinates)
569
+ */
570
+ scroll(selector: string | string[], options?: ActionOptions & {
571
+ x?: number;
572
+ y?: number;
573
+ }): Promise<boolean>;
574
+ /**
575
+ * Switch context to an iframe for subsequent actions
576
+ * @param selector - Selector for the iframe element
577
+ * @param options - Optional timeout and optional flags
578
+ * @returns true if switch succeeded
579
+ */
580
+ switchToFrame(selector: string | string[], options?: ActionOptions): Promise<boolean>;
581
+ /**
582
+ * Switch back to the main document from an iframe
583
+ */
584
+ switchToMain(): Promise<void>;
585
+ /**
586
+ * Get the current frame context (null = main frame)
587
+ */
588
+ getCurrentFrame(): string | null;
589
+ /**
590
+ * Wait for an element to reach a state
591
+ */
592
+ waitFor(selector: string | string[], options?: WaitForOptions): Promise<boolean>;
593
+ /**
594
+ * Wait for navigation to complete
595
+ */
596
+ waitForNavigation(options?: ActionOptions): Promise<boolean>;
597
+ /**
598
+ * Wait for network to be idle
599
+ */
600
+ waitForNetworkIdle(options?: NetworkIdleOptions): Promise<boolean>;
601
+ /**
602
+ * Evaluate JavaScript in the page context (or current frame context if in iframe)
603
+ */
604
+ evaluate<T = unknown, Args extends unknown[] = unknown[]>(expression: string | ((...args: Args) => T), ...args: Args): Promise<T>;
605
+ /**
606
+ * Take a screenshot
607
+ */
608
+ screenshot(options?: {
609
+ format?: 'png' | 'jpeg' | 'webp';
610
+ quality?: number;
611
+ fullPage?: boolean;
612
+ }): Promise<string>;
613
+ /**
614
+ * Get text content from the page or a specific element
615
+ */
616
+ text(selector?: string): Promise<string>;
617
+ /**
618
+ * Set files on a file input
619
+ */
620
+ setInputFiles(selector: string | string[], files: FileInput[], options?: ActionOptions): Promise<boolean>;
621
+ /**
622
+ * Wait for a download to complete, triggered by an action
623
+ */
624
+ waitForDownload(trigger: () => Promise<void>, options?: ActionOptions): Promise<Download>;
625
+ /**
626
+ * Get an accessibility tree snapshot of the page
627
+ */
628
+ snapshot(): Promise<PageSnapshot>;
629
+ /**
630
+ * Execute a batch of steps
631
+ */
632
+ batch(steps: Step[], options?: BatchOptions): Promise<BatchResult>;
633
+ /**
634
+ * Set the viewport size and device metrics
635
+ */
636
+ setViewport(options: ViewportOptions): Promise<void>;
637
+ /**
638
+ * Clear viewport override, return to default
639
+ */
640
+ clearViewport(): Promise<void>;
641
+ /**
642
+ * Set the user agent string and optional metadata
643
+ */
644
+ setUserAgent(options: string | UserAgentOptions): Promise<void>;
645
+ /**
646
+ * Set geolocation coordinates
647
+ */
648
+ setGeolocation(options: GeolocationOptions): Promise<void>;
649
+ /**
650
+ * Clear geolocation override
651
+ */
652
+ clearGeolocation(): Promise<void>;
653
+ /**
654
+ * Set timezone override
655
+ */
656
+ setTimezone(timezoneId: string): Promise<void>;
657
+ /**
658
+ * Set locale override
659
+ */
660
+ setLocale(locale: string): Promise<void>;
661
+ /**
662
+ * Emulate a specific device
663
+ */
664
+ emulate(device: DeviceDescriptor): Promise<void>;
665
+ /**
666
+ * Get current emulation state
667
+ */
668
+ getEmulationState(): EmulationState;
669
+ /**
670
+ * Add request interception handler
671
+ * @param pattern URL pattern or resource type to match
672
+ * @param handler Handler function for matched requests
673
+ * @returns Unsubscribe function
674
+ */
675
+ intercept(pattern: string | RequestPattern, handler: RequestHandler): Promise<() => void>;
676
+ /**
677
+ * Route requests matching pattern to a mock response
678
+ * Convenience wrapper around intercept()
679
+ */
680
+ route(urlPattern: string, options: RouteOptions): Promise<() => void>;
681
+ /**
682
+ * Block requests matching resource types
683
+ */
684
+ blockResources(types: ResourceType[]): Promise<() => void>;
685
+ /**
686
+ * Disable all request interception
687
+ */
688
+ disableInterception(): Promise<void>;
689
+ /**
690
+ * Get all cookies for the current page
691
+ */
692
+ cookies(urls?: string[]): Promise<Cookie[]>;
693
+ /**
694
+ * Set a cookie
695
+ */
696
+ setCookie(options: SetCookieOptions): Promise<boolean>;
697
+ /**
698
+ * Set multiple cookies
699
+ */
700
+ setCookies(cookies: SetCookieOptions[]): Promise<void>;
701
+ /**
702
+ * Delete a specific cookie
703
+ */
704
+ deleteCookie(options: DeleteCookieOptions): Promise<void>;
705
+ /**
706
+ * Delete multiple cookies
707
+ */
708
+ deleteCookies(cookies: DeleteCookieOptions[]): Promise<void>;
709
+ /**
710
+ * Clear all cookies
711
+ */
712
+ clearCookies(options?: ClearCookiesOptions): Promise<void>;
713
+ /**
714
+ * Get localStorage value
715
+ */
716
+ getLocalStorage(key: string): Promise<string | null>;
717
+ /**
718
+ * Set localStorage value
719
+ */
720
+ setLocalStorage(key: string, value: string): Promise<void>;
721
+ /**
722
+ * Remove localStorage item
723
+ */
724
+ removeLocalStorage(key: string): Promise<void>;
725
+ /**
726
+ * Clear localStorage
727
+ */
728
+ clearLocalStorage(): Promise<void>;
729
+ /**
730
+ * Get sessionStorage value
731
+ */
732
+ getSessionStorage(key: string): Promise<string | null>;
733
+ /**
734
+ * Set sessionStorage value
735
+ */
736
+ setSessionStorage(key: string, value: string): Promise<void>;
737
+ /**
738
+ * Remove sessionStorage item
739
+ */
740
+ removeSessionStorage(key: string): Promise<void>;
741
+ /**
742
+ * Clear sessionStorage
743
+ */
744
+ clearSessionStorage(): Promise<void>;
745
+ /**
746
+ * Enable console message capture
747
+ */
748
+ private enableConsole;
749
+ /**
750
+ * Handle console API calls
751
+ */
752
+ private handleConsoleMessage;
753
+ /**
754
+ * Handle JavaScript exceptions
755
+ */
756
+ private handleException;
757
+ /**
758
+ * Handle dialog opening
759
+ */
760
+ private handleDialogOpening;
761
+ /**
762
+ * Format console arguments to string
763
+ */
764
+ private formatConsoleArgs;
765
+ /**
766
+ * Subscribe to console messages
767
+ */
768
+ onConsole(handler: ConsoleHandler): Promise<() => void>;
769
+ /**
770
+ * Subscribe to page errors
771
+ */
772
+ onError(handler: ErrorHandler): Promise<() => void>;
773
+ /**
774
+ * Set dialog handler (only one at a time)
775
+ */
776
+ onDialog(handler: DialogHandler | null): Promise<void>;
777
+ /**
778
+ * Collect console messages during an action
779
+ */
780
+ collectConsole<T>(fn: () => Promise<T>): Promise<{
781
+ result: T;
782
+ messages: ConsoleMessage[];
783
+ }>;
784
+ /**
785
+ * Collect errors during an action
786
+ */
787
+ collectErrors<T>(fn: () => Promise<T>): Promise<{
788
+ result: T;
789
+ errors: PageError[];
790
+ }>;
791
+ /**
792
+ * Reset page state for clean test isolation
793
+ * - Stops any pending operations
794
+ * - Clears localStorage and sessionStorage
795
+ * - Resets internal state
796
+ */
797
+ reset(): Promise<void>;
798
+ /**
799
+ * Close this page (no-op for now, managed by Browser)
800
+ * This is a placeholder for API compatibility
801
+ */
802
+ close(): Promise<void>;
803
+ /**
804
+ * Retry wrapper for operations that may encounter stale nodes
805
+ * Catches "Could not find node with given id" errors and retries
806
+ */
807
+ private withStaleNodeRetry;
808
+ /**
809
+ * Find an element using single or multiple selectors
810
+ * Supports ref: prefix for ref-based selectors (e.g., "ref:e4")
811
+ */
812
+ private findElement;
813
+ /**
814
+ * Ensure we have a valid root node ID
815
+ */
816
+ private ensureRootNode;
817
+ /**
818
+ * Execute Runtime.evaluate in the current frame context
819
+ * Automatically injects contextId when in an iframe
820
+ */
821
+ private evaluateInFrame;
822
+ /**
823
+ * Scroll an element into view
824
+ */
825
+ private scrollIntoView;
826
+ /**
827
+ * Get element box model (position and dimensions)
828
+ */
829
+ private getBoxModel;
830
+ /**
831
+ * Click an element by node ID
832
+ */
833
+ private clickElement;
834
+ }
835
+
836
+ /**
837
+ * Action/Step types for batch execution
838
+ */
839
+ type ActionType = 'goto' | 'click' | 'fill' | 'type' | 'select' | 'check' | 'uncheck' | 'submit' | 'press' | 'focus' | 'hover' | 'scroll' | 'wait' | 'snapshot' | 'screenshot' | 'evaluate' | 'text' | 'switchFrame' | 'switchToMain';
840
+ interface Step {
841
+ /** Action type */
842
+ action: ActionType;
843
+ /** Target selector(s) - array means try each until one works */
844
+ selector?: string | string[];
845
+ /** URL for goto action */
846
+ url?: string;
847
+ /** Value for fill, type, select, evaluate actions */
848
+ value?: string | string[];
849
+ /** Key for press action */
850
+ key?: string;
851
+ /** What to wait for (wait action) */
852
+ waitFor?: 'visible' | 'hidden' | 'attached' | 'detached' | 'navigation' | 'networkIdle';
853
+ /** Step-specific timeout override (ms) */
854
+ timeout?: number;
855
+ /** Should this step's failure be ignored? */
856
+ optional?: boolean;
857
+ /** Submit method */
858
+ method?: 'enter' | 'click' | 'enter+click';
859
+ /** Clear input before filling */
860
+ clear?: boolean;
861
+ /** Delay between keystrokes for type action */
862
+ delay?: number;
863
+ /** Wait for navigation after click action completes */
864
+ waitForNavigation?: boolean;
865
+ /** Custom select: trigger selector */
866
+ trigger?: string | string[];
867
+ /** Custom select: option selector */
868
+ option?: string | string[];
869
+ /** Custom select: match type */
870
+ match?: 'text' | 'value' | 'contains';
871
+ /** Scroll coordinates */
872
+ x?: number;
873
+ y?: number;
874
+ /** Scroll direction for page-level scroll */
875
+ direction?: 'up' | 'down' | 'left' | 'right';
876
+ /** Scroll amount in pixels */
877
+ amount?: number;
878
+ /** Screenshot options */
879
+ format?: 'png' | 'jpeg' | 'webp';
880
+ quality?: number;
881
+ fullPage?: boolean;
882
+ }
883
+ interface BatchOptions {
884
+ /** Default timeout for all steps (ms) */
885
+ timeout?: number;
886
+ /** How to handle failures */
887
+ onFail?: 'stop' | 'continue';
888
+ }
889
+ interface StepResult {
890
+ /** Step index */
891
+ index: number;
892
+ /** Action type */
893
+ action: ActionType;
894
+ /** Target selector(s) if provided */
895
+ selector?: string | string[];
896
+ /** Which selector was actually used (if multiple provided) */
897
+ selectorUsed?: string;
898
+ /** Whether the step succeeded */
899
+ success: boolean;
900
+ /** Time taken in ms */
901
+ durationMs: number;
902
+ /** Error message if failed */
903
+ error?: string;
904
+ /** Selectors that failed before success (if multiple provided) */
905
+ failedSelectors?: Array<{
906
+ selector: string;
907
+ reason: string;
908
+ }>;
909
+ /** Result value (for snapshot, screenshot, evaluate) */
910
+ result?: unknown;
911
+ /** Text content (for text action) */
912
+ text?: string;
913
+ }
914
+ interface BatchResult {
915
+ /** Whether all steps succeeded */
916
+ success: boolean;
917
+ /** Index where execution stopped (if onFail: 'stop') */
918
+ stoppedAtIndex?: number;
919
+ /** Individual step results */
920
+ steps: StepResult[];
921
+ /** Total execution time in ms */
922
+ totalDurationMs: number;
923
+ }
924
+
925
+ export { type WaitResult as $, type ActionType as A, type BatchOptions as B, type ConsoleHandler as C, type Dialog as D, type ElementInfo as E, type FileInput as F, type GeolocationOptions as G, type FailRequestOptions as H, type InteractiveElement as I, type FulfillRequestOptions as J, type InterceptedRequest as K, type RequestActions as L, type ResourceType as M, NavigationError as N, type RouteOptions as O, Page as P, type ClearCookiesOptions 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, type Cookie as X, type DeleteCookieOptions as Y, type SetCookieOptions as Z, type WaitOptions as _, type RequestHandler as a, type WaitState as a0, waitForAnyElement as a1, waitForElement as a2, waitForNavigation as a3, waitForNetworkIdle as a4, type BatchResult as b, type StepResult as c, type ActionOptions as d, type ActionResult as e, type ConsoleMessage as f, type ConsoleMessageType as g, type CustomSelectConfig as h, type DialogHandler as i, type DialogType as j, type Download as k, ElementNotFoundError as l, type EmulationState as m, type ErrorHandler as n, type FillOptions as o, type NetworkIdleOptions as p, type PageError as q, type PageSnapshot as r, type SnapshotNode as s, type SubmitOptions as t, type TypeOptions as u, type UserAgentOptions as v, type DeviceDescriptor as w, type DeviceName as x, devices as y, type ContinueRequestOptions as z };