// Type definitions for puppeteer 0.12 // Project: https://github.com/GoogleChrome/puppeteer#readme // Definitions by: Marvin Hagemeister // Christopher Deutsch // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 /// export interface Keyboard { down(key: string, options?: { text?: string }): Promise; press(key: string, options?: { text?: string, delay?: number }): Promise; sendCharacter(char: string): Promise; type(text: string, options?: { delay?: number }): Promise; up(key: string): Promise; } export interface MousePressOptions { button?: MouseButtons; clickCount?: number; } export interface Mouse { click(x: number, y: number, options: ClickOptions): Promise; down(options?: MousePressOptions): Promise; move(x: number, y: number, options?: { steps: number }): Promise; up(options?: MousePressOptions): Promise; } export interface Touchscreen { tap(x: number, y: number): Promise; } export interface Tracing { start(options: { path: string; screenshots?: boolean }): Promise; stop(): Promise; } export interface Dialog { accept(promptText?: string): Promise; defaultValue(): string; dismiss(): Promise; message(): string; type: "alert" | "beforeunload" | "confirm" | "prompt"; } export interface ConsoleMessage { args: JSHandle[]; text: string; type: 'log' | 'debug' | 'info' | 'error' | 'warning' | 'dir' | 'dirxml' | 'table' | 'trace' | 'clear' | 'startGroup' | 'startGroupCollapsed' | 'endGroup' | 'assert' | 'profile' | 'profileEnd' | 'count' | 'timeEnd'; } export type PageEvents = | "console" | "dialog" | "error" | "frameattached" | "framedetached" | "framenavigated" | "load" | "pageerror" | "request" | "requestfailed" | "requestfinished" | "response"; export interface AuthOptions { username: string; password: string; } export type MouseButtons = "left" | "right" | "middle"; export interface ClickOptions { /** defaults to left */ button?: MouseButtons; /** defaults to 1 */ clickCount?: number; /** * Time to wait between mousedown and mouseup in milliseconds. * Defaults to 0. */ delay?: number; } export interface Cookie { name: string; value: string; domain: string; path: string; expires: number; httpOnly: boolean; secure: boolean; sameSite: "Strict" | "Lax"; } export interface Viewport { width: number; height: number; deviceScaleFactor?: number; isMobile?: boolean; hasTouch?: boolean; isLandscape?: boolean; } export interface EmulateOptions { viewport?: Viewport; userAgent?: string; } export type EvaluateFn = string | ((...args: any[]) => any); export interface NavigationOptions { timeout?: number; waitUntil?: "load" | "networkidle" | "networkIdleTimeout"; networkIdleInflight?: number; networkIdleTimeout?: number; } export type PDFFormat = | "Letter" | "Legal" | "Tabload" | "Ledger" | "A0" | "A1" | "A2" | "A3" | "A4" | "A5"; export interface PDFOptions { /** If no path is provided, the PDF won't be saved to the disk. */ path?: string; scale?: number; displayHeaderFooter?: boolean; printBackground?: boolean; landscape?: boolean; /** * Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty * string, which means print all pages. */ pageRanges?: string; format?: PDFFormat; width?: string; height?: string; margin?: { top?: string; right?: string; bottom?: string; left?: string; }; } export interface ScreenshotOptions { path?: string; type?: "jpeg" | "png"; /** The quality of the image, between 0-100. Not applicable to png images. */ quality?: number; fullPage?: boolean; clip?: BoundingBox; omitBackground?: boolean; } export interface TagOptions { url?: string; path?: string; content?: string; } export interface PageFnOptions { polling?: "raf" | "mutation" | number; timeout?: number; } export interface BoundingBox { x: number; y: number; width: number; height: number; } export interface ElementHandle extends JSHandle { boundingBox(): BoundingBox; click(options?: ClickOptions): Promise; focus(): Promise; hover(): Promise; press(key: string, options?: { text?: string, delay?: number }): Promise; screenshot(options?: ScreenshotOptions): Promise; tap(): Promise; toString(): string; type(text: string, options?: { delay: number }): Promise; uploadFile(...filePaths: string[]): Promise; } export interface ExecutionContext { evaluate( fn: EvaluateFn, ...args: any[] ): Promise; evaluateHandle( fn: EvaluateFn, ...args: any[] ): Promise; queryObjects(prototypeHandle: JSHandle): JSHandle; } export interface JSHandle { asElement(): ElementHandle; dispose(): Promise; executionContext(): ExecutionContext; getProperties(): Promise>; getProperty(propertyName: string): Promise; jsonValue(): Promise; } export interface Metrics { Timestamp: number; Documents: number; Frames: number; JSEventListeners: number; Nodes: number; LayoutCount: number; RecalcStyleCount: number; LayoutDuration: number; RecalcStyleDuration: number; ScriptDuration: number; TaskDuration: number; JSHeapUsedSize: number; JSHeapTotalSize: number; } export type Headers = Record; export type HttpMethod = | "GET" | "POST" | "PATCH" | "PUT" | "DELETE" | "OPTIONS"; export type ResourceType = | "Document" | "Stylesheet" | "Image" | "Media" | "Font" | "Script" | "TextTrack" | "XHR" | "Fetch" | "EventSource" | "WebSocket" | "Manifest" | "Other"; export interface Overrides { url?: string; method?: HttpMethod; postData?: string; headers?: Headers; } export interface Request { abort(): Promise; continue(overrides?: Overrides): Promise; headers: Headers; method: HttpMethod; postData: string | undefined; resourceType: ResourceType; response(): Response | null; url: string; } export interface Response { buffer(): Promise; headers: Headers; json(): Promise; ok: boolean; request(): Request; status: number; text(): Promise; url: string; } export interface FrameBase { $(selector: string): Promise; $$(selector: string): Promise; $$eval( selector: string, fn: (...args: any[]) => void ): Promise; $eval( selector: string, fn: (...args: any[]) => void ): Promise; addScriptTag(options: TagOptions): Promise; addStyleTag(options: TagOptions): Promise; injectFile(filePath: string): Promise; evaluate( fn: EvaluateFn, ...args: any[] ): Promise; title(): Promise; url(): string; waitFor( // fn can be an abritary function // tslint:disable-next-line ban-types selectorOrFunctionOrTimeout: string | number | Function, options?: any, ...args: any[] ): Promise; waitForFunction( // fn can be an abritary function // tslint:disable-next-line ban-types fn: string | Function, options?: PageFnOptions, ...args: any[] ): Promise; waitForSelector( selector: string, options?: { visible: boolean; timeout: number } ): Promise; } export interface Frame extends FrameBase { childFrames(): Frame[]; executionContext(): ExecutionContext; isDetached(): boolean; name(): string; parentFrame(): Frame | undefined; } export interface EventObj { console: ConsoleMessage; dialog: Dialog; error: Error; frameattached: Frame; framedetached: Frame; framenavigated: Frame; load: undefined; metrics: { title: string, metrics: any }; pageerror: string; request: Request; requestfailed: Request; requestfinished: Request; response: Response; } export interface Page extends FrameBase { on( event: K, handler: (e: EventObj[K], ...args: any[]) => void ): void; authenticate(credentials: AuthOptions | null): Promise; click(selector: string, options?: ClickOptions): Promise; close(): Promise; content(): Promise; cookies(...urls: string[]): Promise; deleteCookie( ...cookies: Array<{ name: string; url?: string; domain?: string; path?: string; secure?: boolean; }> ): Promise; emulate(options: Partial): Promise; emulateMedia(mediaType: 'screen' | 'print' | null): Promise; evaluateHandle( fn: EvaluateFn, ...args: any[] ): Promise; evaluateOnNewDocument( fn: EvaluateFn, ...args: any[] ): Promise; // Argument `fn` can be an arbitrary function exposeFunction(name: string, fn: (...args: any[]) => any): Promise; focus(selector: string): Promise; frames(): Frame[]; getMetrics(): Metrics; goBack(options?: Partial): Promise; goForward(options?: Partial): Promise; goto(url: string, options?: Partial): Promise; hover(selector: string): Promise; keyboard: Keyboard; mainFrame(): Frame; mouse: Mouse; pdf(options?: Partial): Promise; queryObjects(prototypeHandle: JSHandle): Promise; reload(options?: NavigationOptions): Promise; screenshot(options?: ScreenshotOptions): Promise; select(selector: string, ...values: string[]): Promise; setContent(html: string): Promise; setCookie(...cookies: Cookie[]): Promise; setExtraHTTPHeaders(headers: Headers): Promise; setJavaScriptEnabled(enabled: boolean): Promise; setRequestInterceptionEnabled(value: boolean): Promise; setUserAgent(userAgent: string): Promise; setViewport(viewport: Viewport): Promise; tap(selector: string): Promise; touchscreen: Touchscreen; tracing: Tracing; type(selector: string, text: string, options?: { delay: number }): Promise; viewport(): Viewport; waitForNavigation(options?: NavigationOptions): Promise; } export interface Browser { close(): Promise; newPage(): Promise; version(): Promise; wsEndpoint(): string; } export interface LaunchOptions { /** Whether to ignore HTTPS errors during navigation. Defaults to false. */ ignoreHTTPSErrors?: boolean; /** Whether to run Chromium in headless mode. Defaults to true. */ headless?: boolean; /** * Path to a Chromium executable to run instead of bundled Chromium. If * executablePath is a relative path, then it is resolved relative to current * working directory. */ executablePath?: string; /** * Slows down Puppeteer operations by the specified amount of milliseconds. * Useful so that you can see what is going on. */ slowMo?: number; /** * Additional arguments to pass to the Chromium instance. List of Chromium * flags can be found here. */ args?: string[]; /** Close chrome process on Ctrl-C. Defaults to true. */ handleSIGINT?: boolean; /** * Maximum time in milliseconds to wait for the Chrome instance to start. * Defaults to 30000 (30 seconds). Pass 0 to disable timeout. */ timeout?: number; /** * Whether to pipe browser process stdout and stderr into process.stdout and * process.stderr. Defaults to false. */ dumpio?: boolean; /** Path to a User Data Directory. */ userDataDir?: string; /** Specify environment variables that will be visible to Chromium. Defaults to process.env. */ env?: any; /** Whether to auto-open DevTools panel for each tab. If this option is true, the headless option will be set false. */ devtools?: boolean; } export interface ConnectOptions { browserWSEndpoint?: string; ignoreHTTPSErrors?: boolean; } /** Attaches Puppeteer to an existing Chromium instance */ export function connect(options?: ConnectOptions): Promise; /** Path where Puppeteer expects to find bundled Chromium */ export function executablePath(): string; export function launch(options?: LaunchOptions): Promise;