/** * Puppeteer Core Functions * * This module implements the core browser automation functionality using Puppeteer. * It provides a comprehensive set of functions for browser control, page navigation, * interaction with elements, and data extraction. These functions serve as the * underlying implementation for the Chrome Control tools exposed through MCP. * * The module is organized into several categories: * - Browser management (create, list, close browsers) * - Tab management (create, list, close tabs) * - Navigation (navigate to URLs, wait for events) * - Interaction (click, fill, select, hover) * - Input control (keyboard, mouse) * - Data extraction (screenshot, evaluate) * - State management (cookies) * - Action chaining (combining multiple actions) * * Each function follows a consistent pattern: * 1. Accept parameters with proper typing * 2. Perform the requested browser automation task * 3. Return a standardized response with context information * * @module puppeteer */ import { NavigateParams, ScreenshotParams, ClickParams, FillParams, SelectParams, HoverParams, EvaluateParams, BrowserParams, TabParams, KeyboardParams, MouseParams, WaitParams, CookieParams, ChromeToolResponse } from './types/puppeteer.js'; /** * Creates a new browser instance * * Launches a new Chromium browser instance with the specified configuration options. * By default, browsers are launched in windowed mode (not headless) for user visibility, * but this can be customized through the launchOptions parameter. * * @param params - Browser creation parameters * @param params.browserId - Optional ID to assign to the browser (generated if not provided) * @param params.launchOptions - Optional Puppeteer launch options to customize the browser * @returns Promise resolving to a response with browser information * * @example * ```typescript * // Create a browser with default settings * const response = await createBrowser({}); * * // Create a browser with custom options * const response = await createBrowser({ * launchOptions: { * headless: true, * args: ['--no-sandbox', '--disable-setuid-sandbox'] * } * }); * ``` */ export declare function createBrowser(params: BrowserParams): Promise; /** * Lists all available browser instances * * Returns information about all currently running browser instances managed by Chrome Control. * This includes their IDs, page counts, creation times, and last usage times. * * @returns Promise resolving to a response with browser list information * * @example * ```typescript * // Get a list of all running browsers * const response = await listBrowsers(); * console.log(response.content); // Array of text items with browser information * ``` */ export declare function listBrowsers(): Promise; export declare function closeBrowser(params: BrowserParams): Promise; /** * Tab management commands */ export declare function createTab(params: TabParams): Promise; export declare function listTabs(params: BrowserParams): Promise; export declare function closeTab(params: TabParams): Promise; /** * Navigation commands */ /** * Navigates to a specified URL in a browser tab * * This is one of the core functions of Chrome Control. It navigates a browser tab to the specified URL * and can return different types of information about the resulting page based on the responseType parameter. * This function supports response customization to optimize for token efficiency with LLMs. * * @param params - Navigation parameters or URL string * @param params.url - The URL to navigate to * @param params.browserId - Optional browser ID to use (default is used if not provided) * @param params.tabId - Optional tab ID to use (first tab is used if not provided) * @param params.waitUntil - Optional page load state to wait for (defaults to 'networkidle0') * @param params.timeout - Optional timeout in milliseconds (defaults to global timeout) * @param params.responseType - Optional response format type: * - 'full': Full page HTML (default if not specified) * - 'text': Only text content * - 'links': Only links on the page * - 'inputs': Only input fields * - 'jsonld': JSON-LD structured data if available * - 'custom': Filtered by CSS selectors provided in responseOptions * @param params.responseOptions - Optional additional options for customizing the response * @returns Promise resolving to a response with page information * * @example * ```typescript * // Navigate to a URL with default settings * const response = await navigate('https://example.com'); * * // Navigate with custom response format * const response = await navigate({ * url: 'https://example.com', * responseType: 'text', * waitUntil: 'domcontentloaded', * timeout: 30000 * }); * * // Navigate and get only links * const response = await navigate({ * url: 'https://example.com', * responseType: 'links' * }); * ``` */ export declare function navigate(params: NavigateParams | string): Promise; /** * Wait for behaviors */ export declare function wait(params: WaitParams): Promise; /** * Taking screenshots */ /** * Takes a screenshot of the current page or a specific element * * This function captures visual information from the browser, either the entire page * or a specific element identified by a CSS selector. The screenshot is returned as * a Base64-encoded image that can be displayed by LLMs with vision capabilities. * * @param params - Screenshot parameters * @param params.browserId - Optional browser ID to use (default is used if not provided) * @param params.tabId - Optional tab ID to use (first tab is used if not provided) * @param params.selector - Optional CSS selector to capture a specific element * @param params.fullPage - Whether to capture the full scrollable page (default: false) * @param params.encoding - Image encoding format (default: 'base64') * @param params.type - Image format type (default: 'png') * @param params.quality - Optional quality for JPEG images (1-100) * @param params.omitBackground - Whether to make background transparent if possible * @param params.captureBeyondViewport - Whether to capture content outside viewport in fullPage mode * @param params.fromSurface - Whether to screenshot from GPU surface rather than software rendering * @returns Promise resolving to a response with the screenshot image * * @example * ```typescript * // Capture the entire viewport * const response = await screenshot({}); * * // Capture a specific element * const response = await screenshot({ * selector: '#main-content' * }); * * // Capture the full page * const response = await screenshot({ * fullPage: true, * type: 'jpeg', * quality: 80 * }); * ``` */ export declare function screenshot(params: ScreenshotParams): Promise; /** * Mouse interactions */ /** * Clicks an element on the page * * This function simulates a mouse click on an element identified by a CSS selector. * It waits for the element to be present on the page before attempting to click it. * Additional click options can be provided to customize the click behavior. * * @param params - Click parameters * @param params.selector - CSS selector to identify the element to click * @param params.browserId - Optional browser ID to use (default is used if not provided) * @param params.tabId - Optional tab ID to use (first tab is used if not provided) * @param params.options - Optional click behavior options (button, clickCount, delay, etc.) * @returns Promise resolving to a response with click result information * * @example * ```typescript * // Click a button * const response = await click({ * selector: 'button.submit' * }); * * // Double-click with right mouse button * const response = await click({ * selector: '#target-element', * options: { * button: 'right', * clickCount: 2 * } * }); * ``` */ export declare function click(params: ClickParams): Promise; export declare function hover(params: HoverParams): Promise; export declare function mouse(params: MouseParams): Promise; /** * Keyboard interactions */ export declare function keyboard(params: KeyboardParams): Promise; /** * Form interactions */ /** * Fills a form field with the specified value * * This function fills an input field or textarea identified by a CSS selector * with the provided value. It first clears the field by triple-clicking it * (which selects all text) and then types the new value. * * @param params - Fill parameters * @param params.selector - CSS selector to identify the input field to fill * @param params.value - The text to enter into the input field * @param params.browserId - Optional browser ID to use (default is used if not provided) * @param params.tabId - Optional tab ID to use (first tab is used if not provided) * @returns Promise resolving to a response with fill result information * * @example * ```typescript * // Fill a text input * const response = await fill({ * selector: 'input[name="username"]', * value: 'johndoe' * }); * * // Fill a textarea * const response = await fill({ * selector: 'textarea#message', * value: 'This is a multi-line\nmessage to be entered.' * }); * ``` */ export declare function fill(params: FillParams): Promise; export declare function select(params: SelectParams): Promise; /** * Cookie management */ export declare function cookies(params: CookieParams): Promise; /** * JavaScript evaluation */ export declare function evaluate(params: EvaluateParams): Promise; /** * Check if puppeteer is installed and working */ /** * Checks if Puppeteer is correctly installed and functional * * This diagnostic function verifies that Puppeteer can successfully launch and control * a Chrome browser. It's typically called during server startup to ensure that the * browser automation system is operational before accepting requests. * * The function attempts to launch a browser and then immediately close it. If this * operation succeeds, Puppeteer is considered available and working. * * @returns Promise resolving to a boolean indicating Puppeteer availability * * @example * ```typescript * // Check if Puppeteer is available before starting the server * const isPuppeteerAvailable = await checkPuppeteer(); * if (!isPuppeteerAvailable) { * console.error('Chrome automation unavailable - exiting'); * process.exit(1); * } * ``` */ export declare function checkPuppeteer(): Promise; /** * Action chaining for multiple operations */ export declare function chain(params: any): Promise; /** * Close all browsers on shutdown */ /** * Closes all browser instances * * This utility function cleanly shuts down all browser instances that were created * by Chrome Control. It's typically called during server shutdown to ensure that * no browser processes are left running in the background. * * @returns Promise that resolves when all browsers have been closed * * @example * ```typescript * // During server shutdown * process.on('SIGTERM', async () => { * console.log('Shutting down...'); * await closeAllBrowsers(); * process.exit(0); * }); * ``` */ export declare function closeAllBrowsers(): Promise; //# sourceMappingURL=puppeteer.d.ts.map