2019-11-26 00:06:52 +01:00
|
|
|
// Copyright (c) Microsoft Corporation.
|
|
|
|
|
// Licensed under the MIT license.
|
|
|
|
|
|
2019-11-28 01:03:51 +01:00
|
|
|
import * as js from './javascript';
|
2019-12-06 01:26:09 +01:00
|
|
|
import * as dom from './dom';
|
2019-11-28 01:03:51 +01:00
|
|
|
|
2019-12-06 01:26:09 +01:00
|
|
|
type Boxed<Args extends any[]> = { [Index in keyof Args]: Args[Index] | js.JSHandle<Args[Index]> };
|
2019-11-26 00:06:52 +01:00
|
|
|
type PageFunction<Args extends any[], R = any> = string | ((...args: Args) => R | Promise<R>);
|
|
|
|
|
type PageFunctionOn<On, Args extends any[], R = any> = string | ((on: On, ...args: Args) => R | Promise<R>);
|
|
|
|
|
|
2019-12-06 01:26:09 +01:00
|
|
|
type Handle<T> = T extends Node ? dom.ElementHandle<T> : js.JSHandle<T>;
|
2019-12-06 20:52:32 +01:00
|
|
|
type ElementForSelector<T> = T extends keyof HTMLElementTagNameMap ? HTMLElementTagNameMap[T] : Element;
|
2019-12-06 01:26:09 +01:00
|
|
|
|
2019-11-28 01:03:51 +01:00
|
|
|
export type Evaluate = <Args extends any[], R>(pageFunction: PageFunction<Args, R>, ...args: Boxed<Args>) => Promise<R>;
|
2019-12-06 01:26:09 +01:00
|
|
|
export type EvaluateHandle = <Args extends any[], R>(pageFunction: PageFunction<Args, R>, ...args: Boxed<Args>) => Promise<Handle<R>>;
|
2019-12-17 23:30:02 +01:00
|
|
|
export type $Eval = <Args extends any[], R, S extends string>(selector: S, pageFunction: PageFunctionOn<ElementForSelector<S>, Args, R>, ...args: Boxed<Args>) => Promise<R>;
|
|
|
|
|
export type $$Eval = <Args extends any[], R, S extends string>(selector: S, pageFunction: PageFunctionOn<ElementForSelector<S>[], Args, R>, ...args: Boxed<Args>) => Promise<R>;
|
2019-12-06 01:26:09 +01:00
|
|
|
export type EvaluateOn<T> = <Args extends any[], R>(pageFunction: PageFunctionOn<T, Args, R>, ...args: Boxed<Args>) => Promise<R>;
|
|
|
|
|
export type EvaluateHandleOn<T> = <Args extends any[], R>(pageFunction: PageFunctionOn<T, Args, R>, ...args: Boxed<Args>) => Promise<Handle<R>>;
|
2019-11-28 01:03:51 +01:00
|
|
|
|
2019-12-11 20:26:34 +01:00
|
|
|
export type Size = { width: number, height: number };
|
2019-11-28 01:03:51 +01:00
|
|
|
export type Point = { x: number, y: number };
|
2019-12-11 20:26:34 +01:00
|
|
|
export type Rect = Size & Point;
|
2019-12-05 18:54:50 +01:00
|
|
|
export type Quad = [ Point, Point, Point, Point ];
|
2019-12-04 22:11:10 +01:00
|
|
|
|
|
|
|
|
export type TimeoutOptions = { timeout?: number };
|
2019-12-15 04:13:22 +01:00
|
|
|
export type Visibility = 'visible' | 'hidden' | 'any';
|
2019-12-04 22:11:10 +01:00
|
|
|
|
|
|
|
|
export type Polling = 'raf' | 'mutation' | number;
|
|
|
|
|
export type WaitForFunctionOptions = TimeoutOptions & { polling?: Polling };
|
|
|
|
|
|
2019-12-06 20:33:24 +01:00
|
|
|
export type ElementScreenshotOptions = {
|
2019-12-05 23:48:39 +01:00
|
|
|
type?: 'png' | 'jpeg',
|
|
|
|
|
path?: string,
|
|
|
|
|
quality?: number,
|
|
|
|
|
omitBackground?: boolean,
|
|
|
|
|
};
|
2019-12-06 20:33:24 +01:00
|
|
|
|
|
|
|
|
export type ScreenshotOptions = ElementScreenshotOptions & {
|
|
|
|
|
fullPage?: boolean,
|
|
|
|
|
clip?: Rect,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export type Viewport = {
|
|
|
|
|
width: number;
|
|
|
|
|
height: number;
|
|
|
|
|
deviceScaleFactor?: number;
|
|
|
|
|
isMobile?: boolean;
|
|
|
|
|
isLandscape?: boolean;
|
|
|
|
|
hasTouch?: boolean;
|
2019-12-10 20:15:14 +01:00
|
|
|
};
|
2019-12-17 23:00:39 +01:00
|
|
|
|
|
|
|
|
export type SearchParamsMatch = { [key: string]: string | RegExp | (string | RegExp)[] };
|
|
|
|
|
export type URLMatch = {
|
|
|
|
|
url?: string | RegExp,
|
|
|
|
|
hash?: string | RegExp,
|
|
|
|
|
host?: string | RegExp,
|
|
|
|
|
hostname?: string | RegExp,
|
|
|
|
|
origin?: string | RegExp,
|
|
|
|
|
password?: string | RegExp,
|
|
|
|
|
pathname?: string | RegExp,
|
|
|
|
|
port?: string | RegExp,
|
|
|
|
|
protocol?: string | RegExp,
|
|
|
|
|
search?: string | RegExp,
|
|
|
|
|
strictSearchParams?: boolean,
|
|
|
|
|
searchParams?: SearchParamsMatch,
|
|
|
|
|
username?: string | RegExp,
|
|
|
|
|
};
|