UNPKG

78.7 kBTypeScriptView Raw
1// Type definitions for puppeteer 4.0
2// Project: https://github.com/GoogleChrome/puppeteer#readme
3// Definitions by: Marvin Hagemeister <https://github.com/marvinhagemeister>
4// Christopher Deutsch <https://github.com/cdeutsch>
5// Konstantin Simon Maria Möllers <https://github.com/ksm2>
6// Simon Schick <https://github.com/SimonSchick>
7// Serban Ghita <https://github.com/SerbanGhita>
8// Jason Kaczmarsky <https://github.com/JasonKaz>
9// Dave Cardwell <https://github.com/davecardwell>
10// Andrés Ortiz <https://github.com/angrykoala>
11// Piotr Błażejewicz <https://github.com/peterblazejewicz>
12// Cameron Hunter <https://github.com/cameronhunter>
13// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
14// TypeScript Version: 3.0
15
16/// <reference types="node" />
17
18import { ChildProcess } from 'child_process';
19
20import * as errors from './Errors';
21import * as devices from './DeviceDescriptors';
22
23export { errors, devices };
24
25/** Wraps a DOM element into an ElementHandle instance */
26export type WrapElementHandle<X> = X extends Element ? ElementHandle<X> : X;
27
28/** Unwraps a DOM element out of an ElementHandle instance */
29export type UnwrapElementHandle<X> = X extends ElementHandle<infer E> ? E : X;
30
31export type Serializable = number | string | boolean | null | JSONArray | JSONObject;
32export interface JSONArray extends Array<Serializable> {}
33export interface JSONObject {
34 [key: string]: Serializable;
35}
36export type SerializableOrJSHandle = Serializable | JSHandle;
37
38export type Platform = 'mac' | 'win32' | 'win64' | 'linux';
39
40export type Product = 'chrome' | 'firefox';
41
42/** Defines `$eval` and `$$eval` for Page, Frame and ElementHandle. */
43export interface Evalable {
44 /**
45 * This method runs `document.querySelector` within the context and passes it as the first argument to `pageFunction`.
46 * If there's no element matching `selector`, the method throws an error.
47 *
48 * If `pageFunction` returns a Promise, then `$eval` would wait for the promise to resolve and return its value.
49 *
50 * @param selector A selector to query for
51 * @param pageFunction Function to be evaluated in browser context
52 * @returns Promise which resolves to the return value of pageFunction
53 */
54 $eval<R>(selector: string, pageFunction: (element: Element) => R | Promise<R>): Promise<WrapElementHandle<R>>;
55
56 /**
57 * This method runs `document.querySelector` within the context and passes it as the first argument to `pageFunction`.
58 * If there's no element matching `selector`, the method throws an error.
59 *
60 * If `pageFunction` returns a Promise, then `$eval` would wait for the promise to resolve and return its value.
61 *
62 * @param selector A selector to query for
63 * @param pageFunction Function to be evaluated in browser context
64 * @param x1 First argument to pass to pageFunction
65 * @returns Promise which resolves to the return value of pageFunction
66 */
67 $eval<R, X1>(
68 selector: string,
69 pageFunction: (element: Element, x1: UnwrapElementHandle<X1>) => R | Promise<R>,
70 x1: X1,
71 ): Promise<WrapElementHandle<R>>;
72
73 /**
74 * This method runs `document.querySelector` within the context and passes it as the first argument to `pageFunction`.
75 * If there's no element matching `selector`, the method throws an error.
76 *
77 * If `pageFunction` returns a Promise, then `$eval` would wait for the promise to resolve and return its value.
78 *
79 * @param selector A selector to query for
80 * @param pageFunction Function to be evaluated in browser context
81 * @param x1 First argument to pass to pageFunction
82 * @param x2 Second argument to pass to pageFunction
83 * @returns Promise which resolves to the return value of pageFunction
84 */
85 $eval<R, X1, X2>(
86 selector: string,
87 pageFunction: (element: Element, x1: UnwrapElementHandle<X1>, x2: UnwrapElementHandle<X2>) => R | Promise<R>,
88 x1: X1,
89 x2: X2,
90 ): Promise<WrapElementHandle<R>>;
91
92 /**
93 * This method runs `document.querySelector` within the context and passes it as the first argument to `pageFunction`.
94 * If there's no element matching `selector`, the method throws an error.
95 *
96 * If `pageFunction` returns a Promise, then `$eval` would wait for the promise to resolve and return its value.
97 *
98 * @param selector A selector to query for
99 * @param pageFunction Function to be evaluated in browser context
100 * @param x1 First argument to pass to pageFunction
101 * @param x2 Second argument to pass to pageFunction
102 * @param x3 Third argument to pass to pageFunction
103 * @returns Promise which resolves to the return value of pageFunction
104 */
105 $eval<R, X1, X2, X3>(
106 selector: string,
107 pageFunction: (
108 element: Element,
109 x1: UnwrapElementHandle<X1>,
110 x2: UnwrapElementHandle<X2>,
111 x3: UnwrapElementHandle<X3>,
112 ) => R | Promise<R>,
113 x1: X1,
114 x2: X2,
115 x3: X3,
116 ): Promise<WrapElementHandle<R>>;
117
118 /**
119 * This method runs `document.querySelector` within the context and passes it as the first argument to `pageFunction`.
120 * If there's no element matching `selector`, the method throws an error.
121 *
122 * If `pageFunction` returns a Promise, then `$eval` would wait for the promise to resolve and return its value.
123 *
124 * @param selector A selector to query for
125 * @param pageFunction Function to be evaluated in browser context
126 * @param args Arguments to pass to pageFunction
127 * @returns Promise which resolves to the return value of pageFunction
128 */
129 $eval<R>(
130 selector: string,
131 pageFunction: (element: Element, ...args: any[]) => R | Promise<R>,
132 ...args: SerializableOrJSHandle[]
133 ): Promise<WrapElementHandle<R>>;
134
135 /**
136 * This method runs `Array.from(document.querySelectorAll(selector))` within the context and passes it as the
137 * first argument to `pageFunction`.
138 *
139 * If `pageFunction` returns a Promise, then `$$eval` would wait for the promise to resolve and return its value.
140 *
141 * @param selector A selector to query for
142 * @param pageFunction Function to be evaluated in browser context
143 * @returns Promise which resolves to the return value of pageFunction
144 */
145 $$eval<R>(selector: string, pageFunction: (elements: Element[]) => R | Promise<R>): Promise<WrapElementHandle<R>>;
146
147 /**
148 * This method runs `Array.from(document.querySelectorAll(selector))` within the context and passes it as the
149 * first argument to `pageFunction`.
150 *
151 * If `pageFunction` returns a Promise, then `$$eval` would wait for the promise to resolve and return its value.
152 *
153 * @param selector A selector to query for
154 * @param pageFunction Function to be evaluated in browser context
155 * @param x1 First argument to pass to pageFunction
156 * @returns Promise which resolves to the return value of pageFunction
157 */
158 $$eval<R, X1>(
159 selector: string,
160 pageFunction: (elements: Element[], x1: UnwrapElementHandle<X1>) => R | Promise<R>,
161 x1: X1,
162 ): Promise<WrapElementHandle<R>>;
163
164 /**
165 * This method runs `Array.from(document.querySelectorAll(selector))` within the context and passes it as the
166 * first argument to `pageFunction`.
167 *
168 * If `pageFunction` returns a Promise, then `$$eval` would wait for the promise to resolve and return its value.
169 *
170 * @param selector A selector to query for
171 * @param pageFunction Function to be evaluated in browser context
172 * @param x1 First argument to pass to pageFunction
173 * @param x2 Second argument to pass to pageFunction
174 * @returns Promise which resolves to the return value of pageFunction
175 */
176 $$eval<R, X1, X2>(
177 selector: string,
178 pageFunction: (elements: Element[], x1: UnwrapElementHandle<X1>, x2: UnwrapElementHandle<X2>) => R | Promise<R>,
179 x1: X1,
180 x2: X2,
181 ): Promise<WrapElementHandle<R>>;
182
183 /**
184 * This method runs `Array.from(document.querySelectorAll(selector))` within the context and passes it as the
185 * first argument to `pageFunction`.
186 *
187 * If `pageFunction` returns a Promise, then `$$eval` would wait for the promise to resolve and return its value.
188 *
189 * @param selector A selector to query for
190 * @param pageFunction Function to be evaluated in browser context
191 * @param x1 First argument to pass to pageFunction
192 * @param x2 Second argument to pass to pageFunction
193 * @param x3 Third argument to pass to pageFunction
194 * @returns Promise which resolves to the return value of pageFunction
195 */
196 $$eval<R, X1, X2, X3>(
197 selector: string,
198 pageFunction: (
199 elements: Element[],
200 x1: UnwrapElementHandle<X1>,
201 x2: UnwrapElementHandle<X2>,
202 x3: UnwrapElementHandle<X3>,
203 ) => R | Promise<R>,
204 x1: X1,
205 x2: X2,
206 x3: X3,
207 ): Promise<WrapElementHandle<R>>;
208
209 /**
210 * This method runs `Array.from(document.querySelectorAll(selector))` within the context and passes it as the
211 * first argument to `pageFunction`.
212 *
213 * If `pageFunction` returns a Promise, then `$$eval` would wait for the promise to resolve and return its value.
214 *
215 * @param selector A selector to query for
216 * @param pageFunction Function to be evaluated in browser context
217 * @param args Arguments to pass to pageFunction
218 * @returns Promise which resolves to the return value of pageFunction
219 */
220 $$eval<R>(
221 selector: string,
222 pageFunction: (elements: Element[], ...args: any[]) => R | Promise<R>,
223 ...args: SerializableOrJSHandle[]
224 ): Promise<WrapElementHandle<R>>;
225}
226
227export interface JSEvalable<A = any> {
228 /**
229 * Evaluates a function in the browser context.
230 * If the function, passed to the frame.evaluate, returns a Promise, then frame.evaluate would wait for the promise to resolve and return its value.
231 * If the function passed into frame.evaluate returns a non-Serializable value, then frame.evaluate resolves to undefined.
232 * @param fn Function to be evaluated in browser context
233 * @param args Arguments to pass to `fn`
234 */
235 evaluate<T extends EvaluateFn<A>>(
236 pageFunction: T,
237 ...args: SerializableOrJSHandle[]
238 ): Promise<EvaluateFnReturnType<T> extends PromiseLike<infer U> ? U : EvaluateFnReturnType<T>>;
239 /**
240 * The only difference between `evaluate` and `evaluateHandle` is that `evaluateHandle` returns in-page object (`JSHandle`).
241 * If the function, passed to the `evaluateHandle`, returns a `Promise`, then `evaluateHandle` would wait for the
242 * promise to resolve and return its value.
243 * @param fn Function to be evaluated in browser context
244 * @param args Arguments to pass to `fn`
245 */
246 evaluateHandle(
247 pageFunction: string | ((arg1: A, ...args: any[]) => any),
248 ...args: SerializableOrJSHandle[]
249 ): Promise<JSHandle>;
250}
251
252/** Keyboard provides an api for managing a virtual keyboard. */
253export interface Keyboard {
254 /**
255 * Dispatches a keydown event.
256 * @param key Name of key to press, such as ArrowLeft.
257 * @param options Specifies a input text event.
258 */
259 down(key: string, options?: { text?: string | undefined }): Promise<void>;
260
261 /** Shortcut for `keyboard.down` and `keyboard.up`. */
262 press(key: string, options?: { text?: string | undefined; delay?: number | undefined }): Promise<void>;
263
264 /** Dispatches a `keypress` and `input` event. This does not send a `keydown` or keyup `event`. */
265 sendCharacter(char: string): Promise<void>;
266
267 /**
268 * Sends a keydown, keypress/input, and keyup event for each character in the text.
269 * @param text A text to type into a focused element.
270 * @param options Specifies the typing options.
271 */
272 type(text: string, options?: { delay?: number | undefined }): Promise<void>;
273
274 /**
275 * Dispatches a keyup event.
276 * @param key Name of key to release, such as ArrowLeft.
277 */
278 up(key: string): Promise<void>;
279}
280
281export interface MousePressOptions {
282 /**
283 * left, right, or middle.
284 * @default left
285 */
286 button?: MouseButtons | undefined;
287 /**
288 * The number of clicks.
289 * @default 1
290 */
291 clickCount?: number | undefined;
292}
293
294export interface Mouse {
295 /**
296 * Shortcut for `mouse.move`, `mouse.down` and `mouse.up`.
297 * @param x The x position.
298 * @param y The y position.
299 * @param options The click options.
300 */
301 click(x: number, y: number, options?: ClickOptions): Promise<void>;
302 /**
303 * Dispatches a `mousedown` event.
304 * @param options The mouse press options.
305 */
306 down(options?: MousePressOptions): Promise<void>;
307
308 /**
309 * Dispatches a `mousemove` event.
310 * @param x The x position.
311 * @param y The y position.
312 * @param options The mouse move options.
313 */
314 move(x: number, y: number, options?: { steps: number }): Promise<void>;
315 /**
316 * Dispatches a `mouseup` event.
317 * @param options The mouse press options.
318 */
319 up(options?: MousePressOptions): Promise<void>;
320}
321
322export interface Touchscreen {
323 /**
324 * Dispatches a touchstart and touchend event.
325 * @param x The x position.
326 * @param y The y position.
327 */
328 tap(x: number, y: number): Promise<void>;
329}
330/**
331 * You can use `tracing.start` and `tracing.stop` to create a trace file which can be opened in Chrome DevTools or timeline viewer.
332 */
333export interface Tracing {
334 start(options: TracingStartOptions): Promise<void>;
335 stop(): Promise<Buffer>;
336}
337
338export interface TracingStartOptions {
339 path?: string | undefined;
340 screenshots?: boolean | undefined;
341 categories?: string[] | undefined;
342}
343
344export type DialogType = 'alert' | 'beforeunload' | 'confirm' | 'prompt';
345
346/** Dialog objects are dispatched by page via the 'dialog' event. */
347export interface Dialog {
348 /**
349 * Accepts the dialog.
350 * @param promptText A text to enter in prompt. Does not cause any effects if the dialog's type is not prompt.
351 */
352 accept(promptText?: string): Promise<void>;
353
354 /** If dialog is prompt, returns default prompt value. Otherwise, returns empty string. */
355 defaultValue(): string;
356
357 /** Dismiss the dialog */
358 dismiss(): Promise<void>;
359
360 /** Returns the message displayed in the dialog. */
361 message(): string;
362
363 /** The dialog type. Dialog's type, can be one of `alert`, `beforeunload`, `confirm` or `prompt`. */
364 type(): DialogType;
365}
366
367export type ConsoleMessageType =
368 | 'log'
369 | 'debug'
370 | 'info'
371 | 'error'
372 | 'warning'
373 | 'dir'
374 | 'dirxml'
375 | 'table'
376 | 'trace'
377 | 'clear'
378 | 'startGroup'
379 | 'startGroupCollapsed'
380 | 'endGroup'
381 | 'assert'
382 | 'profile'
383 | 'profileEnd'
384 | 'count'
385 | 'timeEnd';
386
387export interface ConsoleMessageLocation {
388 /**
389 * URL of the resource if known.
390 */
391 url?: string | undefined;
392 /**
393 * Line number in the resource if known
394 */
395 lineNumber?: number | undefined;
396 /**
397 * Column number in the resource if known.
398 */
399 columnNumber?: number | undefined;
400}
401
402/** ConsoleMessage objects are dispatched by page via the 'console' event. */
403export interface ConsoleMessage {
404 /** The message arguments. */
405 args(): JSHandle[];
406 /** The location the message originated from */
407 location(): ConsoleMessageLocation;
408 /** The message text. */
409 text(): string;
410 type(): ConsoleMessageType;
411}
412
413export interface AuthOptions {
414 username: string;
415 password: string;
416}
417
418export type MouseButtons = 'left' | 'right' | 'middle';
419
420export interface ClickOptions {
421 /** @default MouseButtons.Left */
422 button?: MouseButtons | undefined;
423 /** @default 1 */
424 clickCount?: number | undefined;
425 /**
426 * Time to wait between mousedown and mouseup in milliseconds.
427 * @default 0
428 */
429 delay?: number | undefined;
430}
431
432export type SameSiteSetting = 'Strict' | 'Lax';
433
434/** Represents a browser cookie. */
435export interface Cookie {
436 /** The cookie name. */
437 name: string;
438 /** The cookie value. */
439 value: string;
440 /** The cookie domain. */
441 domain: string;
442 /** The cookie path. */
443 path: string;
444 /** The cookie Unix expiration time in seconds. */
445 expires: number;
446 /** The cookie size */
447 size: number;
448 /** The cookie http only flag. */
449 httpOnly: boolean;
450 /** The session cookie flag. */
451 session: boolean;
452 /** The cookie secure flag. */
453 secure: boolean;
454 /** The cookie same site definition. */
455 sameSite: SameSiteSetting;
456}
457
458export interface DeleteCookie {
459 /** The cookie name. */
460 name: string;
461 url?: string | undefined;
462 domain?: string | undefined;
463 path?: string | undefined;
464}
465
466export interface SetCookie {
467 /** The cookie name. */
468 name: string;
469 /** The cookie value. */
470 value: string;
471 /** The request-URI to associate with the setting of the cookie. This value can affect the default domain and path values of the created cookie. */
472 url?: string | undefined;
473 /** The cookie domain. */
474 domain?: string | undefined;
475 /** The cookie path. */
476 path?: string | undefined;
477 /** The cookie Unix expiration time in seconds. */
478 expires?: number | undefined;
479 /** The cookie http only flag. */
480 httpOnly?: boolean | undefined;
481 /** The session cookie flag. */
482 session?: boolean | undefined;
483 /** The cookie secure flag. */
484 secure?: boolean | undefined;
485 /** The cookie same site definition. */
486 sameSite?: SameSiteSetting | undefined;
487}
488
489export interface Viewport {
490 /** The page width in pixels. */
491 width: number;
492 /** The page height in pixels. */
493 height: number;
494 /**
495 * Specify device scale factor (can be thought of as dpr).
496 * @default 1
497 */
498 deviceScaleFactor?: number | undefined;
499 /**
500 * Whether the `meta viewport` tag is taken into account.
501 * @default false
502 */
503 isMobile?: boolean | undefined;
504 /**
505 * Specifies if viewport supports touch events.
506 * @default false
507 */
508 hasTouch?: boolean | undefined;
509 /**
510 * Specifies if viewport is in landscape mode.
511 * @default false
512 */
513 isLandscape?: boolean | undefined;
514}
515
516/** Page emulation options. */
517export interface EmulateOptions {
518 /** The viewport emulation options. */
519 viewport: Viewport;
520 /** The emulated user-agent. */
521 userAgent: string;
522}
523
524export type EvaluateFn<T = any> = string | ((arg1: T, ...args: any[]) => any);
525export type EvaluateFnReturnType<T extends EvaluateFn> = T extends (...args: any[]) => infer R ? R : unknown;
526
527export type LoadEvent = 'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2';
528
529export interface Timeoutable {
530 /**
531 * Maximum navigation time in milliseconds, pass 0 to disable timeout.
532 * @default 30000
533 */
534 timeout?: number | undefined;
535}
536
537/** The navigation options. */
538export interface NavigationOptions extends Timeoutable {
539 /**
540 * When to consider navigation succeeded.
541 * @default load Navigation is consider when the `load` event is fired.
542 */
543 waitUntil?: LoadEvent | LoadEvent[] | undefined;
544}
545
546/**
547 * Navigation options for `page.goto`.
548 */
549export interface DirectNavigationOptions extends NavigationOptions {
550 /**
551 * Referer header value.
552 * If provided it will take preference over the referer header value set by
553 * [page.setExtraHTTPHeaders()](#pagesetextrahttpheadersheaders).
554 */
555 referer?: string | undefined;
556}
557
558/** Accepts values labeled with units. If number, treat as pixels. */
559export type LayoutDimension = string | number;
560
561export type PDFFormat = 'Letter' | 'Legal' | 'Tabloid' | 'Ledger' | 'A0' | 'A1' | 'A2' | 'A3' | 'A4' | 'A5' | 'A6';
562
563export interface PDFOptions {
564 /**
565 * The file path to save the PDF to.
566 * If `path` is a relative path, then it is resolved relative to current working directory.
567 * If no path is provided, the PDF won't be saved to the disk.
568 */
569 path?: string | undefined;
570 /**
571 * Scale of the webpage rendering.
572 * @default 1
573 */
574 scale?: number | undefined;
575 /**
576 * Display header and footer.
577 * @default false
578 */
579 displayHeaderFooter?: boolean | undefined;
580 /**
581 * HTML template for the print header. Should be valid HTML markup with following classes used to inject printing values into them:
582 * - `date` formatted print date
583 * - `title` document title
584 * - `url` document location
585 * - `pageNumber` current page number
586 * - `totalPages` total pages in the document
587 */
588 headerTemplate?: string | undefined;
589 /**
590 * HTML template for the print footer. Should be valid HTML markup with following classes used to inject printing values into them:
591 * - `date` formatted print date
592 * - `title` document title
593 * - `url` document location
594 * - `pageNumber` current page number
595 * - `totalPages` total pages in the document
596 */
597 footerTemplate?: string | undefined;
598 /**
599 * Print background graphics.
600 * @default false
601 */
602 printBackground?: boolean | undefined;
603 /**
604 * Paper orientation.
605 * @default false
606 */
607 landscape?: boolean | undefined;
608 /**
609 * Paper ranges to print, e.g., '1-5, 8, 11-13'.
610 * @default '' which means print all pages.
611 */
612 pageRanges?: string | undefined;
613 /**
614 * Paper format. If set, takes priority over width or height options.
615 * @default 'Letter'
616 */
617 format?: PDFFormat | undefined;
618 /** Paper width. */
619 width?: LayoutDimension | undefined;
620 /** Paper height. */
621 height?: LayoutDimension | undefined;
622 /** Paper margins, defaults to none. */
623 margin?: {
624 /** Top margin. */
625 top?: LayoutDimension | undefined;
626 /** Right margin. */
627 right?: LayoutDimension | undefined;
628 /** Bottom margin. */
629 bottom?: LayoutDimension | undefined;
630 /** Left margin. */
631 left?: LayoutDimension | undefined;
632 } | undefined;
633 /**
634 * Give any CSS @page size declared in the page priority over what is declared in width and
635 * height or format options.
636 * @default false which will scale the content to fit the paper size.
637 */
638 preferCSSPageSize?: boolean | undefined;
639}
640
641/** Defines the screenshot options. */
642export interface ScreenshotOptions {
643 /**
644 * The file path to save the image to. The screenshot type will be inferred from file extension.
645 * If `path` is a relative path, then it is resolved relative to current working directory.
646 * If no path is provided, the image won't be saved to the disk.
647 */
648 path?: string | undefined;
649 /**
650 * The screenshot type.
651 * @default png
652 */
653 type?: 'jpeg' | 'png' | undefined;
654 /** The quality of the image, between 0-100. Not applicable to png images. */
655 quality?: number | undefined;
656 /**
657 * When true, takes a screenshot of the full scrollable page.
658 * @default false
659 */
660 fullPage?: boolean | undefined;
661 /**
662 * An object which specifies clipping region of the page.
663 */
664 clip?: BoundingBox | undefined;
665 /**
666 * Hides default white background and allows capturing screenshots with transparency.
667 * @default false
668 */
669 omitBackground?: boolean | undefined;
670 /**
671 * The encoding of the image, can be either base64 or binary.
672 * @default binary
673 */
674 encoding?: 'base64' | 'binary' | undefined;
675}
676
677export interface BinaryScreenShotOptions extends ScreenshotOptions {
678 encoding?: 'binary' | undefined;
679}
680
681export interface Base64ScreenShotOptions extends ScreenshotOptions {
682 encoding: 'base64';
683}
684
685/** Options for `addStyleTag` */
686export interface StyleTagOptions {
687 /** Url of the <link> tag. */
688 url?: string | undefined;
689 /** Path to the CSS file to be injected into frame. If `path` is a relative path, then it is resolved relative to current working directory. */
690 path?: string | undefined;
691 /** Raw CSS content to be injected into frame. */
692 content?: string | undefined;
693}
694/** Options for `addScriptTag` */
695export interface ScriptTagOptions {
696 /** Url of a script to be added. */
697 url?: string | undefined;
698 /** Path to the JavaScript file to be injected into frame. If `path` is a relative path, then it is resolved relative to current working directory. */
699 path?: string | undefined;
700 /** Raw JavaScript content to be injected into frame. */
701 content?: string | undefined;
702 /** Script type. Use 'module' in order to load a Javascript ES6 module. */
703 type?: string | undefined;
704}
705
706export interface PageFnOptions extends Timeoutable {
707 polling?: 'raf' | 'mutation' | number | undefined;
708}
709
710export interface BoundingBox {
711 /** The x-coordinate of top-left corner. */
712 x: number;
713 /** The y-coordinate of top-left corner. */
714 y: number;
715 /** The width. */
716 width: number;
717 /** The height. */
718 height: number;
719}
720
721export interface BoxModel {
722 /** Content box, represented as an array of {x, y} points. */
723 content: Box[];
724 /** Padding box, represented as an array of {x, y} points. */
725 padding: Box[];
726 /** Border box, represented as an array of {x, y} points. */
727 border: Box[];
728 /** Margin box, represented as an array of {x, y} points. */
729 margin: Box[];
730 width: number;
731 height: number;
732}
733
734export interface Box {
735 x: number;
736 y: number;
737}
738
739/**
740 * The Worker class represents a WebWorker.
741 * The events workercreated and workerdestroyed are emitted on the page object to signal the worker lifecycle.
742 */
743export interface Worker extends JSEvalable {
744 executionContext(): Promise<ExecutionContext>;
745
746 url(): string;
747}
748
749/**
750 * Represents an in-page DOM element. ElementHandles can be created with the page.$ method.
751 */
752export interface ElementHandle<E extends Element = Element> extends JSHandle<E>, Evalable {
753 /**
754 * The method runs element.querySelector within the page.
755 * If no element matches the selector, the return value resolve to null.
756 * @param selector A selector to query element for
757 * @since 0.13.0
758 */
759 $(selector: string): Promise<ElementHandle | null>;
760
761 /**
762 * The method runs element.querySelectorAll within the page.
763 * If no elements match the selector, the return value resolve to [].
764 * @param selector A selector to query element for
765 * @since 0.13.0
766 */
767 $$(selector: string): Promise<ElementHandle[]>;
768
769 /**
770 * @param selector XPath expression to evaluate.
771 */
772 $x(expression: string): Promise<ElementHandle[]>;
773 /**
774 * This method returns the value resolve to the bounding box of the element (relative to the main frame), or null if the element is not visible.
775 */
776 boundingBox(): Promise<BoundingBox | null>;
777 /**
778 * This method returns boxes of the element, or null if the element is not visible.
779 * Boxes are represented as an array of points; each Point is an object {x, y}. Box points are sorted clock-wise.
780 */
781 boxModel(): Promise<BoxModel | null>;
782 /**
783 * This method scrolls element into view if needed, and then uses page.mouse to click in the center of the element.
784 * If the element is detached from DOM, the method throws an error.
785 * @param options Specifies the options.
786 * @since 0.9.0
787 */
788 click(options?: ClickOptions): Promise<void>;
789 /**
790 * @returns Resolves to the content frame for element handles referencing iframe nodes, or null otherwise.
791 * @since 1.2.0
792 */
793 contentFrame(): Promise<Frame | null>;
794 /**
795 * Calls focus on the element.
796 */
797 focus(): Promise<void>;
798 /**
799 * This method scrolls element into view if needed, and then uses page.mouse to hover over the center of the element.
800 * If the element is detached from DOM, the method throws an error.
801 */
802 hover(): Promise<void>;
803 /**
804 * Resolves to true if the element is visible in the current viewport.
805 */
806 isIntersectingViewport(): Promise<boolean>;
807 /**
808 * Focuses the element, and then uses keyboard.down and keyboard.up.
809 * @param key Name of key to press, such as ArrowLeft. See USKeyboardLayout for a list of all key names.
810 * @param options The text and delay options.
811 */
812 press(key: string, options?: { text?: string | undefined; delay?: number | undefined }): Promise<void>;
813 /**
814 * This method scrolls element into view if needed, and then uses page.screenshot to take a screenshot of the element.
815 * If the element is detached from DOM, the method throws an error.
816 * @param options Same options as in page.screenshot.
817 */
818 screenshot(options?: Base64ScreenShotOptions): Promise<string>;
819 screenshot(options?: BinaryScreenShotOptions): Promise<Buffer>;
820 screenshot(options?: ScreenshotOptions): Promise<string | Buffer>;
821 /**
822 * Triggers a change and input event once all the provided options have been selected. If there's no <select> element
823 * matching selector, the method throws an error.
824 * @param values Values of options to select. If the <select> has the multiple attribute, all values are considered, otherwise only the first one is taken into account.
825 * @returns An array of option values that have been successfully selected.
826 * @since 1.12.0
827 */
828 select(...values: string[]): Promise<string[]>;
829 /**
830 * This method scrolls element into view if needed, and then uses touchscreen.tap to tap in the center of the element.
831 * If the element is detached from DOM, the method throws an error.
832 */
833 tap(): Promise<void>;
834 toString(): string;
835 /**
836 * Focuses the element, and then sends a keydown, keypress/input, and keyup event for each character in the text.
837 * @param text A text to type into a focused element.
838 * @param options The typing options.
839 */
840 type(text: string, options?: { delay: number }): Promise<void>;
841 /**
842 * This method expects elementHandle to point to an input element.
843 * @param filePaths Sets the value of the file input these paths. If some of the filePaths are relative paths, then they are resolved relative to current working directory.
844 */
845 uploadFile(...filePaths: string[]): Promise<void>;
846}
847
848/** The class represents a context for JavaScript execution. */
849export interface ExecutionContext extends JSEvalable {
850 queryObjects(prototypeHandle: JSHandle): Promise<JSHandle>;
851}
852
853/** JSHandle represents an in-page JavaScript object. */
854export interface JSHandle<T = any> extends JSEvalable<T> {
855 /**
856 * Returns a ElementHandle
857 */
858 asElement(): ElementHandle | null;
859 /**
860 * Stops referencing the element handle.
861 */
862 dispose(): Promise<void>;
863 /**
864 * Gets the execution context.
865 */
866 executionContext(): ExecutionContext;
867 /**
868 * Returns a map with property names as keys and JSHandle instances for the property values.
869 */
870 getProperties(): Promise<Map<string, JSHandle>>;
871 /**
872 * Fetches a single property from the objectHandle.
873 * @param propertyName The property to get.
874 */
875 getProperty(propertyName: string): Promise<JSHandle>;
876
877 /**
878 * Returns a JSON representation of the object.
879 * The JSON is generated by running JSON.stringify on the object in page and consequent JSON.parse in puppeteer.
880 * @throws The method will throw if the referenced object is not stringifiable.
881 */
882 jsonValue(): Promise<unknown>;
883}
884
885export interface Metrics {
886 /** The timestamp when the metrics sample was taken. */
887 Timestamp: number;
888 /** Number of documents in the page. */
889 Documents: number;
890 /** Number of frames in the page. */
891 Frames: number;
892 /** Number of events in the page. */
893 JSEventListeners: number;
894 /** Number of DOM nodes in the page. */
895 Nodes: number;
896 /** Total number of full or partial page layout. */
897 LayoutCount: number;
898 /** Total number of page style recalculations. */
899 RecalcStyleCount: number;
900 /** Combined durations of all page layouts. */
901 LayoutDuration: number;
902 /** Combined duration of all page style recalculations. */
903 RecalcStyleDuration: number;
904 /** Combined duration of JavaScript execution. */
905 ScriptDuration: number;
906 /** Combined duration of all tasks performed by the browser. */
907 TaskDuration: number;
908 /** Used JavaScript heap size. */
909 JSHeapUsedSize: number;
910 /** Total JavaScript heap size. */
911 JSHeapTotalSize: number;
912}
913
914export type Headers = Record<string, string>;
915export type HttpMethod = 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE' | 'OPTIONS';
916
917export type ResourceType =
918 | 'document'
919 | 'stylesheet'
920 | 'image'
921 | 'media'
922 | 'font'
923 | 'script'
924 | 'texttrack'
925 | 'xhr'
926 | 'fetch'
927 | 'eventsource'
928 | 'websocket'
929 | 'manifest'
930 | 'other';
931
932export type ErrorCode =
933 | 'aborted'
934 | 'accessdenied'
935 | 'addressunreachable'
936 | 'blockedbyclient'
937 | 'blockedbyresponse'
938 | 'connectionaborted'
939 | 'connectionclosed'
940 | 'connectionfailed'
941 | 'connectionrefused'
942 | 'connectionreset'
943 | 'internetdisconnected'
944 | 'namenotresolved'
945 | 'timedout'
946 | 'failed';
947
948export interface Overrides {
949 url?: string | undefined;
950 method?: HttpMethod | undefined;
951 postData?: string | undefined;
952 headers?: Headers | undefined;
953}
954
955/** Represents a page request. */
956export interface Request {
957 /**
958 * Aborts request.
959 * To use this, request interception should be enabled with `page.setRequestInterception`.
960 * @throws An exception is immediately thrown if the request interception is not enabled.
961 */
962 abort(errorCode?: ErrorCode): Promise<void>;
963
964 /**
965 * Continues request with optional request overrides.
966 * To use this, request interception should be enabled with `page.setRequestInterception`.
967 * @throws An exception is immediately thrown if the request interception is not enabled.
968 */
969 continue(overrides?: Overrides): Promise<void>;
970
971 /**
972 * @returns An object if the request failed, null otherwise.
973 */
974 failure(): { errorText: string } | null;
975
976 /**
977 * @returns The `Frame` object that initiated the request, or `null` if navigating to error pages
978 */
979 frame(): Frame | null;
980
981 /**
982 * An object with HTTP headers associated with the request.
983 * All header names are lower-case.
984 */
985 headers(): Headers;
986
987 /** Whether this request is driving frame's navigation. */
988 isNavigationRequest(): boolean;
989
990 /** Returns the request's method (GET, POST, etc.) */
991
992 method(): HttpMethod;
993
994 /** Contains the request's post body, if any. */
995 postData(): string | undefined;
996
997 /**
998 * A `redirectChain` is a chain of requests initiated to fetch a resource.
999 *
1000 * - If there are no redirects and the request was successful, the chain will be empty.
1001 * - If a server responds with at least a single redirect, then the chain will contain all the requests that were redirected.
1002 *
1003 * `redirectChain` is shared between all the requests of the same chain.
1004 *
1005 * @since 1.2.0
1006 */
1007 redirectChain(): Request[];
1008
1009 /** Contains the request's resource type as it was perceived by the rendering engine. */
1010 resourceType(): ResourceType;
1011
1012 /**
1013 * Fulfills request with given response.
1014 * To use this, request interception should be enabled with `page.setRequestInterception`.
1015 * @throws An exception is immediately thrown if the request interception is not enabled.
1016 * @param response The response options that will fulfill this request.
1017 */
1018 respond(response: RespondOptions): Promise<void>;
1019
1020 /** A matching `Response` object, or `null` if the response has not been received yet. */
1021 response(): Response | null;
1022
1023 /** Contains the URL of the request. */
1024 url(): string;
1025}
1026/** Options for `Request.respond` method */
1027export interface RespondOptions {
1028 /**
1029 * Specifies the response status code.
1030 * @default 200
1031 */
1032 status?: number | undefined;
1033 /** Specifies the response headers. */
1034 headers?: Headers | undefined;
1035 /** Specifies the Content-Type response header. */
1036 contentType?: string | undefined;
1037 /** Specifies the response body. */
1038 body?: Buffer | string | undefined;
1039}
1040
1041export interface RemoteInfo {
1042 /** the IP address of the remote server */
1043 ip: string;
1044 /** the port used to connect to the remote server */
1045 port: number;
1046}
1047
1048export interface SecurityDetails {
1049 /** A string with the name of issuer of the certificate. (e.g. "Let's Encrypt Authority X3"). */
1050 issuer(): string;
1051 /** String with the security protocol (e.g. TLS 1.2). */
1052 protocol(): string;
1053 /** Name of the subject to which the certificate was issued to (e.g. "www.example.com"). */
1054 subjectName(): string;
1055 /** Timestamp stating the start of validity of the certificate. */
1056 validFrom(): number;
1057 /** Timestamp stating the end of validity of the certificate. */
1058 validTo(): number;
1059}
1060
1061/** Response class represents responses which are received by page. */
1062export interface Response {
1063 /** Promise which resolves to a buffer with response body. */
1064 buffer(): Promise<Buffer>;
1065 /** A Frame that initiated this response, or null if navigating to error pages. */
1066 frame(): Frame | null;
1067 /** True if the response was served from either the browser's disk cache or memory cache. */
1068 fromCache(): boolean;
1069 /** True if the response was served by a service worker. */
1070 fromServiceWorker(): boolean;
1071 /** An object with HTTP headers associated with the response. All header names are lower-case. */
1072 headers(): Headers;
1073 /**
1074 * Promise which resolves to a JSON representation of response body.
1075 * @throws This method will throw if the response body is not parsable via `JSON.parse`.
1076 */
1077 json(): Promise<unknown>;
1078 /** Contains a boolean stating whether the response was successful (status in the range 200-299) or not. */
1079 ok(): boolean;
1080 /** Returns remote connection info */
1081 remoteAddress(): RemoteInfo;
1082 /** Returns an object with security details associated with the response. */
1083 securityDetails(): SecurityDetails | null;
1084 /** A matching Request object. */
1085 request(): Request;
1086 /** Contains the status code of the response (e.g., 200 for a success). */
1087 status(): number;
1088 /** Contains the status text of the response (e.g. usually an "OK" for a success). */
1089 statusText(): string;
1090 /** Promise which resolves to a text representation of response body. */
1091 text(): Promise<string>;
1092 /** Contains the URL of the response. */
1093 url(): string;
1094}
1095
1096export interface WaitForSelectorOptions extends Timeoutable {
1097 /**
1098 * Wait for element to be present in DOM and to be visible,
1099 * i.e. to not have display: none or visibility: hidden CSS properties.
1100 * @default false
1101 */
1102 visible?: boolean | undefined;
1103 /**
1104 * Wait for element to not be found in the DOM or to be hidden,
1105 * i.e. have display: none or visibility: hidden CSS properties.
1106 * @default false
1107 */
1108 hidden?: boolean | undefined;
1109}
1110
1111export interface WaitForSelectorOptionsHidden extends WaitForSelectorOptions {
1112 hidden: true;
1113}
1114
1115export interface FrameBase extends Evalable, JSEvalable {
1116 /**
1117 * The method queries frame for the selector.
1118 * If there's no such element within the frame, the method will resolve to null.
1119 */
1120 $(selector: string): Promise<ElementHandle | null>;
1121
1122 /**
1123 * The method runs document.querySelectorAll within the frame.
1124 * If no elements match the selector, the return value resolve to [].
1125 */
1126 $$(selector: string): Promise<ElementHandle[]>;
1127
1128 /**
1129 * The method evaluates the XPath expression.
1130 * @param expression XPath expression to evaluate.
1131 */
1132 $x(expression: string): Promise<ElementHandle[]>;
1133
1134 /** Adds a `<script>` tag into the page with the desired url or content. */
1135 addScriptTag(options: ScriptTagOptions): Promise<void>;
1136
1137 /** Adds a `<link rel="stylesheet">` tag into the page with the desired url or a `<style type="text/css">` tag with the content. */
1138 addStyleTag(options: StyleTagOptions): Promise<void>;
1139
1140 /**
1141 * This method fetches an element with selector, scrolls it into view if needed, and
1142 * then uses `page.mouse` to click in the center of the element. If there's no element
1143 * matching selector, the method throws an error.
1144 * @param selector A selector to search for element to click. If there are multiple elements satisfying the selector, the first will be clicked.
1145 * @param options Specifies the click options.
1146 */
1147 click(selector: string, options?: ClickOptions): Promise<void>;
1148
1149 /** Gets the full HTML contents of the page, including the doctype. */
1150 content(): Promise<string>;
1151
1152 /**
1153 * Navigates to a URL.
1154 * @param url URL to navigate page to. The url should include scheme, e.g. `https://`
1155 * @param options The navigation parameters.
1156 */
1157 goto(url: string, options?: DirectNavigationOptions): Promise<Response | null>;
1158
1159 /** This method fetches an element with selector and focuses it. */
1160 focus(selector: string): Promise<void>;
1161
1162 /**
1163 * This method fetches an element with `selector`, scrolls it into view if needed,
1164 * and then uses page.mouse to hover over the center of the element. If there's no
1165 * element matching `selector`, the method throws an error.
1166 * @param selector A selector to search for element to hover. If there are multiple elements satisfying the selector, the first will be hovered.
1167 */
1168 hover(selector: string): Promise<void>;
1169
1170 /**
1171 * Triggers a `change` and `input` event once all the provided options have been selected.
1172 * If there's no `<select>` element matching selector, the method throws an error.
1173 * @param selector A selector to query page for.
1174 * @param values Values of options to select. If the `<select>` has the `multiple` attribute,
1175 * all values are considered, otherwise only the first one is taken into account.
1176 */
1177 select(selector: string, ...values: string[]): Promise<string[]>;
1178
1179 /**
1180 * Sets the page content.
1181 * @param html HTML markup to assign to the page.
1182 * @param options The navigation parameters.
1183 */
1184 setContent(html: string, options?: NavigationOptions): Promise<void>;
1185
1186 /**
1187 * This method fetches an element with `selector`, scrolls it into view if needed,
1188 * and then uses page.touchscreen to tap in the center of the element.
1189 * @param selector A `selector` to search for element to tap. If there are multiple elements
1190 * satisfying the selector, the first will be tapped.
1191 */
1192 tap(selector: string): Promise<void>;
1193
1194 /** Returns page's title. */
1195 title(): Promise<string>;
1196
1197 /**
1198 * Sends a `keydown`, `keypress/input`, and `keyup` event for each character in the text.
1199 * @param selector A selector of an element to type into. If there are multiple elements satisfying the selector, the first will be used.
1200 * @param text: A text to type into a focused element.
1201 * @param options: The typing parameters.
1202 */
1203 type(selector: string, text: string, options?: { delay: number }): Promise<void>;
1204
1205 /** Returns frame's url. */
1206 url(): string;
1207
1208 /**
1209 * Waits for a certain amount of time before resolving.
1210 * @param duration The time to wait for.
1211 */
1212 waitFor(duration: number): Promise<void>;
1213 /**
1214 * Shortcut for waitForSelector and waitForXPath
1215 */
1216 waitFor(selector: string, options: WaitForSelectorOptionsHidden): Promise<ElementHandle | null>;
1217 waitFor(selector: string, options?: WaitForSelectorOptions): Promise<ElementHandle>;
1218
1219 /**
1220 * Shortcut for waitForFunction.
1221 */
1222 waitFor(
1223 selector: EvaluateFn,
1224 options?: WaitForSelectorOptions,
1225 ...args: SerializableOrJSHandle[]
1226 ): Promise<JSHandle>;
1227
1228 /**
1229 * Allows waiting for various conditions.
1230 */
1231 waitForFunction(fn: EvaluateFn, options?: PageFnOptions, ...args: SerializableOrJSHandle[]): Promise<JSHandle>;
1232
1233 /**
1234 * Wait for the page navigation occur.
1235 * @param options The navigation parameters.
1236 */
1237 waitForNavigation(options?: NavigationOptions): Promise<Response>;
1238
1239 waitForSelector(selector: string, options?: WaitForSelectorOptions): Promise<ElementHandle>;
1240 waitForSelector(selector: string, options?: WaitForSelectorOptionsHidden): Promise<ElementHandle | null>;
1241
1242 waitForXPath(xpath: string, options?: WaitForSelectorOptions): Promise<ElementHandle>;
1243}
1244
1245export interface Frame extends FrameBase {
1246 childFrames(): Frame[];
1247 /** Execution context associated with this frame. */
1248 executionContext(): Promise<ExecutionContext>;
1249 /** Returns `true` if the frame has been detached, or `false` otherwise. */
1250 isDetached(): boolean;
1251 /** Returns frame's name attribute as specified in the tag. */
1252 name(): string;
1253 /** Returns parent frame, if any. Detached frames and main frames return null. */
1254 parentFrame(): Frame | null;
1255}
1256
1257export interface PageEventObj {
1258 /** Emitted when the page closes. */
1259 close: undefined;
1260 /**
1261 * Emitted when JavaScript within the page calls one of console API methods, e.g. console.log or console.dir.
1262 * Also emitted if the page throws an error or a warning.
1263 */
1264 console: ConsoleMessage;
1265 /**
1266 * Emitted when a JavaScript dialog appears, such as alert, prompt, confirm or beforeunload.
1267 * Puppeteer can respond to the dialog via Dialog's accept or dismiss methods.
1268 */
1269 dialog: Dialog;
1270 /**
1271 * Emitted when the initial HTML document has been completely loaded and parsed,
1272 * without waiting for stylesheets, images, and subframes to finish loading.
1273 */
1274 domcontentloaded: never;
1275 /** Emitted when the page crashes. */
1276 error: Error;
1277 /** Emitted when a frame is attached. */
1278 frameattached: Frame;
1279 /** Emitted when a frame is detached. */
1280 framedetached: Frame;
1281 /** Emitted when a frame is navigated to a new url. */
1282 framenavigated: Frame;
1283 /** Emitted when the JavaScript load event is dispatched. */
1284 load: undefined;
1285 /**
1286 * Emitted when the JavaScript code makes a call to `console.timeStamp`.
1287 * For the list of metrics see `page.metrics`.
1288 */
1289 metrics: { title: string; metrics: Metrics };
1290 /** Emitted when an uncaught exception happens within the page. */
1291 pageerror: Error;
1292 /** Emitted when the page opens a new tab or window. */
1293 popup: Page;
1294 /**
1295 * Emitted when a page issues a request. The request object is read-only.
1296 * In order to intercept and mutate requests, see page.setRequestInterceptionEnabled.
1297 */
1298 request: Request;
1299 /** Emitted when a request fails, for example by timing out. */
1300 requestfailed: Request;
1301 /** Emitted when a request finishes successfully. */
1302 requestfinished: Request;
1303 /** Emitted when a response is received. */
1304 response: Response;
1305 /** Emitted when a dedicated WebWorker is spawned by the page. */
1306 workercreated: Worker;
1307 /** Emitted when a dedicated WebWorker is terminated. */
1308 workerdestroyed: Worker;
1309}
1310
1311export interface PageCloseOptions {
1312 /**
1313 * Whether to run the before unload page handlers.
1314 * @default false
1315 */
1316 runBeforeUnload?: boolean | undefined;
1317}
1318
1319export interface GeoOptions {
1320 /**
1321 * Latitude between -90 and 90.
1322 */
1323 latitude: number;
1324 /**
1325 * Longitude between -180 and 180.
1326 */
1327 longitude: number;
1328 /**
1329 * Non-negative accuracy value.
1330 */
1331 accuracy?: number | undefined;
1332}
1333
1334export type MediaType = 'screen' | 'print';
1335
1336export interface AXNode {
1337 /**
1338 * The role.
1339 */
1340 role: string;
1341 /**
1342 * A human readable name for the node.
1343 */
1344 name: string;
1345 /**
1346 * The current value of the node.
1347 */
1348 value: string | number;
1349 /**
1350 * An additional human readable description of the node.
1351 */
1352 description: string;
1353 /**
1354 * Keyboard shortcuts associated with this node.
1355 */
1356 keyshortcuts: string;
1357 /**
1358 * A human readable alternative to the role.
1359 */
1360 roledescription: string;
1361 /**
1362 * A description of the current value.
1363 */
1364 valuetext: string;
1365 /**
1366 * Whether the node is disabled.
1367 */
1368 disabled: boolean;
1369 /**
1370 * Whether the node is expanded or collapsed.
1371 */
1372 expanded: boolean;
1373 /**
1374 * Whether the node is focused.
1375 */
1376 focused: boolean;
1377 /**
1378 * Whether the node is modal.
1379 */
1380 modal: boolean;
1381 /**
1382 * Whether the node text input supports multiline.
1383 */
1384 multiline: boolean;
1385 /**
1386 * Whether more than one child can be selected.
1387 */
1388 multiselectable: boolean;
1389 /**
1390 * Whether the node is read only.
1391 */
1392 readonly: boolean;
1393 /**
1394 * Whether the node is required.
1395 */
1396 required: boolean;
1397 /**
1398 * Whether the node is selected in its parent node.
1399 */
1400 selected: boolean;
1401 /**
1402 * Whether the checkbox is checked, or "mixed".
1403 */
1404 checked: boolean | 'mixed';
1405 /**
1406 * Whether the toggle button is checked, or "mixed".
1407 */
1408 pressed: boolean | 'mixed';
1409 /**
1410 * The level of a heading.
1411 */
1412 level: number;
1413 /**
1414 * The minimum value in a node.
1415 */
1416 valuemin: number;
1417 /**
1418 * The maximum value in a node.
1419 */
1420 valuemax: number;
1421 /**
1422 * What kind of autocomplete is supported by a control.
1423 */
1424 autocomplete: string;
1425 /**
1426 * What kind of popup is currently being shown for a node.
1427 */
1428 haspopup: string;
1429 /**
1430 * Whether and in what way this node's value is invalid.
1431 */
1432 invalid: string;
1433 /**
1434 * Whether the node is oriented horizontally or vertically.
1435 */
1436 orientation: string;
1437 /**
1438 * Child nodes of this node, if any.
1439 */
1440 children: AXNode[];
1441}
1442
1443export interface SnapshopOptions {
1444 /**
1445 * Prune uninteresting nodes from the tree.
1446 * @default true
1447 */
1448 interestingOnly?: boolean | undefined;
1449 /**
1450 * The root DOM element for the snapshot.
1451 * @default document.body
1452 */
1453 root?: ElementHandle | undefined;
1454}
1455
1456/**
1457 * The Accessibility class provides methods for inspecting Chromium's accessibility tree.
1458 * The accessibility tree is used by assistive technology such as screen readers.
1459 * Accessibility is a very platform-specific thing. On different platforms,
1460 * there are different screen readers that might have wildly different output.
1461 * Blink - Chrome's rendering engine - has a concept of "accessibility tree",
1462 * which is than translated into different platform-specific APIs.
1463 * Accessibility namespace gives users access to the Blink Accessibility Tree.
1464 * Most of the accessibility tree gets filtered out when converting from Blink AX Tree to Platform-specific AX-Tree or
1465 * by screen readers themselves. By default, Puppeteer tries to approximate this filtering,
1466 * exposing only the "interesting" nodes of the tree.
1467 */
1468export interface Accessibility {
1469 snapshot(options?: SnapshopOptions): Promise<AXNode>;
1470}
1471
1472export interface MediaFeature {
1473 name: string;
1474 value: string;
1475}
1476
1477export interface FileChooser {
1478 /**
1479 * Accept the file chooser request with given paths.
1480 * If some of the filePaths are relative paths, then they are resolved relative to the current working directory.
1481 */
1482 accept(filePaths: string[]): Promise<void>;
1483 /** Closes the file chooser without selecting any files. */
1484 cancel(): Promise<void>;
1485 /** Whether file chooser allow for multiple file selection. */
1486 isMultiple(): boolean;
1487}
1488
1489/** Page provides methods to interact with a single tab in Chromium. One Browser instance might have multiple Page instances. */
1490export interface Page extends EventEmitter, FrameBase {
1491 /**
1492 * Adds the listener function to the end of the listeners array for the event named `eventName`.
1493 * No checks are made to see if the listener has already been added. Multiple calls passing the same combination of
1494 * `eventName` and listener will result in the listener being added, and called, multiple times.
1495 * @param event The name of the event.
1496 * @param handler The callback function.
1497 */
1498 on<K extends keyof PageEventObj>(eventName: K, handler: (e: PageEventObj[K], ...args: any[]) => void): this;
1499
1500 /**
1501 * Adds a one time listener function for the event named `eventName`.
1502 * The next time `eventName` is triggered, this listener is removed and then invoked.
1503 * @param event The name of the event.
1504 * @param handler The callback function.
1505 */
1506 once<K extends keyof PageEventObj>(eventName: K, handler: (e: PageEventObj[K], ...args: any[]) => void): this;
1507
1508 accessibility: Accessibility;
1509
1510 /**
1511 * Provide credentials for http authentication.
1512 * To disable authentication, pass `null`.
1513 */
1514 authenticate(credentials: AuthOptions | null): Promise<void>;
1515
1516 /** Brings page to front (activates tab). */
1517 bringToFront(): Promise<void>;
1518
1519 /** Get the browser the page belongs to. */
1520 browser(): Browser;
1521
1522 /** Get the browser context that the page belongs to. */
1523 browserContext(): BrowserContext;
1524
1525 /** Closes the current page. */
1526 close(options?: PageCloseOptions): Promise<void>;
1527
1528 /**
1529 * Gets the cookies.
1530 * If no URLs are specified, this method returns cookies for the current page URL.
1531 * If URLs are specified, only cookies for those URLs are returned.
1532 */
1533 cookies(...urls: string[]): Promise<Cookie[]>;
1534
1535 coverage: Coverage;
1536
1537 /**
1538 * Deletes the specified cookies.
1539 */
1540 deleteCookie(...cookies: DeleteCookie[]): Promise<void>;
1541
1542 /** Emulates given device metrics and user agent. This method is a shortcut for `setUserAgent` and `setViewport`. */
1543 emulate(options: EmulateOptions): Promise<void>;
1544
1545 /** Emulates the media. */
1546 emulateMediaType(mediaType: MediaType | null): Promise<void>;
1547
1548 /**
1549 * Given an array of media feature objects, emulates CSS media features on the page.
1550 * Passing null resets all.
1551 */
1552 emulateMediaFeatures(features: MediaFeature[] | null): Promise<void>;
1553
1554 /**
1555 * Changes the timezone of the page.
1556 * See ICUs [metaZones.txt](https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1) for a list of supported timezone IDs.
1557 * Passing null disables timezone emulation.
1558 */
1559 emulateTimezone(tz: string | null): Promise<void>;
1560
1561 /**
1562 * Adds a function which would be invoked in one of the following scenarios: whenever the page is navigated; whenever the child frame is attached or navigated.
1563 * The function is invoked after the document was created but before any of its scripts were run. This is useful to amend JavaScript environment, e.g. to seed Math.random.
1564 * @param fn The function to be evaluated in browser context.
1565 * @param args The arguments to pass to the `fn`.
1566 */
1567 evaluateOnNewDocument(fn: EvaluateFn, ...args: SerializableOrJSHandle[]): Promise<void>;
1568
1569 /**
1570 * The method adds a function called name on the page's `window` object.
1571 * When called, the function executes `puppeteerFunction` in node.js and returns a
1572 * Promise which resolves to the return value of `puppeteerFunction`.
1573 * @param name The name of the function on the window object.
1574 * @param fn Callback function which will be called in Puppeteer's context.
1575 */
1576 exposeFunction(name: string, puppeteerFunction: (...args: any[]) => any): Promise<void>;
1577
1578 /** An array of all frames attached to the page. */
1579 frames(): Frame[];
1580
1581 /**
1582 * Navigate to the previous page in history.
1583 * @param options The navigation parameters.
1584 */
1585 goBack(options?: NavigationOptions): Promise<Response | null>;
1586
1587 /**
1588 * Navigate to the next page in history.
1589 * @param options The navigation parameters.
1590 */
1591 goForward(options?: NavigationOptions): Promise<Response | null>;
1592
1593 /** Returns the virtual keyboard. */
1594 keyboard: Keyboard;
1595
1596 /** Indicates that the page has been closed. */
1597 isClosed(): boolean;
1598
1599 /**
1600 * @returns `true` if the page has JavaScript enabled, `false` otherwise.
1601 */
1602 isJavaScriptEnabled(): boolean;
1603
1604 /** Page is guaranteed to have a main frame which persists during navigation's. */
1605 mainFrame(): Frame;
1606
1607 /** Gets the page metrics. */
1608 metrics(): Promise<Metrics>;
1609
1610 /** Gets the virtual mouse. */
1611 mouse: Mouse;
1612
1613 /**
1614 * Generates a PDF of the page with `print` css media.
1615 * To generate a pdf with `screen` media, call `page.emulateMedia('screen')` before calling `page.pdf()`:
1616 * @param options The PDF parameters.
1617 */
1618 pdf(options?: PDFOptions): Promise<Buffer>;
1619
1620 /**
1621 * The method iterates JavaScript heap and finds all the objects with the given prototype.
1622 * @param prototypeHandle A handle to the object prototype.
1623 */
1624 queryObjects(prototypeHandle: JSHandle): Promise<JSHandle>;
1625
1626 /**
1627 * Reloads the current page.
1628 * @param options The navigation parameters.
1629 */
1630 reload(options?: NavigationOptions): Promise<Response>;
1631
1632 /**
1633 * Captures a screenshot of the page.
1634 * @param options The screenshot options.
1635 */
1636 screenshot(options?: Base64ScreenShotOptions): Promise<string>;
1637 screenshot(options?: BinaryScreenShotOptions): Promise<Buffer>;
1638 screenshot(options?: ScreenshotOptions): Promise<string | Buffer>;
1639
1640 /**
1641 * Toggles bypassing page's Content-Security-Policy.
1642 * NOTE CSP bypassing happens at the moment of CSP initialization rather then evaluation.
1643 * Usually this means that page.setBypassCSP should be called before navigating to the domain.
1644 * @param enabled sets bypassing of page's Content-Security-Policy.
1645 */
1646 setBypassCSP(enabled: boolean): Promise<void>;
1647
1648 /**
1649 * Determines whether cache is enabled on the page.
1650 * @param [enabled=true] Whether or not to enable cache on the page.
1651 */
1652 setCacheEnabled(enabled?: boolean): Promise<void>;
1653
1654 /**
1655 * Sets the cookies on the page.
1656 * @param cookies The cookies to set.
1657 */
1658 setCookie(...cookies: SetCookie[]): Promise<void>;
1659
1660 /**
1661 * This setting will change the default maximum navigation time of 30 seconds for the following methods:
1662 * - `page.goto`
1663 * - `page.goBack`
1664 * - `page.goForward`
1665 * - `page.reload`
1666 * - `page.waitForNavigation`
1667 */
1668 setDefaultNavigationTimeout(timeout: number): void;
1669
1670 /**
1671 * This setting will change the default maximum time for the following methods and related shortcuts:
1672 * - `page.goBack`
1673 * - `page.goForward`
1674 * - `page.goto`
1675 * - `page.reload`
1676 * - `page.setContent`
1677 * - `page.waitFor`
1678 * - `page.waitForFunction`
1679 * - `page.waitForNavigation`
1680 * - `page.waitForRequest`
1681 * - `page.waitForResponse`
1682 * - `page.waitForSelector`
1683 * - `page.waitForXPath`
1684 *
1685 * NOTE page.setDefaultNavigationTimeout takes priority over page.setDefaultTimeout
1686 */
1687 setDefaultTimeout(timeout: number): void;
1688
1689 /**
1690 * The extra HTTP headers will be sent with every request the page initiates.
1691 * @param headers An object containing additional http headers to be sent with every request. All header values must be strings.
1692 */
1693 setExtraHTTPHeaders(headers: Headers): Promise<void>;
1694
1695 /**
1696 * Sets the page's geolocation.
1697 */
1698 setGeolocation(options: GeoOptions): Promise<void>;
1699
1700 /**
1701 * Determines whether JavaScript is enabled on the page.
1702 * @param enable Whether or not to enable JavaScript on the page.
1703 */
1704 setJavaScriptEnabled(enabled: boolean): Promise<void>;
1705
1706 /**
1707 * Determines whether the offline mode is enabled.
1708 * @param enabled When `true`, enables the offline mode for the page.
1709 */
1710 setOfflineMode(enabled: boolean): Promise<void>;
1711
1712 /**
1713 * Determines whether the request interception is enabled.
1714 * @param enabled When `true` the methods `request.abort`, `request.continue` and `request.respond` must be used.
1715 */
1716 setRequestInterception(enabled: boolean): Promise<void>;
1717
1718 /**
1719 * Specifies the User-Agent used in this page.
1720 * @param userAgent The user-agent to be used in the page.
1721 */
1722 setUserAgent(userAgent: string): Promise<void>;
1723 /**
1724 * Sets the viewport of the page.
1725 * @param viewport The viewport parameters.
1726 */
1727 setViewport(viewport: Viewport): Promise<void>;
1728
1729 /** @returns The target this page was created from */
1730 target(): Target;
1731
1732 /** Returns the page's title. */
1733 title(): Promise<string>;
1734
1735 /** Returns the virtual touchscreen object. */
1736 touchscreen: Touchscreen;
1737
1738 /** Returns the tracing object. */
1739 tracing: Tracing;
1740
1741 /**
1742 * The page's URL. This is a shortcut for `page.mainFrame().url()`
1743 */
1744 url(): string;
1745
1746 /** Gets the page viewport. */
1747 viewport(): Viewport;
1748
1749 waitForRequest(urlOrPredicate: string | ((req: Request) => boolean), options?: Timeoutable): Promise<Request>;
1750
1751 waitForResponse(urlOrPredicate: string | ((res: Response) => boolean), options?: Timeoutable): Promise<Response>;
1752
1753 /**
1754 * In non-headless Chromium, this method results in the native file picker dialog not showing up for the user.
1755 * This method is typically coupled with an action that triggers file choosing.
1756 * This must be called before the file chooser is launched. It will not return a currently active file chooser.
1757 */
1758 waitForFileChooser(options?: Timeoutable): Promise<FileChooser>;
1759
1760 /** This method returns all of the dedicated WebWorkers associated with the page. */
1761 workers(): Worker[];
1762}
1763
1764export interface TargetAwaiter {
1765 waitForTarget(predicate: (target: Target) => boolean, options?: Timeoutable): Promise<Target>;
1766}
1767
1768/** A Browser is created when Puppeteer connects to a Chromium instance, either through puppeteer.launch or puppeteer.connect. */
1769export interface Browser extends EventEmitter, TargetAwaiter {
1770 /**
1771 * Adds the listener function to the end of the listeners array for the event named `eventName`.
1772 * No checks are made to see if the listener has already been added. Multiple calls passing the same combination of
1773 * `eventName` and listener will result in the listener being added, and called, multiple times.
1774 * @param event The name of the event.
1775 * @param handler The callback function.
1776 */
1777 on<K extends keyof BrowserEventObj>(eventName: K, handler: (e: BrowserEventObj[K], ...args: any[]) => void): this;
1778
1779 /**
1780 * Adds a one time listener function for the event named `eventName`.
1781 * The next time `eventName` is triggered, this listener is removed and then invoked.
1782 * @param event The name of the event.
1783 * @param handler The callback function.
1784 */
1785 once<K extends keyof BrowserEventObj>(eventName: K, handler: (e: BrowserEventObj[K], ...args: any[]) => void): this;
1786
1787 /**
1788 * Returns an array of all open browser contexts.
1789 * In a newly created browser, this will return a single instance of BrowserContext.
1790 */
1791 browserContexts(): BrowserContext[];
1792
1793 /**
1794 * Closes browser with all the pages (if any were opened).
1795 * The browser object itself is considered to be disposed and can not be used anymore.
1796 */
1797 close(): Promise<void>;
1798
1799 /**
1800 * Creates a new incognito browser context.
1801 * This won't share cookies/cache with other browser contexts.
1802 */
1803 createIncognitoBrowserContext(): Promise<BrowserContext>;
1804
1805 /**
1806 * Disconnects Puppeteer from the browser, but leaves the Chromium process running.
1807 * After calling `disconnect`, the browser object is considered disposed and cannot be used anymore.
1808 */
1809 disconnect(): void;
1810
1811 /** Indicates that the browser is connected. */
1812 isConnected(): boolean;
1813
1814 /**
1815 * Returns the default browser context.
1816 * The default browser context can not be closed.
1817 */
1818 defaultBrowserContext(): BrowserContext;
1819
1820 /** Promise which resolves to a new Page object. */
1821 newPage(): Promise<Page>;
1822
1823 /** Promise which resolves to an array of all open pages. */
1824 pages(): Promise<Page[]>;
1825
1826 /** Spawned browser process. Returns `null` if the browser instance was created with `puppeteer.connect` method */
1827 process(): ChildProcess;
1828
1829 /** A target associated with the browser. */
1830 target(): Target;
1831
1832 /** Promise which resolves to an array of all active targets. */
1833 targets(): Promise<Target[]>;
1834
1835 /**
1836 * Promise which resolves to the browser's original user agent.
1837 * **NOTE** Pages can override browser user agent with `page.setUserAgent`.
1838 */
1839 userAgent(): Promise<string>;
1840
1841 /** For headless Chromium, this is similar to HeadlessChrome/61.0.3153.0. For non-headless, this is similar to Chrome/61.0.3153.0. */
1842 version(): Promise<string>;
1843
1844 /** Browser websocket endpoint which can be used as an argument to puppeteer.connect. The format is ws://${host}:${port}/devtools/browser/<id> */
1845 wsEndpoint(): string;
1846}
1847
1848export interface BrowserEventObj {
1849 /** Emitted when puppeteer gets disconnected from the browser instance. */
1850 disconnected: undefined;
1851
1852 /** Emitted when the url of a target changes. */
1853 targetchanged: Target;
1854
1855 /** Emitted when a target is created, for example when a new page is opened by `window.open` or `browser.newPage`. */
1856 targetcreated: Target;
1857
1858 /** Emitted when a target is destroyed, for example when a page is closed. */
1859 targetdestroyed: Target;
1860}
1861
1862export type Permission =
1863 | 'geolocation'
1864 | 'midi'
1865 | 'midi-sysex'
1866 | 'notifications'
1867 | 'push'
1868 | 'camera'
1869 | 'microphone'
1870 | 'background-sync'
1871 | 'ambient-light-sensor'
1872 | 'accelerometer'
1873 | 'gyroscope'
1874 | 'magnetometer'
1875 | 'accessibility-events'
1876 | 'clipboard-read'
1877 | 'clipboard-write'
1878 | 'payment-handler';
1879
1880/**
1881 * BrowserContexts provide a way to operate multiple independent browser sessions.
1882 * When a browser is launched, it has a single BrowserContext used by default.
1883 * The method `browser.newPage()` creates a page in the default browser context.
1884 */
1885export interface BrowserContext extends EventEmitter, TargetAwaiter {
1886 /**
1887 * Adds the listener function to the end of the listeners array for the event named `eventName`.
1888 * No checks are made to see if the listener has already been added. Multiple calls passing the same combination of
1889 * `eventName` and listener will result in the listener being added, and called, multiple times.
1890 * @param event The name of the event.
1891 * @param handler The callback function.
1892 */
1893 on<K extends keyof BrowserContextEventObj>(
1894 eventName: K,
1895 handler: (e: BrowserContextEventObj[K], ...args: any[]) => void,
1896 ): this;
1897
1898 /**
1899 * Adds a one time listener function for the event named `eventName`.
1900 * The next time `eventName` is triggered, this listener is removed and then invoked.
1901 * @param event The name of the event.
1902 * @param handler The callback function.
1903 */
1904 once<K extends keyof BrowserContextEventObj>(
1905 eventName: K,
1906 handler: (e: BrowserContextEventObj[K], ...args: any[]) => void,
1907 ): this;
1908
1909 /** The browser this browser context belongs to. */
1910 browser(): Browser;
1911
1912 /**
1913 * Clears all permission overrides for the browser context.
1914 */
1915 clearPermissionOverrides(): Promise<void>;
1916
1917 /** Closes the browser context. All the targets that belong to the browser context will be closed. */
1918 close(): Promise<void>;
1919
1920 /**
1921 * Returns whether BrowserContext is incognito.
1922 * The default browser context is the only non-incognito browser context.
1923 */
1924 isIncognito(): boolean;
1925
1926 /** Creates a new page in the browser context. */
1927 newPage(): Promise<Page>;
1928
1929 /**
1930 *
1931 * @param origin The origin to grant permissions to, e.g. "https://example.com".
1932 * @param permissions An array of permissions to grant.
1933 * All permissions that are not listed here will be automatically denied.
1934 */
1935 overridePermissions(origin: string, permissions: Permission[]): Promise<void>;
1936
1937 /** Promise which resolves to an array of all open pages. */
1938 pages(): Promise<Page[]>;
1939
1940 /** An array of all active targets inside the browser context. */
1941 targets(): Target[];
1942}
1943
1944export interface BrowserContextEventObj {
1945 /** Emitted when the url of a target inside the browser context changes. */
1946 targetchanged: Target;
1947
1948 /** Emitted when a target is created, for example when a new page is opened by `window.open` or `browserContext.newPage`. */
1949 targetcreated: Target;
1950
1951 /** Emitted when a target is destroyed, for example when a page is closed. */
1952 targetdestroyed: Target;
1953}
1954
1955export type TargetType = 'page' | 'background_page' | 'shared_worker' | 'service_worker' | 'browser' | 'other';
1956
1957export interface Target {
1958 /** Get the browser the target belongs to. */
1959 browser(): Browser;
1960
1961 /** The browser context the target belongs to. */
1962 browserContext(): BrowserContext;
1963
1964 /** Creates a Chrome Devtools Protocol session attached to the target. */
1965 createCDPSession(): Promise<CDPSession>;
1966
1967 /** Get the target that opened this target. Top-level targets return `null`. */
1968 opener(): Target | null;
1969
1970 /** Returns the target `Page` or a `null` if the type of the page is not "page". */
1971 page(): Promise<Page>;
1972
1973 /** Identifies what kind of target this is. */
1974 type(): TargetType;
1975
1976 /** Returns the target URL. */
1977 url(): string;
1978
1979 /** If the target is not of type `service_worker` or `shared_worker`, resolves `null`. */
1980 worker(): Promise<Worker | null>;
1981}
1982
1983export interface LaunchOptions extends ChromeArgOptions, BrowserOptions, Timeoutable {
1984 /**
1985 * Which browser to launch.
1986 * At this time, this is either `chrome` or `firefox`. See also `PUPPETEER_PRODUCT`.
1987 * @default 'chrome'
1988 */
1989 product?: Product | undefined;
1990 /**
1991 * Path to a Chromium executable to run instead of bundled Chromium. If
1992 * executablePath is a relative path, then it is resolved relative to current
1993 * working directory.
1994 */
1995 executablePath?: string | undefined;
1996 /**
1997 * Do not use `puppeteer.defaultArgs()` for launching Chromium.
1998 * @default false
1999 */
2000 ignoreDefaultArgs?: boolean | string[] | undefined;
2001 /**
2002 * Close chrome process on Ctrl-C.
2003 * @default true
2004 */
2005 handleSIGINT?: boolean | undefined;
2006 /**
2007 * Close chrome process on SIGTERM.
2008 * @default true
2009 */
2010 handleSIGTERM?: boolean | undefined;
2011 /**
2012 * Close chrome process on SIGHUP.
2013 * @default true
2014 */
2015 handleSIGHUP?: boolean | undefined;
2016 /**
2017 * Whether to pipe browser process stdout and stderr into process.stdout and
2018 * process.stderr.
2019 * @default false
2020 */
2021 dumpio?: boolean | undefined;
2022 /**
2023 * Specify environment variables that will be visible to Chromium.
2024 * @default `process.env`.
2025 */
2026 env?: {
2027 [key: string]: string | boolean | number;
2028 } | undefined;
2029 /**
2030 * Connects to the browser over a pipe instead of a WebSocket.
2031 * @default false
2032 */
2033 pipe?: boolean | undefined;
2034}
2035
2036export interface ChromeArgOptions {
2037 /**
2038 * Whether to run browser in headless mode.
2039 * @default true unless the devtools option is true.
2040 */
2041 headless?: boolean | undefined;
2042 /**
2043 * Additional arguments to pass to the browser instance.
2044 * The list of Chromium flags can be found here.
2045 */
2046 args?: string[] | undefined;
2047 /**
2048 * Path to a User Data Directory.
2049 */
2050 userDataDir?: string | undefined;
2051 /**
2052 * Whether to auto-open a DevTools panel for each tab.
2053 * If this option is true, the headless option will be set false.
2054 */
2055 devtools?: boolean | undefined;
2056}
2057
2058export interface BrowserOptions {
2059 /**
2060 * Whether to ignore HTTPS errors during navigation.
2061 * @default false
2062 */
2063 ignoreHTTPSErrors?: boolean | undefined;
2064 /**
2065 * Sets a consistent viewport for each page. Defaults to an 800x600 viewport. null disables the default viewport.
2066 */
2067 defaultViewport?: {
2068 /**
2069 * page width in pixels.
2070 */
2071 width?: number | undefined;
2072 /**
2073 * page height in pixels.
2074 */
2075 height?: number | undefined;
2076 /**
2077 * Specify device scale factor (can be thought of as dpr).
2078 * @default 1
2079 */
2080 deviceScaleFactor?: number | undefined;
2081 /**
2082 * Whether the meta viewport tag is taken into account.
2083 * @default false
2084 */
2085 isMobile?: boolean | undefined;
2086 /**
2087 * Specifies if viewport supports touch events.
2088 * @default false
2089 */
2090 hasTouch?: boolean | undefined;
2091 /**
2092 * Specifies if viewport is in landscape mode.
2093 * @default false
2094 */
2095 isLandscape?: boolean | undefined;
2096 } | null | undefined;
2097 /**
2098 * Slows down Puppeteer operations by the specified amount of milliseconds.
2099 * Useful so that you can see what is going on.
2100 */
2101 slowMo?: number | undefined;
2102}
2103
2104export interface ConnectOptions extends BrowserOptions {
2105 /**
2106 * A browser url to connect to, in format `http://${host}:${port}`.
2107 * Use interchangeably with browserWSEndpoint to let Puppeteer fetch it from metadata endpoint.
2108 */
2109 browserURL?: string | undefined;
2110
2111 /** A browser websocket endpoint to connect to. */
2112 browserWSEndpoint?: string | undefined;
2113
2114 /**
2115 * **Experimental** Specify a custom transport object for Puppeteer to use.
2116 */
2117 transport?: ConnectionTransport | undefined;
2118}
2119
2120export interface ConnectionTransport {
2121 send(message: string): void;
2122 close(): void;
2123 onmessage?(message: string): void;
2124 onclose?(): void;
2125}
2126
2127export interface CDPSession extends EventEmitter {
2128 /**
2129 * Detaches session from target. Once detached, session won't emit any events and can't be used
2130 * to send messages.
2131 */
2132 detach(): Promise<void>;
2133
2134 /**
2135 * @param method Protocol method name
2136 */
2137 send(method: string, params?: object): Promise<object>;
2138}
2139
2140export interface Coverage {
2141 startCSSCoverage(options?: StartCoverageOptions): Promise<void>;
2142 startJSCoverage(options?: StartCoverageOptions): Promise<void>;
2143 stopCSSCoverage(): Promise<CoverageEntry[]>;
2144 stopJSCoverage(): Promise<CoverageEntry[]>;
2145}
2146
2147export interface StartCoverageOptions {
2148 /**
2149 * Whether to reset coverage on every navigation.
2150 * @default true
2151 */
2152 resetOnNavigation?: boolean | undefined;
2153 /**
2154 * Whether anonymous scripts generated by the page should be reported.
2155 * @default false
2156 */
2157 reportAnonymousScripts?: boolean | undefined;
2158}
2159
2160export interface CoverageEntry {
2161 url: string;
2162 text: string;
2163 ranges: Array<{ start: number; end: number }>;
2164}
2165
2166/** BrowserFetcher can download and manage different versions of Chromium. */
2167export interface BrowserFetcher {
2168 /** The method initiates a HEAD request to check if the revision is available. */
2169 canDownload(revision: string): Promise<boolean>;
2170 /** The method initiates a GET request to download the revision from the host. */
2171 download(
2172 revision: string,
2173 progressCallback?: (downloadBytes: number, totalBytes: number) => void,
2174 ): Promise<RevisionInfo>;
2175 localRevisions(): Promise<string[]>;
2176 platform(): Platform;
2177 product(): Product;
2178 remove(revision: string): Promise<void>;
2179 revisionInfo(revision: string): RevisionInfo;
2180}
2181
2182export interface RevisionInfo {
2183 /** The revision the info was created from */
2184 revision: string;
2185 /** Path to the extracted revision folder */
2186 folderPath: string;
2187 /** Path to the revision executable */
2188 executablePath: string;
2189 /** URL this revision can be downloaded from */
2190 url: string;
2191 /** whether the revision is locally available on disk */
2192 local: boolean;
2193 product: Product;
2194}
2195
2196export interface FetcherOptions {
2197 /** A download host to be used. Defaults to `https://storage.googleapis.com`. */
2198 host?: string | undefined;
2199 /** A path for the downloads folder. Defaults to `<root>/.local-chromium`, where `<root>` is puppeteer's package root. */
2200 path?: string | undefined;
2201 /** Possible values are: `mac`, `win32`, `win64`, `linux`. Defaults to the current platform. */
2202 platform?: Platform | undefined;
2203 /**
2204 * @default 'chrome'
2205 */
2206 product?: Product | undefined;
2207}
2208
2209type EventType = string | symbol;
2210type Handler<T = any> = (event?: T) => void;
2211
2212export interface EventEmitter {
2213 on(event: EventType, handler: Handler): EventEmitter;
2214 off(event: EventType, handler: Handler): EventEmitter;
2215 addListener(event: EventType, handler: Handler): EventEmitter;
2216 removeListener(event: EventType, handler: Handler): EventEmitter;
2217 emit(event: EventType, eventData?: any): boolean;
2218 once(event: EventType, handler: Handler): EventEmitter;
2219 listenerCount(event: string): number;
2220 removeAllListeners(event?: EventType): EventEmitter;
2221}
2222
2223/** Attaches Puppeteer to an existing Chromium instance */
2224export function connect(options?: ConnectOptions): Promise<Browser>;
2225/** The default flags that Chromium will be launched with */
2226export function defaultArgs(options?: ChromeArgOptions): string[];
2227/** Path where Puppeteer expects to find bundled Chromium */
2228export function executablePath(): string;
2229/** The method launches a browser instance with given arguments. The browser will be closed when the parent node.js process is closed. */
2230export function launch(options?: LaunchOptions): Promise<Browser>;
2231/** This methods attaches Puppeteer to an existing Chromium instance. */
2232export function createBrowserFetcher(options?: FetcherOptions): BrowserFetcher;
2233
\No newline at end of file