/** * 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 { launch(params: { options?: types.LaunchOptions }): Promise; launchPersistentContext(params: { userDataDir: string, options?: types.LaunchOptions & types.BrowserContextOptions }): Promise; connect(params: { options: types.ConnectOptions }): Promise; } export interface BrowserChannel extends Channel { newContext(params: { options?: types.BrowserContextOptions }): Promise; newPage(params: { options?: types.BrowserContextOptions }): Promise; close(): Promise; } export interface BrowserContextChannel extends Channel { setDefaultNavigationTimeoutNoReply(params: { timeout: number }): void; setDefaultTimeoutNoReply(params: { timeout: number }): void; exposeBinding(params: { name: string }): Promise; newPage(): Promise; cookies(params: { urls: string[] }): Promise; addCookies(params: { cookies: types.SetNetworkCookieParam[] }): Promise; clearCookies(): Promise; grantPermissions(params: { permissions: string[]; options?: { origin?: string } }): Promise; clearPermissions(): Promise; setGeolocation(params: { geolocation: types.Geolocation | null }): Promise; setExtraHTTPHeaders(params: { headers: types.Headers }): Promise; setOffline(params: { offline: boolean }): Promise; setHTTPCredentials(params: { httpCredentials: types.Credentials | null }): Promise; addInitScript(params: { source: string }): Promise; setNetworkInterceptionEnabled(params: { enabled: boolean }): Promise; waitForEvent(params: { event: string }): Promise; close(): Promise; } export interface PageChannel extends Channel { 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 }) => void): this; on(event: 'request', callback: (params: RequestChannel) => void): this; on(event: 'response', callback: (params: ResponseChannel) => void): this; on(event: 'requestFinished', callback: (params: RequestChannel) => void): this; on(event: 'requestFailed', callback: (params: RequestChannel) => void): this; on(event: 'close', callback: () => void): this; setDefaultNavigationTimeoutNoReply(params: { timeout: number }): void; setDefaultTimeoutNoReply(params: { timeout: number }): Promise; setFileChooserInterceptedNoReply(params: { intercepted: boolean }): Promise; opener(): Promise; exposeBinding(params: { name: string }): Promise; setExtraHTTPHeaders(params: { headers: types.Headers }): Promise; reload(params: { options?: types.NavigateOptions }): Promise; waitForEvent(params: { event: string }): Promise; goBack(params: { options?: types.NavigateOptions }): Promise; goForward(params: { options?: types.NavigateOptions }): Promise; emulateMedia(params: { options: { media?: 'screen' | 'print', colorScheme?: 'dark' | 'light' | 'no-preference' } }): Promise; setViewportSize(params: { viewportSize: types.Size }): Promise; addInitScript(params: { source: string }): Promise; setNetworkInterceptionEnabled(params: { enabled: boolean }): Promise; screenshot(params: { options?: types.ScreenshotOptions }): Promise; close(params: { options?: { runBeforeUnload?: boolean } }): Promise; } export interface FrameChannel extends Channel { goto(params: { url: string, options: types.GotoOptions }): Promise; waitForNavigation(params: { options: types.WaitForNavigationOptions }): Promise; waitForLoadState(params: { state: types.LifecycleEvent, options: types.TimeoutOptions }): Promise; frameElement(): Promise; evaluateExpression(params: { expression: string, isFunction: boolean, arg: any }): Promise; evaluateExpressionHandle(params: { expression: string, isFunction: boolean, arg: any}): Promise; querySelector(params: { selector: string }): Promise; waitForSelector(params: { selector: string, options: types.WaitForElementOptions }): Promise; dispatchEvent(params: { selector: string, type: string, eventInit: Object | undefined, options: types.TimeoutOptions }): Promise; $eval(params: { selector: string; expression: string, isFunction: boolean, arg: any }): Promise; $$eval(params: { selector: string; expression: string, isFunction: boolean, arg: any }): Promise; querySelectorAll(params: { selector: string }): Promise; content(): Promise; setContent(params: { html: string, options: types.NavigateOptions }): 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; click(params: { selector: string, options: types.PointerActionOptions & types.MouseClickOptions & types.TimeoutOptions & { force?: boolean } & { noWaitAfter?: boolean } }): Promise; dblclick(params: { selector: string, options: types.PointerActionOptions & types.MouseMultiClickOptions & types.TimeoutOptions & { force?: boolean }}): Promise; fill(params: { selector: string, value: string, options: types.NavigatingActionWaitOptions }): Promise; focus(params: { selector: string, options: types.TimeoutOptions }): Promise; textContent(params: { selector: string, options: types.TimeoutOptions }): Promise; innerText(params: { selector: string, options: types.TimeoutOptions }): Promise; innerHTML(params: { selector: string, options: types.TimeoutOptions }): Promise; getAttribute(params: { selector: string, name: string, options: types.TimeoutOptions }): Promise; hover(params: { selector: string, options: types.PointerActionOptions & types.TimeoutOptions & { force?: boolean } }): Promise; selectOption(params: { selector: string, values: string | ElementHandleChannel | types.SelectOption | string[] | ElementHandleChannel[] | types.SelectOption[] | null, options: types.NavigatingActionWaitOptions }): Promise; setInputFiles(params: { selector: string, files: string | string[] | types.FilePayload | types.FilePayload[], options: types.NavigatingActionWaitOptions }): Promise; type(params: { selector: string, text: string, options: { delay?: number | undefined } & types.TimeoutOptions & { noWaitAfter?: boolean } }): Promise; press(params: { selector: string, key: string, options: { delay?: number | undefined } & types.TimeoutOptions & { noWaitAfter?: boolean } }): Promise; check(params: { selector: string, options: types.TimeoutOptions & { force?: boolean } & { 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; title(): Promise; } export interface JSHandleChannel extends Channel { 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; dispose(): Promise; } export interface ElementHandleChannel extends JSHandleChannel { ownerFrame(): Promise; contentFrame(): Promise; getAttribute(params: { name: string }): Promise; textContent(): Promise; innerText(): Promise; innerHTML(): Promise; boundingBox(): Promise; hover(params: { options?: types.PointerActionOptions & types.TimeoutOptions & { force?: boolean } }): Promise; click(params: { options?: types.PointerActionOptions & types.MouseClickOptions & types.TimeoutOptions & { force?: boolean } & { noWaitAfter?: boolean } }): Promise; dblclick(params: { options?: types.PointerActionOptions & types.MouseMultiClickOptions & types.TimeoutOptions & { force?: boolean } & { noWaitAfter?: boolean } }): Promise; selectOption(params: { values: string | ElementHandleChannel | types.SelectOption | string[] | ElementHandleChannel[] | types.SelectOption[] | null; options?: types.NavigatingActionWaitOptions }): string[] | Promise; fill(params: { value: string; options?: types.NavigatingActionWaitOptions }): Promise; selectText(params: { options?: types.TimeoutOptions }): Promise; setInputFiles(params: { files: string | string[] | types.FilePayload | types.FilePayload[], options?: types.NavigatingActionWaitOptions }): Promise; focus(): Promise; type(params: { text: string; options?: { delay?: number } & types.TimeoutOptions & { noWaitAfter?: boolean } }): Promise; press(params: { key: string; options?: { delay?: number } & types.TimeoutOptions & { noWaitAfter?: boolean } }): Promise; check(params: { options?: types.TimeoutOptions & { force?: boolean } & { noWaitAfter?: boolean } }): Promise; uncheck(params: { options?: types.TimeoutOptions & { force?: boolean } & { noWaitAfter?: boolean } }): Promise; dispatchEvent(params: { type: string, eventInit: any }): Promise; scrollIntoViewIfNeeded(params: { options?: types.TimeoutOptions }): Promise; screenshot(params: { options?: types.ElementScreenshotOptions }): Promise; querySelector(params: { selector: string }): Promise; querySelectorAll(params: { selector: string }): Promise; $eval(params: { selector: string; expression: string, isFunction: boolean, arg: any }): Promise; $$eval(params: { selector: string; expression: string, isFunction: boolean, arg: any }): Promise; } export interface RequestChannel extends Channel { continue(params: { overrides: { method?: string, headers?: types.Headers, postData?: string } }): Promise; fulfill(params: { response: types.FulfillResponse & { path?: string } }): Promise; abort(params: { errorCode: string }): Promise; response(): Promise; } export interface ResponseChannel extends Channel { body(): Promise; finished(): Promise; }