2020-01-06 18:22:35 -08:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2019-11-25 15:06:52 -08:00
|
|
|
|
2019-11-27 16:03:51 -08:00
|
|
|
import * as js from './javascript';
|
2019-12-05 16:26:09 -08:00
|
|
|
import * as dom from './dom';
|
2020-03-20 15:08:17 -07:00
|
|
|
|
|
|
|
type NoHandles<Arg> = Arg extends js.JSHandle ? never : (Arg extends object ? { [Key in keyof Arg]: NoHandles<Arg[Key]> } : Arg);
|
|
|
|
type Unboxed<Arg> =
|
|
|
|
Arg extends dom.ElementHandle<infer T> ? T :
|
|
|
|
Arg extends js.JSHandle<infer T> ? T :
|
|
|
|
Arg extends NoHandles<Arg> ? Arg :
|
2020-06-03 13:22:05 -07:00
|
|
|
Arg extends [infer A0] ? [Unboxed<A0>] :
|
|
|
|
Arg extends [infer A0, infer A1] ? [Unboxed<A0>, Unboxed<A1>] :
|
|
|
|
Arg extends [infer A0, infer A1, infer A2] ? [Unboxed<A0>, Unboxed<A1>, Unboxed<A2>] :
|
2020-03-20 15:08:17 -07:00
|
|
|
Arg extends Array<infer T> ? Array<Unboxed<T>> :
|
|
|
|
Arg extends object ? { [Key in keyof Arg]: Unboxed<Arg[Key]> } :
|
|
|
|
Arg;
|
|
|
|
export type Func0<R> = string | (() => R | Promise<R>);
|
|
|
|
export type Func1<Arg, R> = string | ((arg: Unboxed<Arg>) => R | Promise<R>);
|
|
|
|
export type FuncOn<On, Arg2, R> = string | ((on: On, arg2: Unboxed<Arg2>) => R | Promise<R>);
|
|
|
|
export type SmartHandle<T> = T extends Node ? dom.ElementHandle<T> : js.JSHandle<T>;
|
2019-11-27 16:03:51 -08:00
|
|
|
|
2019-12-11 11:26:34 -08:00
|
|
|
export type Size = { width: number, height: number };
|
2019-11-27 16:03:51 -08:00
|
|
|
export type Point = { x: number, y: number };
|
2019-12-11 11:26:34 -08:00
|
|
|
export type Rect = Size & Point;
|
2019-12-05 09:54:50 -08:00
|
|
|
export type Quad = [ Point, Point, Point, Point ];
|
2019-12-04 13:11:10 -08:00
|
|
|
|
|
|
|
export type TimeoutOptions = { timeout?: number };
|
2020-02-22 06:16:28 -08:00
|
|
|
|
2020-05-04 11:03:44 -07:00
|
|
|
export type WaitForElementOptions = TimeoutOptions & { state?: 'attached' | 'detached' | 'visible' | 'hidden' };
|
2019-12-04 13:11:10 -08:00
|
|
|
|
2020-04-29 21:34:14 -07:00
|
|
|
export type Polling = 'raf' | number;
|
2019-12-04 13:11:10 -08:00
|
|
|
export type WaitForFunctionOptions = TimeoutOptions & { polling?: Polling };
|
|
|
|
|
2020-04-20 16:52:26 -07:00
|
|
|
export type LifecycleEvent = 'load' | 'domcontentloaded' | 'networkidle';
|
|
|
|
export const kLifecycleEvents: Set<LifecycleEvent> = new Set(['load', 'domcontentloaded', 'networkidle']);
|
2020-03-06 08:24:32 -08:00
|
|
|
|
|
|
|
export type NavigateOptions = TimeoutOptions & {
|
|
|
|
waitUntil?: LifecycleEvent,
|
|
|
|
};
|
|
|
|
|
2020-03-06 16:24:21 -08:00
|
|
|
export type NavigatingActionWaitOptions = TimeoutOptions & {
|
2020-04-16 20:31:04 -07:00
|
|
|
noWaitAfter?: boolean,
|
2020-03-06 14:32:15 -08:00
|
|
|
};
|
|
|
|
|
2020-03-06 16:24:21 -08:00
|
|
|
export type PointerActionWaitOptions = TimeoutOptions & {
|
|
|
|
force?: boolean,
|
2020-03-06 14:32:15 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
export type WaitForNavigationOptions = TimeoutOptions & {
|
|
|
|
waitUntil?: LifecycleEvent,
|
|
|
|
url?: URLMatch
|
|
|
|
};
|
2020-03-06 08:24:32 -08:00
|
|
|
|
2019-12-06 11:33:24 -08:00
|
|
|
export type ElementScreenshotOptions = {
|
2019-12-05 14:48:39 -08:00
|
|
|
type?: 'png' | 'jpeg',
|
|
|
|
path?: string,
|
|
|
|
quality?: number,
|
|
|
|
omitBackground?: boolean,
|
|
|
|
};
|
2019-12-06 11:33:24 -08:00
|
|
|
|
|
|
|
export type ScreenshotOptions = ElementScreenshotOptions & {
|
|
|
|
fullPage?: boolean,
|
|
|
|
clip?: Rect,
|
|
|
|
};
|
|
|
|
|
2020-01-07 11:55:24 -08:00
|
|
|
export type URLMatch = string | RegExp | ((url: URL) => boolean);
|
2019-12-30 14:09:54 -08:00
|
|
|
|
|
|
|
export type Credentials = {
|
|
|
|
username: string;
|
|
|
|
password: string;
|
2020-01-03 12:59:06 -08:00
|
|
|
};
|
2020-01-03 10:14:50 -08:00
|
|
|
|
|
|
|
export type Geolocation = {
|
2020-01-13 15:39:13 -08:00
|
|
|
longitude: number;
|
|
|
|
latitude: number;
|
|
|
|
accuracy?: number;
|
2020-01-03 12:59:06 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
export type SelectOption = {
|
|
|
|
value?: string;
|
|
|
|
label?: string;
|
|
|
|
index?: number;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type FilePayload = {
|
2020-04-16 10:25:28 -07:00
|
|
|
name: string,
|
|
|
|
mimeType: string,
|
|
|
|
buffer: Buffer,
|
|
|
|
};
|
|
|
|
|
|
|
|
export type FileTransferPayload = {
|
2020-01-03 12:59:06 -08:00
|
|
|
name: string,
|
|
|
|
type: string,
|
|
|
|
data: string,
|
|
|
|
};
|
|
|
|
|
|
|
|
export type MediaType = 'screen' | 'print';
|
|
|
|
export const mediaTypes: Set<MediaType> = new Set(['screen', 'print']);
|
|
|
|
|
|
|
|
export type ColorScheme = 'dark' | 'light' | 'no-preference';
|
|
|
|
export const colorSchemes: Set<ColorScheme> = new Set(['dark', 'light', 'no-preference']);
|
2020-01-07 12:53:06 -08:00
|
|
|
|
|
|
|
export type DeviceDescriptor = {
|
|
|
|
userAgent: string,
|
2020-03-17 18:21:02 -07:00
|
|
|
viewport: Size,
|
|
|
|
deviceScaleFactor: number,
|
|
|
|
isMobile: boolean,
|
|
|
|
hasTouch: boolean
|
2020-01-07 12:53:06 -08:00
|
|
|
};
|
2020-03-17 16:04:42 -07:00
|
|
|
export type Devices = { [name: string]: DeviceDescriptor };
|
2020-01-07 13:57:37 -08:00
|
|
|
|
|
|
|
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,
|
2020-02-07 13:36:49 -08:00
|
|
|
ranges: {start: number, end: number}[]
|
2020-01-07 13:57:37 -08:00
|
|
|
};
|
2020-01-16 17:46:50 -08:00
|
|
|
|
|
|
|
export type CSSCoverageOptions = {
|
|
|
|
resetOnNavigation?: boolean,
|
|
|
|
};
|
|
|
|
|
|
|
|
export type JSCoverageOptions = {
|
|
|
|
resetOnNavigation?: boolean,
|
|
|
|
reportAnonymousScripts?: boolean,
|
|
|
|
};
|
2020-03-25 14:08:46 -07:00
|
|
|
|
|
|
|
export type ParsedSelector = {
|
2020-04-27 10:14:09 -07:00
|
|
|
parts: {
|
|
|
|
name: string,
|
|
|
|
body: string,
|
|
|
|
}[],
|
|
|
|
capture?: number,
|
|
|
|
};
|
2020-05-15 15:21:49 -07:00
|
|
|
|
|
|
|
export type InjectedScriptResult<T = undefined> =
|
|
|
|
(T extends undefined ? { status: 'success', value?: T} : { status: 'success', value: T }) |
|
|
|
|
{ status: 'notconnected' } |
|
|
|
|
{ status: 'error', error: string };
|
2020-05-30 15:00:53 -07:00
|
|
|
|
2020-06-01 15:48:23 -07:00
|
|
|
export type InjectedScriptProgress = {
|
|
|
|
canceled: boolean,
|
|
|
|
log: (message: string) => void,
|
|
|
|
};
|
|
|
|
|
|
|
|
export type InjectedScriptLogs = { current: string[], next: Promise<InjectedScriptLogs> };
|
|
|
|
export type InjectedScriptPoll<T> = {
|
2020-05-30 15:00:53 -07:00
|
|
|
result: Promise<T>,
|
2020-06-01 15:48:23 -07:00
|
|
|
logs: Promise<InjectedScriptLogs>,
|
2020-06-06 20:59:06 -07:00
|
|
|
takeLastLogs: () => string[],
|
2020-05-30 15:00:53 -07:00
|
|
|
cancel: () => void,
|
|
|
|
};
|
2020-06-05 13:50:15 -07:00
|
|
|
|
|
|
|
export type ProxySettings = {
|
|
|
|
server: string,
|
|
|
|
bypass?: string,
|
|
|
|
username?: string,
|
|
|
|
password?: string
|
|
|
|
}
|