2020-01-06 18:22:35 -08:00
|
|
|
/**
|
2020-06-25 18:01:18 -07:00
|
|
|
* Copyright 2018 Google Inc. All rights reserved.
|
|
|
|
* Modifications copyright (c) Microsoft Corporation.
|
2020-01-06 18:22:35 -08:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
2020-06-23 14:51:06 -07:00
|
|
|
// NOTE: No imports allowed - only primitive, self-contained types are allowed here.
|
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
|
|
|
|
2020-06-24 10:16:54 -07:00
|
|
|
export type ElementScreenshotOptions = TimeoutOptions & {
|
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
|
|
|
|
2020-06-01 15:48:23 -07:00
|
|
|
export type InjectedScriptProgress = {
|
2020-06-24 15:12:17 -07:00
|
|
|
aborted: boolean,
|
2020-06-01 15:48:23 -07:00
|
|
|
log: (message: string) => void,
|
2020-06-10 18:45:18 -07:00
|
|
|
logRepeating: (message: string) => void,
|
2020-06-01 15:48:23 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
export type InjectedScriptPoll<T> = {
|
2020-05-30 15:00:53 -07:00
|
|
|
result: Promise<T>,
|
2020-06-25 13:13:10 -07:00
|
|
|
// Takes more logs, waiting until at least one message is available.
|
|
|
|
takeNextLogs: () => Promise<string[]>,
|
|
|
|
// Takes all current logs without waiting.
|
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
|
2020-06-10 15:12:50 -07:00
|
|
|
};
|
|
|
|
|
2020-06-23 14:51:06 -07:00
|
|
|
export type WaitForEventOptions = Function | { predicate?: Function, timeout?: number };
|
2020-06-16 17:11:19 -07:00
|
|
|
|
2020-06-23 14:51:06 -07:00
|
|
|
export type KeyboardModifier = 'Alt' | 'Control' | 'Meta' | 'Shift';
|
|
|
|
export type MouseButton = 'left' | 'right' | 'middle';
|
2020-06-16 17:11:19 -07:00
|
|
|
|
2020-06-23 14:51:06 -07:00
|
|
|
export type PointerActionOptions = {
|
|
|
|
modifiers?: KeyboardModifier[];
|
|
|
|
position?: Point;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type MouseClickOptions = PointerActionOptions & {
|
|
|
|
delay?: number;
|
|
|
|
button?: MouseButton;
|
|
|
|
clickCount?: number;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type MouseMultiClickOptions = PointerActionOptions & {
|
|
|
|
delay?: number;
|
|
|
|
button?: MouseButton;
|
|
|
|
};
|
2020-06-24 17:03:28 -07:00
|
|
|
|
|
|
|
export type World = 'main' | 'utility';
|
2020-06-25 08:30:56 -07:00
|
|
|
|
|
|
|
export type Headers = { [key: string]: string };
|
|
|
|
|
|
|
|
export type GotoOptions = NavigateOptions & {
|
|
|
|
referer?: string,
|
|
|
|
};
|
|
|
|
|
|
|
|
export type FulfillResponse = {
|
|
|
|
status?: number,
|
|
|
|
headers?: Headers,
|
|
|
|
contentType?: string,
|
|
|
|
body?: string | Buffer,
|
|
|
|
};
|
|
|
|
|
|
|
|
export type NetworkCookie = {
|
|
|
|
name: string,
|
|
|
|
value: string,
|
|
|
|
domain: string,
|
|
|
|
path: string,
|
|
|
|
expires: number,
|
|
|
|
httpOnly: boolean,
|
|
|
|
secure: boolean,
|
|
|
|
sameSite: 'Strict' | 'Lax' | 'None'
|
|
|
|
};
|
|
|
|
|
|
|
|
export type SetNetworkCookieParam = {
|
|
|
|
name: string,
|
|
|
|
value: string,
|
|
|
|
url?: string,
|
|
|
|
domain?: string,
|
|
|
|
path?: string,
|
|
|
|
expires?: number,
|
|
|
|
httpOnly?: boolean,
|
|
|
|
secure?: boolean,
|
|
|
|
sameSite?: 'Strict' | 'Lax' | 'None'
|
|
|
|
};
|
|
|
|
|
|
|
|
export type BrowserContextOptions = {
|
|
|
|
viewport?: Size | null,
|
|
|
|
ignoreHTTPSErrors?: boolean,
|
|
|
|
javaScriptEnabled?: boolean,
|
|
|
|
bypassCSP?: boolean,
|
|
|
|
userAgent?: string,
|
|
|
|
locale?: string,
|
|
|
|
timezoneId?: string,
|
|
|
|
geolocation?: Geolocation,
|
|
|
|
permissions?: string[],
|
|
|
|
extraHTTPHeaders?: Headers,
|
|
|
|
offline?: boolean,
|
|
|
|
httpCredentials?: Credentials,
|
|
|
|
deviceScaleFactor?: number,
|
|
|
|
isMobile?: boolean,
|
|
|
|
hasTouch?: boolean,
|
|
|
|
colorScheme?: ColorScheme,
|
|
|
|
acceptDownloads?: boolean,
|
|
|
|
};
|
|
|
|
|
|
|
|
export type Env = {[key: string]: string | number | boolean | undefined};
|
|
|
|
|
|
|
|
export type LaunchOptionsBase = {
|
|
|
|
executablePath?: string,
|
|
|
|
args?: string[],
|
|
|
|
ignoreDefaultArgs?: boolean | string[],
|
|
|
|
handleSIGINT?: boolean,
|
|
|
|
handleSIGTERM?: boolean,
|
|
|
|
handleSIGHUP?: boolean,
|
|
|
|
timeout?: number,
|
|
|
|
env?: Env,
|
|
|
|
headless?: boolean,
|
|
|
|
devtools?: boolean,
|
|
|
|
proxy?: ProxySettings,
|
|
|
|
downloadsPath?: string,
|
|
|
|
};
|
|
|
|
|
|
|
|
export type LaunchOptions = LaunchOptionsBase & { slowMo?: number };
|
|
|
|
export type LaunchServerOptions = LaunchOptionsBase & { port?: number };
|
|
|
|
|
|
|
|
export type ConnectOptions = {
|
|
|
|
wsEndpoint: string,
|
|
|
|
slowMo?: number,
|
|
|
|
timeout?: number,
|
|
|
|
};
|
2020-06-25 18:01:18 -07:00
|
|
|
|
|
|
|
export type SerializedAXNode = {
|
|
|
|
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?: SerializedAXNode[]
|
|
|
|
};
|
|
|
|
|
|
|
|
export type ConsoleMessageLocation = {
|
|
|
|
url?: string,
|
|
|
|
lineNumber?: number,
|
|
|
|
columnNumber?: number,
|
|
|
|
};
|