import { EventEmitter } from 'events'; import CDP from 'chrome-remote-interface'; export interface WaitForResponseOptions { urlPattern: string | RegExp; timeout?: number; statusCode?: number; } export interface Viewport { width: number; height: number; } export interface Cookie { name: string; value: string; domain?: string; path?: string; expires?: number; size?: number; httpOnly?: boolean; secure?: boolean; session?: boolean; sameSite?: 'Strict' | 'Lax' | 'None'; } export interface GotoOptions { waitUntil?: "domcontentloaded" | "load"; timeout?: number; } export interface SelectOptionOptions { /** Maximum wait time in milliseconds. Default: 30000 */ timeout?: number; /** Bypass visibility and disabled checks. Default: false */ force?: boolean; /** Wait for dropdown options to load after opening. Default: true */ waitForOptions?: boolean; /** Maximum scroll attempts for virtualized dropdowns. Default: 10 */ maxScrollAttempts?: number; } export interface EvaluateResult { result: any; exceptionDetails?: { text: string; }; } export interface ScreenshotOptions { /** The path to save the screenshot to. Optional. */ path?: string; /** Whether to capture the full scrollable page. Default: false */ fullPage?: boolean; /** The image format. Default: 'png' */ format?: 'png' | 'jpeg'; } export interface CdpScreenshotOptions { /** The image format */ format: 'png' | 'jpeg'; /** Whether to capture beyond the viewport */ captureBeyondViewport?: boolean; } export default class CdpPage extends EventEmitter { _rawClient: CDP.Client; client: CDP.Client; private loadedUrl; isReconnecting: boolean; private enabledDomains; private connectionMonitor?; private isClosed; private humanization; private lastMousePosition; constructor(client: CDP.Client); private _attachConnectionMonitor; static create(client: CDP.Client): Promise; private initialize; /** * Lazily enable Page domain only when needed for script injection. * This avoids enabling Page upfront which is a CDP detection vector. * Once enabled, subsequent calls are no-ops. */ ensurePageEnabled(): Promise; /** * Lazily enable Network domain only when needed for request interception/monitoring. * This avoids enabling Network upfront which is a CDP detection vector. * Once enabled, subsequent calls are no-ops. */ ensureNetworkEnabled(): Promise; setHumanizationOptions(options?: { mouse?: boolean; keyboard?: boolean; scroll?: boolean; }): void; url(): Promise; /** * Get current URL without activating the Runtime domain. * Uses Page.getNavigationHistory which only requires the Page domain. */ private _getCurrentUrlWithoutRuntime; goto(url: string, options?: GotoOptions): Promise; /** * Reloads the current page. * @param options - Options for waiting and timeout, similar to goto. */ reload(options?: GotoOptions): Promise; evaluate(pageFunction: Function | string, ...args: any[]): Promise; click(selector: string, options?: { timeout?: number; force?: boolean; delay?: number; button?: 'left' | 'right' | 'middle'; clickCount?: number; }): Promise; /** * Performs a human-like click with proper mouse events. * Note: screenX/screenY compensation is handled browser-side via fingerprint * overrides that set realistic window.screenX/screenY values, which Chrome * uses when constructing MouseEvent from CDP dispatch. */ private _performClick; private _moveMouseTo; /** * Gets detailed information about an element */ private _getElementInfo; /** * Enhanced visibility check that considers more factors */ private _isElementVisible; /** * Enhanced clickable check that considers more factors */ private _isElementClickable; /** * Enhanced scroll into view with better positioning */ private _scrollElementIntoView; /** * Waits for an element's position to stabilize by polling its position over time. * This is useful for waiting for scroll animations or dynamic layout changes to complete. * * @param selector - The CSS selector for the element to monitor * @param timeout - Maximum time to wait in milliseconds (default: 2000) * @param checkInterval - How often to check position in milliseconds (default: 100) * @param stabilityThreshold - Number of consecutive stable checks required (default: 3) * @param tolerance - Maximum pixel difference to consider "stable" (default: 1) */ private _waitForElementPositionToStabilize; waitForElementPositionToStabilize(selector: string, timeout?: number, checkInterval?: number, stabilityThreshold?: number, tolerance?: number): Promise; /** * Check if element is within the viewport (with some tolerance) */ private _isElementInViewport; type(selector: string, text: string, options?: { delay?: number; }): Promise; /** * Deletes (clears) the value of an input field specified by selector. * @param selector - The CSS selector for the input element. */ deleteInput(selector: string): Promise; setViewport(viewport: Viewport): Promise; setUserAgent(userAgent: string): Promise; setExtraHTTPHeaders(headers: Record): Promise; waitForSelector(selector: string, options?: { timeout?: number; }): Promise; waitForResponse(urlPart: string, statusCode?: number, timeout?: number): Promise; screenshot(options?: ScreenshotOptions): Promise; content(): Promise; toCheerio(): Promise; close(): Promise; elementExists(selector: string): Promise; getTextContent(selector: string): Promise; getHref(selector: string): Promise; scrollIntoView(selector: string): Promise; setupFetchMetadataHeaders(): Promise; blockRequests(urlPatterns: string[]): Promise; private getNodeId; setCookies(cookies: Cookie[]): Promise; /** * Retrieves all cookies associated with the given URLs or all cookies for the current page if no URLs are provided. * * @param {string[]} [urls] - An optional array of URLs for which to retrieve cookies. * If no URLs are provided, the method will return all cookies associated with the current page. * * @returns {Promise} - A promise that resolves to an array of cookies. * Each cookie contains information such as name, value, domain, path, expiration, and flags like httpOnly, secure, etc. * * */ getCookies(urls?: string[]): Promise; /** * Evaluates a function across multiple elements matching the given selector. * * @param selector - The CSS selector to find elements. * @param pageFunction - The function to execute within the browser context. * @param args - Additional arguments to pass to the pageFunction. * @returns - The result of the evaluation. */ $$eval(selector: string, pageFunction: (elements: HTMLElement[], ...args: any[]) => T, ...args: any[]): Promise; /** * Enables a CDP domain only if it hasn't been enabled yet * @private */ private _enableDomain; reconnectSession(retries?: number): Promise; /** * Selects one or more options from a select element or dropdown. * * Automatically handles both regular HTML select elements and custom dropdowns: * - For