/** * Copyright (c) Microsoft Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { EventEmitter } from 'events'; import * as types from '../types'; export interface Channel extends EventEmitter { _type: string; _guid: string; _object: any; } export interface BrowserTypeChannel extends Channel { connect(params: { options: types.ConnectOptions }): Promise; launch(params: { options?: types.LaunchOptions }): Promise; launchPersistentContext(params: { userDataDir: string, options?: types.LaunchOptions & types.BrowserContextOptions }): Promise; } export type BrowserTypeInitializer = { executablePath: string, name: string }; export interface BrowserChannel extends Channel { close(): Promise; newContext(params: { options?: types.BrowserContextOptions }): Promise; newPage(params: { options?: types.BrowserContextOptions }): Promise; } export type BrowserInitializer = {}; export interface BrowserContextChannel extends Channel { on(event: 'bindingCall', callback: (params: BindingCallChannel) => void): this; on(event: 'page', callback: (params: PageChannel) => void): this; addCookies(params: { cookies: types.SetNetworkCookieParam[] }): Promise; addInitScript(params: { source: string }): Promise; clearCookies(): Promise; clearPermissions(): Promise; close(): Promise; cookies(params: { urls: string[] }): Promise; exposeBinding(params: { name: string }): Promise; grantPermissions(params: { permissions: string[]; options?: { origin?: string } }): Promise; newPage(): Promise; setDefaultNavigationTimeoutNoReply(params: { timeout: number }): void; setDefaultTimeoutNoReply(params: { timeout: number }): void; setExtraHTTPHeaders(params: { headers: types.Headers }): Promise; setGeolocation(params: { geolocation: types.Geolocation | null }): Promise; setHTTPCredentials(params: { httpCredentials: types.Credentials | null }): Promise; setNetworkInterceptionEnabled(params: { enabled: boolean }): Promise; setOffline(params: { offline: boolean }): Promise; waitForEvent(params: { event: string }): Promise; } export type BrowserContextInitializer = { pages: PageChannel[] }; export interface PageChannel extends Channel { on(event: 'bindingCall', callback: (params: BindingCallChannel) => void): this; on(event: 'close', callback: () => void): this; on(event: 'console', callback: (params: ConsoleMessageChannel) => void): this; on(event: 'crash', callback: () => void): this; on(event: 'dialog', callback: (params: DialogChannel) => void): this; on(event: 'download', callback: (params: DownloadChannel) => void): this; on(event: 'domcontentloaded', callback: () => void): this; on(event: 'frameAttached', callback: (params: FrameChannel) => void): this; on(event: 'frameDetached', callback: (params: FrameChannel) => void): this; on(event: 'frameNavigated', callback: (params: { frame: FrameChannel, url: string, name: string }) => void): this; on(event: 'frameNavigated', callback: (params: { frame: FrameChannel, url: string, name: string }) => void): this; on(event: 'load', callback: () => void): this; on(event: 'pageError', callback: (params: { error: types.Error }) => void): this; on(event: 'popup', callback: (params: PageChannel) => void): this; on(event: 'request', callback: (params: RequestChannel) => void): this; on(event: 'requestFailed', callback: (params: { request: RequestChannel, failureText: string | null }) => void): this; on(event: 'requestFinished', callback: (params: RequestChannel) => void): this; on(event: 'response', callback: (params: ResponseChannel) => void): this; on(event: 'route', callback: (params: { route: RouteChannel, request: RequestChannel }) => void): this; setDefaultNavigationTimeoutNoReply(params: { timeout: number }): void; setDefaultTimeoutNoReply(params: { timeout: number }): Promise; setFileChooserInterceptedNoReply(params: { intercepted: boolean }): Promise; addInitScript(params: { source: string }): Promise; close(params: { options?: { runBeforeUnload?: boolean } }): Promise; emulateMedia(params: { options: { media?: 'screen' | 'print', colorScheme?: 'dark' | 'light' | 'no-preference' } }): Promise; exposeBinding(params: { name: string }): Promise; goBack(params: { options?: types.NavigateOptions }): Promise; goForward(params: { options?: types.NavigateOptions }): Promise; opener(): Promise; reload(params: { options?: types.NavigateOptions }): Promise; screenshot(params: { options?: types.ScreenshotOptions }): Promise; setExtraHTTPHeaders(params: { headers: types.Headers }): Promise; setNetworkInterceptionEnabled(params: { enabled: boolean }): Promise; setViewportSize(params: { viewportSize: types.Size }): Promise; // Input keyboardDown(params: { key: string }): Promise; keyboardUp(params: { key: string }): Promise; keyboardInsertText(params: { text: string }): Promise; keyboardType(params: { text: string, options?: { delay?: number } }): Promise; keyboardPress(params: { key: string, options?: { delay?: number } }): Promise; mouseMove(params: { x: number, y: number, options?: { steps?: number } }): Promise; mouseDown(params: { options?: { button?: types.MouseButton, clickCount?: number } }): Promise; mouseUp(params: { options?: { button?: types.MouseButton, clickCount?: number } }): Promise; mouseClick(params: { x: number, y: number, options?: { delay?: number, button?: types.MouseButton, clickCount?: number } }): Promise; // A11Y accessibilitySnapshot(params: { options: { interestingOnly?: boolean, root?: ElementHandleChannel } }): Promise; } export type PageInitializer = { mainFrame: FrameChannel, viewportSize: types.Size | null }; export interface FrameChannel extends Channel { $$eval(params: { selector: string; expression: string, isFunction: boolean, arg: any }): Promise; $eval(params: { selector: string; expression: string, isFunction: boolean, arg: any }): Promise; addScriptTag(params: { options: { url?: string | undefined, path?: string | undefined, content?: string | undefined, type?: string | undefined } }): Promise; addStyleTag(params: { options: { url?: string | undefined, path?: string | undefined, content?: string | undefined } }): Promise; check(params: { selector: string, options: types.TimeoutOptions & { force?: boolean } & { noWaitAfter?: boolean } }): Promise; click(params: { selector: string, options: types.PointerActionOptions & types.MouseClickOptions & types.TimeoutOptions & { force?: boolean } & { noWaitAfter?: boolean } }): Promise; content(): Promise; dblclick(params: { selector: string, options: types.PointerActionOptions & types.MouseMultiClickOptions & types.TimeoutOptions & { force?: boolean }}): Promise; dispatchEvent(params: { selector: string, type: string, eventInit: Object | undefined, options: types.TimeoutOptions }): Promise; evaluateExpression(params: { expression: string, isFunction: boolean, arg: any }): Promise; evaluateExpressionHandle(params: { expression: string, isFunction: boolean, arg: any}): Promise; fill(params: { selector: string, value: string, options: types.NavigatingActionWaitOptions }): Promise; focus(params: { selector: string, options: types.TimeoutOptions }): Promise; frameElement(): Promise; getAttribute(params: { selector: string, name: string, options: types.TimeoutOptions }): Promise; goto(params: { url: string, options: types.GotoOptions }): Promise; hover(params: { selector: string, options: types.PointerActionOptions & types.TimeoutOptions & { force?: boolean } }): Promise; innerHTML(params: { selector: string, options: types.TimeoutOptions }): Promise; innerText(params: { selector: string, options: types.TimeoutOptions }): Promise; press(params: { selector: string, key: string, options: { delay?: number | undefined } & types.TimeoutOptions & { noWaitAfter?: boolean } }): Promise; querySelector(params: { selector: string }): Promise; querySelectorAll(params: { selector: string }): Promise; selectOption(params: { selector: string, values: string | ElementHandleChannel | types.SelectOption | string[] | ElementHandleChannel[] | types.SelectOption[] | null, options: types.NavigatingActionWaitOptions }): Promise; setContent(params: { html: string, options: types.NavigateOptions }): Promise; setInputFiles(params: { selector: string, files: { name: string, mimeType: string, buffer: string }[], options: types.NavigatingActionWaitOptions }): Promise; textContent(params: { selector: string, options: types.TimeoutOptions }): Promise; title(): Promise; type(params: { selector: string, text: string, options: { delay?: number | undefined } & types.TimeoutOptions & { noWaitAfter?: boolean } }): Promise; uncheck(params: { selector: string, options: types.TimeoutOptions & { force?: boolean } & { noWaitAfter?: boolean } }): Promise; waitForFunction(params: { expression: string, isFunction: boolean, arg: any; options: types.WaitForFunctionOptions }): Promise; waitForLoadState(params: { state: types.LifecycleEvent, options: types.TimeoutOptions }): Promise; waitForNavigation(params: { options: types.WaitForNavigationOptions }): Promise; waitForSelector(params: { selector: string, options: types.WaitForElementOptions }): Promise; } export type FrameInitializer = { url: string, name: string, parentFrame: FrameChannel | null }; export interface JSHandleChannel extends Channel { dispose(): Promise; evaluateExpression(params: { expression: string, isFunction: boolean, arg: any }): Promise; evaluateExpressionHandle(params: { expression: string, isFunction: boolean, arg: any}): Promise; getPropertyList(): Promise<{ name: string, value: JSHandleChannel}[]>; jsonValue(): Promise; } export type JSHandleInitializer = { preview: string, }; export interface ElementHandleChannel extends JSHandleChannel { $$evalExpression(params: { selector: string; expression: string, isFunction: boolean, arg: any }): Promise; $evalExpression(params: { selector: string; expression: string, isFunction: boolean, arg: any }): Promise; boundingBox(): Promise; check(params: { options?: types.TimeoutOptions & { force?: boolean } & { noWaitAfter?: boolean } }): Promise; click(params: { options?: types.PointerActionOptions & types.MouseClickOptions & types.TimeoutOptions & { force?: boolean } & { noWaitAfter?: boolean } }): Promise; contentFrame(): Promise; dblclick(params: { options?: types.PointerActionOptions & types.MouseMultiClickOptions & types.TimeoutOptions & { force?: boolean } & { noWaitAfter?: boolean } }): Promise; dispatchEvent(params: { type: string, eventInit: any }): Promise; fill(params: { value: string; options?: types.NavigatingActionWaitOptions }): Promise; focus(): Promise; getAttribute(params: { name: string }): Promise; hover(params: { options?: types.PointerActionOptions & types.TimeoutOptions & { force?: boolean } }): Promise; innerHTML(): Promise; innerText(): Promise; ownerFrame(): Promise; press(params: { key: string; options?: { delay?: number } & types.TimeoutOptions & { noWaitAfter?: boolean } }): Promise; querySelector(params: { selector: string }): Promise; querySelectorAll(params: { selector: string }): Promise; screenshot(params: { options?: types.ElementScreenshotOptions }): Promise; scrollIntoViewIfNeeded(params: { options?: types.TimeoutOptions }): Promise; selectOption(params: { values: string | ElementHandleChannel | types.SelectOption | string[] | ElementHandleChannel[] | types.SelectOption[] | null; options?: types.NavigatingActionWaitOptions }): string[] | Promise; selectText(params: { options?: types.TimeoutOptions }): Promise; setInputFiles(params: { files: string | string[] | types.FilePayload | types.FilePayload[], options?: types.NavigatingActionWaitOptions }): Promise; textContent(): Promise; type(params: { text: string; options?: { delay?: number } & types.TimeoutOptions & { noWaitAfter?: boolean } }): Promise; uncheck(params: { options?: types.TimeoutOptions & { force?: boolean } & { noWaitAfter?: boolean } }): Promise; } export interface RequestChannel extends Channel { response(): Promise; } export type RequestInitializer = { frame: FrameChannel, url: string, resourceType: string, method: string, postData: string | null, headers: types.Headers, isNavigationRequest: boolean, redirectedFrom: RequestChannel | null, }; export interface RouteChannel extends Channel { abort(params: { errorCode: string }): Promise; continue(params: { overrides: { method?: string, headers?: types.Headers, postData?: string } }): Promise; fulfill(params: { response: types.FulfillResponse & { path?: string } }): Promise; } export type RouteInitializer = { request: RequestChannel, }; export interface ResponseChannel extends Channel { body(): Promise; finished(): Promise; } export type ResponseInitializer = { request: RequestChannel, url: string, status: number, statusText: string, headers: types.Headers, }; export interface ConsoleMessageChannel extends Channel { } export type ConsoleMessageInitializer = { type: string, text: string, args: JSHandleChannel[], location: types.ConsoleMessageLocation, }; export interface BindingCallChannel extends Channel { reject(params: { error: types.Error }): void; resolve(params: { result: any }): void; } export type BindingCallInitializer = { frame: FrameChannel, name: string, args: any[] }; export interface DialogChannel extends Channel { accept(params: { promptText?: string }): Promise; dismiss(): Promise; } export type DialogInitializer = { type: string, message: string, defaultValue: string, }; export interface DownloadChannel extends Channel { path(): Promise; failure(): Promise; delete(): Promise; } export type DownloadInitializer = { url: string, suggestedFilename: string, };