UNPKG

@puberty-labs/clits

Version:

CLiTS (Chrome Logging and Inspection Tool Suite) is a powerful Node.js library for automated Chrome browser testing, logging, and inspection. It provides a comprehensive suite of tools for monitoring network requests, console logs, DOM mutations, and more

214 lines (213 loc) 5.94 kB
import { EventEmitter } from 'events'; export interface NavigationOptions { url: string; waitForSelector?: string; timeout?: number; screenshotPath?: string; chromePort?: number; chromeHost?: string; } export interface InteractionOptions { clickSelector?: string; typeSelector?: string; typeText?: string; toggleSelector?: string; waitForSelector?: string; timeout?: number; captureNetwork?: boolean; screenshotPath?: string; chromePort?: number; chromeHost?: string; discoverTabs?: boolean; findSaveButton?: boolean; customSavePatterns?: string[]; tabLabelPattern?: string; takeScreenshot?: boolean; base64Output?: boolean; fullPageScreenshot?: boolean; withMetadata?: boolean; annotated?: boolean; selectorMap?: boolean; useJavaScriptExpression?: boolean; jsExpression?: string; switchTabIndex?: number; tabNext?: boolean; tabPrev?: boolean; keyCommand?: string; } export interface InteractionResult { success: boolean; timestamp: string; screenshotPath?: string; screenshotBase64?: string; selectorMap?: Array<{ selector: string; text: string; coordinates: { x: number; y: number; }; boundingBox: { x: number; y: number; width: number; height: number; }; }>; metadata?: { viewport: { width: number; height: number; }; url: string; title: string; elementCount: number; }; networkLogs?: any[]; error?: string; } export interface AutomationStep { action: 'navigate' | 'wait' | 'click' | 'type' | 'toggle' | 'screenshot' | 'discover_links' | 'interact' | 'click-text' | 'click-region' | 'key' | 'switch-tab' | 'tab-next' | 'tab-prev'; url?: string; selector?: string; text?: string; path?: string; timeout?: number; wait?: number; clickText?: string; clickColor?: string; clickRegion?: string; clickDescription?: string; screenshotPath?: string; region?: string; keyCommand?: string; tabIndex?: number; } export interface AutomationScript { steps: AutomationStep[]; options?: { timeout?: number; captureNetwork?: boolean; monitor?: boolean; }; } export interface AutomationOptions { scriptPath: string; monitor?: boolean; saveResultsPath?: string; chromePort?: number; chromeHost?: string; } export interface AutomationResult { success: boolean; completedSteps: number; totalSteps: number; error?: string; screenshots?: string[]; networkLogs?: any[]; monitoringData?: any[]; timestamp: string; } interface CDPClient extends EventEmitter { Page: any; Runtime: any; Network: any; DOM: any; Input: any; close: () => Promise<void>; } export declare class ChromeAutomation { private static readonly DEFAULT_PORT; private static readonly DEFAULT_HOST; private static readonly DEFAULT_TIMEOUT; private port; private host; private chromeExtractor?; constructor(port?: number, host?: string); navigate(options: NavigationOptions): Promise<{ actualUrl: string; success: boolean; }>; interact(options: InteractionOptions): Promise<InteractionResult>; runAutomation(options: AutomationOptions): Promise<AutomationResult>; private connectToChrome; private checkChromeConnection; private launchChromeIfNeeded; private autoSelectTarget; private executeStep; private escapeSelector; private findElementWithFallback; private waitForSelector; private clickElement; private clickElementByJavaScript; private typeInElement; private toggleElement; private takeScreenshot; /** * Discovers all tab labels in a dialog or tabbed interface * @param client CDP client instance * @returns Array of tab labels with their selectors */ discoverTabLabels(client: CDPClient): Promise<Array<{ label: string; selector: string; index: number; }>>; /** * Finds the best save button in a dialog using multiple strategies * @param client CDP client instance * @param customText Optional custom text patterns for save buttons * @returns Save button element info or null */ findSaveButton(client: CDPClient, customText?: string[]): Promise<{ x: number; y: number; strategy: string; } | null>; private takeEnhancedScreenshot; private generateSelectorMap; private collectPageMetadata; findElementByText(text: string): Promise<string>; findElementByColor(color: string): Promise<string>; findElementByRegion(region: string): Promise<string>; findElementByDescription(description: string): Promise<string>; discoverAllSelectors(): Promise<string[]>; generateElementMap(): Promise<Array<{ tag: string; selector: string; text: string; x: number; y: number; width: number; height: number; isClickable: boolean; }>>; private discoverAllLinks; /** * List all open browser tabs with URLs and titles */ listBrowserTabs(): Promise<Array<{ id: string; type: string; url: string; title: string; webSocketDebuggerUrl?: string; }>>; /** * Switch to a specific tab by index (0-based) */ switchToTab(tabIndex: number): Promise<void>; /** * Switch to the next tab */ switchToNextTab(): Promise<void>; /** * Switch to the previous tab */ switchToPrevTab(): Promise<void>; /** * Send keyboard commands including shortcuts */ sendKeyCommand(client: CDPClient, keyCommand: string): Promise<void>; } export {};