/** * 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 * as js from './javascript'; import * as dom from './dom'; type NoHandles = Arg extends js.JSHandle ? never : (Arg extends object ? { [Key in keyof Arg]: NoHandles } : Arg); type Unboxed = Arg extends dom.ElementHandle ? T : Arg extends js.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 Array ? Array> : Arg extends object ? { [Key in keyof Arg]: Unboxed } : Arg; export type Func0 = string | (() => R | Promise); export type Func1 = string | ((arg: Unboxed) => R | Promise); export type FuncOn = string | ((on: On, arg2: Unboxed) => R | Promise); export type SmartHandle = T extends Node ? dom.ElementHandle : js.JSHandle; export type Size = { width: number, height: number }; export type Point = { x: number, y: number }; export type Rect = Size & Point; export type Quad = [ Point, Point, Point, Point ]; export type TimeoutOptions = { timeout?: number }; export type WaitForElementOptions = TimeoutOptions & { state?: 'attached' | 'detached' | 'visible' | 'hidden' }; export type Polling = 'raf' | number; export type WaitForFunctionOptions = TimeoutOptions & { polling?: Polling }; export type LifecycleEvent = 'load' | 'domcontentloaded' | 'networkidle'; export const kLifecycleEvents: Set = new Set(['load', 'domcontentloaded', 'networkidle']); export type NavigateOptions = TimeoutOptions & { waitUntil?: LifecycleEvent, }; export type NavigatingActionWaitOptions = TimeoutOptions & { noWaitAfter?: boolean, }; export type PointerActionWaitOptions = TimeoutOptions & { force?: boolean, }; export type WaitForNavigationOptions = TimeoutOptions & { waitUntil?: LifecycleEvent, url?: URLMatch }; export type ElementScreenshotOptions = { type?: 'png' | 'jpeg', path?: string, quality?: number, omitBackground?: boolean, }; export type ScreenshotOptions = ElementScreenshotOptions & { fullPage?: boolean, clip?: Rect, }; export type URLMatch = string | RegExp | ((url: URL) => boolean); export type Credentials = { username: string; password: string; }; export type Geolocation = { longitude: number; latitude: number; accuracy?: number; }; export type SelectOption = { value?: string; label?: string; index?: number; }; export type FilePayload = { name: string, mimeType: string, buffer: Buffer, }; export type FileTransferPayload = { name: string, type: string, data: string, }; export type MediaType = 'screen' | 'print'; export const mediaTypes: Set = new Set(['screen', 'print']); export type ColorScheme = 'dark' | 'light' | 'no-preference'; export const colorSchemes: Set = new Set(['dark', 'light', 'no-preference']); export type DeviceDescriptor = { userAgent: string, viewport: Size, deviceScaleFactor: number, isMobile: boolean, hasTouch: boolean }; export type Devices = { [name: string]: DeviceDescriptor }; export type PDFOptions = { scale?: number, displayHeaderFooter?: boolean, headerTemplate?: string, footerTemplate?: string, printBackground?: boolean, landscape?: boolean, pageRanges?: string, format?: string, width?: string|number, height?: string|number, preferCSSPageSize?: boolean, margin?: {top?: string|number, bottom?: string|number, left?: string|number, right?: string|number}, path?: string, } export type CoverageEntry = { url: string, text: string, ranges: {start: number, end: number}[] }; export type CSSCoverageOptions = { resetOnNavigation?: boolean, }; export type JSCoverageOptions = { resetOnNavigation?: boolean, reportAnonymousScripts?: boolean, }; export type InjectedScriptResult = { error?: string, value?: T }; export type InjectedScriptProgress = { canceled: boolean, log: (message: string) => void, logRepeating: (message: string) => void, }; export type InjectedScriptLogs = { current: string[], next: Promise }; export type InjectedScriptPoll = { result: Promise, logs: Promise, takeLastLogs: () => string[], cancel: () => void, }; export type ProxySettings = { server: string, bypass?: string, username?: string, password?: string }; export type WaitForEventOptions = Function | { predicate?: Function, timeout?: number };