/** * @fileoverview Client for the Cloudflare Puppeteer-based scraper service. * Renders JavaScript-heavy pages and bypasses bot detection. * * This wraps the scraper-cloudflare package deployed as a Cloudflare Worker * with Browser Rendering (Puppeteer) support. */ export interface ScraperOptions { /** URL to render */ url: string; /** API key for authentication (optional if SCRAPER_API_KEY not set) */ apiKey?: string; /** Additional wait time after page load (ms) */ wait?: number; /** Block image loading for faster rendering */ blockImages?: boolean; /** Session ID for cookie persistence */ sessionId?: string; /** Navigation timeout (ms) */ timeout?: number; /** Puppeteer waitUntil condition */ waitUntil?: 'domcontentloaded' | 'load' | 'networkidle0' | 'networkidle2'; /** Response format */ format?: 'html' | 'json'; /** Custom headers */ headers?: Record; /** Proxy configuration */ proxyUrl?: string; proxyUser?: string; proxyPass?: string; /** Bypass Cloudflare challenges and CAPTCHAs */ bypassCaptcha?: boolean; /** Challenge detection pattern */ challengeMatch?: string; /** Max retry attempts for challenges */ maxRetries?: number; /** 2Captcha API key for solving */ twoCaptchaKey?: string; /** Abort signal to bound the request (e.g. an 8s deadline). */ signal?: AbortSignal; } export interface ScraperJsonResponse { html: string; url: string; title: string; cookies: Array<{ name: string; value: string; domain: string; path: string; expires?: number; httpOnly?: boolean; secure?: boolean; sameSite?: 'Strict' | 'Lax' | 'None'; }>; challengeBypassed: boolean; retryCount: number; loadTime: number; } export interface ScraperConfig { /** Base URL of the scraper service */ baseURL: string; /** Global API key */ apiKey?: string; } /** * Renders a URL using the Cloudflare Puppeteer scraper service. * Supports JavaScript rendering, bot detection bypass, and session management. * * @param options - Scraping configuration * @param config - Service configuration (base URL and API key) * @returns Rendered HTML or structured JSON response * * @example * ```ts * // Basic usage * const html = await renderWithCloudflare({ url: 'https://example.com' }); * * // With challenge bypass * const result = await renderWithCloudflare({ * url: 'https://protected-site.com', * bypassCaptcha: true, * format: 'json' * }); * * // With session management * const html = await renderWithCloudflare({ * url: 'https://site-requiring-login.com', * sessionId: 'user-123', * blockImages: true * }); * ``` */ export declare function renderWithCloudflare(options: ScraperOptions, config?: Partial): Promise; /** * Convenience function to render a URL and return just the HTML content. * * @param url - URL to render * @param options - Additional scraping options * @param config - Service configuration * @returns Rendered HTML string */ export declare function renderUrlToHtml(url: string, options?: Omit, config?: Partial): Promise; /** * Renders a URL and returns full metadata including cookies, load time, etc. * * @param url - URL to render * @param options - Additional scraping options * @param config - Service configuration * @returns Structured response with HTML and metadata */ export declare function renderUrlWithMetadata(url: string, options?: Omit, config?: Partial): Promise;