UNPKG

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