/** * 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 { Protocol } from './protocol'; import { ChildProcess } from 'child_process'; import { EventEmitter } from 'events'; import { Readable } from 'stream'; /** * Can be converted to JSON */ type Serializable = {}; /** * Can be converted to JSON, but may also contain JSHandles. */ type EvaluationArgument = {}; type NoHandles = Arg extends JSHandle ? never : (Arg extends object ? { [Key in keyof Arg]: NoHandles } : Arg); type Unboxed = Arg extends ElementHandle ? T : Arg extends JSHandle ? T : Arg extends NoHandles ? Arg : Arg extends [infer A0] ? [Unboxed] : Arg extends [infer A0, infer A1] ? [Unboxed, Unboxed] : Arg extends [infer A0, infer A1, infer A2] ? [Unboxed, Unboxed, Unboxed] : Arg extends [infer A0, infer A1, infer A2, infer A3] ? [Unboxed, Unboxed, Unboxed, Unboxed] : Arg extends Array ? Array> : Arg extends object ? { [Key in keyof Arg]: Unboxed } : Arg; type PageFunction = string | ((arg: Unboxed) => R | Promise); type PageFunctionOn = string | ((on: On, arg2: Unboxed) => R | Promise); type SmartHandle = T extends Node ? ElementHandle : JSHandle; type ElementHandleForTag = ElementHandle; type PageWaitForSelectorOptionsNotHidden = PageWaitForSelectorOptions & { state: 'visible'|'attached'; }; type ElementHandleWaitForSelectorOptionsNotHidden = ElementHandleWaitForSelectorOptions & { state: 'visible'|'attached'; }; type BindingSource = { context: BrowserContext, page: Page, frame: Frame }; export interface Page { evaluate(pageFunction: PageFunction, arg: Arg): Promise; evaluate(pageFunction: PageFunction, arg?: any): Promise; evaluateHandle(pageFunction: PageFunction, arg: Arg): Promise>; evaluateHandle(pageFunction: PageFunction, arg?: any): Promise>; $(selector: K): Promise | null>; $(selector: string): Promise | null>; $$(selector: K): Promise[]>; $$(selector: string): Promise[]>; $eval(selector: K, pageFunction: PageFunctionOn, arg: Arg): Promise; $eval(selector: string, pageFunction: PageFunctionOn, arg: Arg): Promise; $eval(selector: K, pageFunction: PageFunctionOn, arg?: any): Promise; $eval(selector: string, pageFunction: PageFunctionOn, arg?: any): Promise; $$eval(selector: K, pageFunction: PageFunctionOn, arg: Arg): Promise; $$eval(selector: string, pageFunction: PageFunctionOn, arg: Arg): Promise; $$eval(selector: K, pageFunction: PageFunctionOn, arg?: any): Promise; $$eval(selector: string, pageFunction: PageFunctionOn, arg?: any): Promise; waitForFunction(pageFunction: PageFunction, arg: Arg, options?: PageWaitForFunctionOptions): Promise>; waitForFunction(pageFunction: PageFunction, arg?: any, options?: PageWaitForFunctionOptions): Promise>; waitForSelector(selector: K, options?: PageWaitForSelectorOptionsNotHidden): Promise>; waitForSelector(selector: string, options?: PageWaitForSelectorOptionsNotHidden): Promise>; waitForSelector(selector: K, options: PageWaitForSelectorOptions): Promise | null>; waitForSelector(selector: string, options: PageWaitForSelectorOptions): Promise>; exposeBinding(name: string, playwrightBinding: (source: BindingSource, arg: JSHandle) => any, options: { handle: true }): Promise; exposeBinding(name: string, playwrightBinding: (source: BindingSource, ...args: any[]) => any, options?: { handle?: boolean }): Promise; } export interface Frame { evaluate(pageFunction: PageFunction, arg: Arg): Promise; evaluate(pageFunction: PageFunction, arg?: any): Promise; evaluateHandle(pageFunction: PageFunction, arg: Arg): Promise>; evaluateHandle(pageFunction: PageFunction, arg?: any): Promise>; $(selector: K): Promise | null>; $(selector: string): Promise | null>; $$(selector: K): Promise[]>; $$(selector: string): Promise[]>; $eval(selector: K, pageFunction: PageFunctionOn, arg: Arg): Promise; $eval(selector: string, pageFunction: PageFunctionOn, arg: Arg): Promise; $eval(selector: K, pageFunction: PageFunctionOn, arg?: any): Promise; $eval(selector: string, pageFunction: PageFunctionOn, arg?: any): Promise; $$eval(selector: K, pageFunction: PageFunctionOn, arg: Arg): Promise; $$eval(selector: string, pageFunction: PageFunctionOn, arg: Arg): Promise; $$eval(selector: K, pageFunction: PageFunctionOn, arg?: any): Promise; $$eval(selector: string, pageFunction: PageFunctionOn, arg?: any): Promise; waitForFunction(pageFunction: PageFunction, arg: Arg, options?: PageWaitForFunctionOptions): Promise>; waitForFunction(pageFunction: PageFunction, arg?: any, options?: PageWaitForFunctionOptions): Promise>; waitForSelector(selector: K, options?: PageWaitForSelectorOptionsNotHidden): Promise>; waitForSelector(selector: string, options?: PageWaitForSelectorOptionsNotHidden): Promise>; waitForSelector(selector: K, options: PageWaitForSelectorOptions): Promise | null>; waitForSelector(selector: string, options: PageWaitForSelectorOptions): Promise>; } export interface BrowserContext { exposeBinding(name: string, playwrightBinding: (source: BindingSource, arg: JSHandle) => any, options: { handle: true }): Promise; exposeBinding(name: string, playwrightBinding: (source: BindingSource, ...args: any[]) => any, options?: { handle?: boolean }): Promise; } export interface Worker { evaluate(pageFunction: PageFunction, arg: Arg): Promise; evaluate(pageFunction: PageFunction, arg?: any): Promise; evaluateHandle(pageFunction: PageFunction, arg: Arg): Promise>; evaluateHandle(pageFunction: PageFunction, arg?: any): Promise>; } export interface JSHandle { evaluate(pageFunction: PageFunctionOn, arg: Arg): Promise; evaluate(pageFunction: PageFunctionOn, arg?: any): Promise; evaluateHandle(pageFunction: PageFunctionOn, arg: Arg): Promise>; evaluateHandle(pageFunction: PageFunctionOn, arg?: any): Promise>; jsonValue(): Promise; asElement(): T extends Node ? ElementHandle : null; } export interface ElementHandle extends JSHandle { $(selector: K): Promise | null>; $(selector: string): Promise | null>; $$(selector: K): Promise[]>; $$(selector: string): Promise[]>; $eval(selector: K, pageFunction: PageFunctionOn, arg: Arg): Promise; $eval(selector: string, pageFunction: PageFunctionOn, arg: Arg): Promise; $eval(selector: K, pageFunction: PageFunctionOn, arg?: any): Promise; $eval(selector: string, pageFunction: PageFunctionOn, arg?: any): Promise; $$eval(selector: K, pageFunction: PageFunctionOn, arg: Arg): Promise; $$eval(selector: string, pageFunction: PageFunctionOn, arg: Arg): Promise; $$eval(selector: K, pageFunction: PageFunctionOn, arg?: any): Promise; $$eval(selector: string, pageFunction: PageFunctionOn, arg?: any): Promise; waitForSelector(selector: K, options?: ElementHandleWaitForSelectorOptionsNotHidden): Promise>; waitForSelector(selector: string, options?: ElementHandleWaitForSelectorOptionsNotHidden): Promise>; waitForSelector(selector: K, options: ElementHandleWaitForSelectorOptions): Promise | null>; waitForSelector(selector: string, options: ElementHandleWaitForSelectorOptions): Promise>; } export interface BrowserType { } export interface ChromiumBrowser extends Browser { contexts(): Array; newContext(options?: BrowserContextOptions): Promise; } export interface CDPSession { on: (event: T, listener: (payload: T extends symbol ? any : Protocol.Events[T extends keyof Protocol.Events ? T : never]) => void) => this; addListener: (event: T, listener: (payload: T extends symbol ? any : Protocol.Events[T extends keyof Protocol.Events ? T : never]) => void) => this; off: (event: T, listener: (payload: T extends symbol ? any : Protocol.Events[T extends keyof Protocol.Events ? T : never]) => void) => this; removeListener: (event: T, listener: (payload: T extends symbol ? any : Protocol.Events[T extends keyof Protocol.Events ? T : never]) => void) => this; once: (event: T, listener: (payload: T extends symbol ? any : Protocol.Events[T extends keyof Protocol.Events ? T : never]) => void) => this; send( method: T, params?: Protocol.CommandParameters[T] ): Promise; } type DeviceDescriptor = { viewport: ViewportSize; userAgent: string; deviceScaleFactor: number; isMobile: boolean; hasTouch: boolean; defaultBrowserType: 'chromium' | 'firefox' | 'webkit'; }; export namespace errors { class TimeoutError extends Error {} } export interface Accessibility { snapshot(options?: { /** * Prune uninteresting nodes from the tree. Defaults to `true`. */ interestingOnly?: boolean; /** * The root DOM element for the snapshot. Defaults to the whole page. */ root?: ElementHandle; }): Promise; } type AccessibilityNode = { role: string; name: string; value?: string|number; description?: string; keyshortcuts?: string; roledescription?: string; valuetext?: string; disabled?: boolean; expanded?: boolean; focused?: boolean; modal?: boolean; multiline?: boolean; multiselectable?: boolean; readonly?: boolean; required?: boolean; selected?: boolean; checked?: boolean|"mixed"; pressed?: boolean|"mixed"; level?: number; valuemin?: number; valuemax?: number; autocomplete?: string; haspopup?: string; invalid?: string; orientation?: string; children?: AccessibilityNode[]; } export const selectors: Selectors; export const devices: Devices & DeviceDescriptor[]; // This is required to not export everything by default. See https://github.com/Microsoft/TypeScript/issues/19545#issuecomment-340490459 export {};