-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
2255 lines (2017 loc) · 71.2 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Type definitions for puppeteer 2.0
// Project: https://github.com/GoogleChrome/puppeteer#readme
// Definitions by: Marvin Hagemeister <https://github.com/marvinhagemeister>
// Christopher Deutsch <https://github.com/cdeutsch>
// Konstantin Simon Maria Möllers <https://github.com/ksm2>
// Simon Schick <https://github.com/SimonSchick>
// Serban Ghita <https://github.com/SerbanGhita>
// Jason Kaczmarsky <https://github.com/JasonKaz>
// Dave Cardwell <https://github.com/davecardwell>
// Andrés Ortiz <https://github.com/angrykoala>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.0
/// <reference types="node" />
interface Element { }
interface Node { }
interface NodeListOf<TNode = Node> { }
import { EventEmitter } from "events";
import { ChildProcess } from "child_process";
import * as errors from "./Errors";
import * as devices from "./DeviceDescriptors";
export { errors, devices };
/** Wraps a DOM element into an ElementHandle instance */
export type WrapElementHandle<X> = X extends Element ? ElementHandle<X> : X;
/** Unwraps a DOM element out of an ElementHandle instance */
export type UnwrapElementHandle<X> = X extends ElementHandle<infer E> ? E : X;
export type Serializable =
| number
| string
| boolean
| null
| JSONArray
| JSONObject;
export interface JSONArray extends Array<Serializable> { }
export interface JSONObject {
[key: string]: Serializable;
}
export type SerializableOrJSHandle = Serializable | JSHandle;
export type Platform = "mac" | "win32" | "win64" | "linux";
/** Defines `$eval` and `$$eval` for Page, Frame and ElementHandle. */
export interface Evalable {
/**
* This method runs `document.querySelector` within the context and passes it as the first argument to `pageFunction`.
* If there's no element matching `selector`, the method throws an error.
*
* If `pageFunction` returns a Promise, then `$eval` would wait for the promise to resolve and return its value.
*
* @param selector A selector to query for
* @param pageFunction Function to be evaluated in browser context
* @returns Promise which resolves to the return value of pageFunction
*/
$eval<R>(
selector: string,
pageFunction: (element: Element) => R | Promise<R>,
): Promise<WrapElementHandle<R>>;
/**
* This method runs `document.querySelector` within the context and passes it as the first argument to `pageFunction`.
* If there's no element matching `selector`, the method throws an error.
*
* If `pageFunction` returns a Promise, then `$eval` would wait for the promise to resolve and return its value.
*
* @param selector A selector to query for
* @param pageFunction Function to be evaluated in browser context
* @param x1 First argument to pass to pageFunction
* @returns Promise which resolves to the return value of pageFunction
*/
$eval<R, X1>(
selector: string,
pageFunction: (element: Element, x1: UnwrapElementHandle<X1>) => R | Promise<R>,
x1: X1,
): Promise<WrapElementHandle<R>>;
/**
* This method runs `document.querySelector` within the context and passes it as the first argument to `pageFunction`.
* If there's no element matching `selector`, the method throws an error.
*
* If `pageFunction` returns a Promise, then `$eval` would wait for the promise to resolve and return its value.
*
* @param selector A selector to query for
* @param pageFunction Function to be evaluated in browser context
* @param x1 First argument to pass to pageFunction
* @param x2 Second argument to pass to pageFunction
* @returns Promise which resolves to the return value of pageFunction
*/
$eval<R, X1, X2>(
selector: string,
pageFunction: (element: Element, x1: UnwrapElementHandle<X1>, x2: UnwrapElementHandle<X2>) => R | Promise<R>,
x1: X1,
x2: X2,
): Promise<WrapElementHandle<R>>;
/**
* This method runs `document.querySelector` within the context and passes it as the first argument to `pageFunction`.
* If there's no element matching `selector`, the method throws an error.
*
* If `pageFunction` returns a Promise, then `$eval` would wait for the promise to resolve and return its value.
*
* @param selector A selector to query for
* @param pageFunction Function to be evaluated in browser context
* @param x1 First argument to pass to pageFunction
* @param x2 Second argument to pass to pageFunction
* @param x3 Third argument to pass to pageFunction
* @returns Promise which resolves to the return value of pageFunction
*/
$eval<R, X1, X2, X3>(
selector: string,
pageFunction: (element: Element, x1: UnwrapElementHandle<X1>, x2: UnwrapElementHandle<X2>, x3: UnwrapElementHandle<X3>) => R | Promise<R>,
x1: X1,
x2: X2,
x3: X3,
): Promise<WrapElementHandle<R>>;
/**
* This method runs `document.querySelector` within the context and passes it as the first argument to `pageFunction`.
* If there's no element matching `selector`, the method throws an error.
*
* If `pageFunction` returns a Promise, then `$eval` would wait for the promise to resolve and return its value.
*
* @param selector A selector to query for
* @param pageFunction Function to be evaluated in browser context
* @param args Arguments to pass to pageFunction
* @returns Promise which resolves to the return value of pageFunction
*/
$eval<R>(
selector: string,
pageFunction: (element: Element, ...args: any[]) => R | Promise<R>,
...args: SerializableOrJSHandle[],
): Promise<WrapElementHandle<R>>;
/**
* This method runs `Array.from(document.querySelectorAll(selector))` within the context and passes it as the
* first argument to `pageFunction`.
*
* If `pageFunction` returns a Promise, then `$$eval` would wait for the promise to resolve and return its value.
*
* @param selector A selector to query for
* @param pageFunction Function to be evaluated in browser context
* @returns Promise which resolves to the return value of pageFunction
*/
$$eval<R>(
selector: string,
pageFunction: (elements: Element[]) => R | Promise<R>,
): Promise<WrapElementHandle<R>>;
/**
* This method runs `Array.from(document.querySelectorAll(selector))` within the context and passes it as the
* first argument to `pageFunction`.
*
* If `pageFunction` returns a Promise, then `$$eval` would wait for the promise to resolve and return its value.
*
* @param selector A selector to query for
* @param pageFunction Function to be evaluated in browser context
* @param x1 First argument to pass to pageFunction
* @returns Promise which resolves to the return value of pageFunction
*/
$$eval<R, X1>(
selector: string,
pageFunction: (elements: Element[], x1: UnwrapElementHandle<X1>) => R | Promise<R>,
x1: X1,
): Promise<WrapElementHandle<R>>;
/**
* This method runs `Array.from(document.querySelectorAll(selector))` within the context and passes it as the
* first argument to `pageFunction`.
*
* If `pageFunction` returns a Promise, then `$$eval` would wait for the promise to resolve and return its value.
*
* @param selector A selector to query for
* @param pageFunction Function to be evaluated in browser context
* @param x1 First argument to pass to pageFunction
* @param x2 Second argument to pass to pageFunction
* @returns Promise which resolves to the return value of pageFunction
*/
$$eval<R, X1, X2>(
selector: string,
pageFunction: (elements: Element[], x1: UnwrapElementHandle<X1>, x2: UnwrapElementHandle<X2>) => R | Promise<R>,
x1: X1,
x2: X2,
): Promise<WrapElementHandle<R>>;
/**
* This method runs `Array.from(document.querySelectorAll(selector))` within the context and passes it as the
* first argument to `pageFunction`.
*
* If `pageFunction` returns a Promise, then `$$eval` would wait for the promise to resolve and return its value.
*
* @param selector A selector to query for
* @param pageFunction Function to be evaluated in browser context
* @param x1 First argument to pass to pageFunction
* @param x2 Second argument to pass to pageFunction
* @param x3 Third argument to pass to pageFunction
* @returns Promise which resolves to the return value of pageFunction
*/
$$eval<R, X1, X2, X3>(
selector: string,
pageFunction: (elements: Element[], x1: UnwrapElementHandle<X1>, x2: UnwrapElementHandle<X2>, x3: UnwrapElementHandle<X3>) => R | Promise<R>,
x1: X1,
x2: X2,
x3: X3,
): Promise<WrapElementHandle<R>>;
/**
* This method runs `Array.from(document.querySelectorAll(selector))` within the context and passes it as the
* first argument to `pageFunction`.
*
* If `pageFunction` returns a Promise, then `$$eval` would wait for the promise to resolve and return its value.
*
* @param selector A selector to query for
* @param pageFunction Function to be evaluated in browser context
* @param args Arguments to pass to pageFunction
* @returns Promise which resolves to the return value of pageFunction
*/
$$eval<R>(
selector: string,
pageFunction: (elements: Element[], ...args: any[]) => R | Promise<R>,
...args: SerializableOrJSHandle[]
): Promise<WrapElementHandle<R>>;
}
export interface JSEvalable<A = any> {
/**
* Evaluates a function in the browser context.
* 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.
* If the function passed into frame.evaluate returns a non-Serializable value, then frame.evaluate resolves to undefined.
* @param fn Function to be evaluated in browser context
* @param args Arguments to pass to `fn`
*/
evaluate<T extends EvaluateFn<A>>(
pageFunction: T,
...args: SerializableOrJSHandle[],
): Promise<EvaluateFnReturnType<T>>;
/**
* The only difference between `evaluate` and `evaluateHandle` is that `evaluateHandle` returns in-page object (`JSHandle`).
* If the function, passed to the `evaluateHandle`, returns a `Promise`, then `evaluateHandle` would wait for the
* promise to resolve and return its value.
* @param fn Function to be evaluated in browser context
* @param args Arguments to pass to `fn`
*/
evaluateHandle(
pageFunction: string | ((arg1: A, ...args: any[]) => any),
...args: SerializableOrJSHandle[],
): Promise<JSHandle>;
}
/** Keyboard provides an api for managing a virtual keyboard. */
export interface Keyboard {
/**
* Dispatches a keydown event.
* @param key Name of key to press, such as ArrowLeft.
* @param options Specifies a input text event.
*/
down(key: string, options?: { text?: string }): Promise<void>;
/** Shortcut for `keyboard.down` and `keyboard.up`. */
press(key: string, options?: { text?: string, delay?: number }): Promise<void>;
/** Dispatches a `keypress` and `input` event. This does not send a `keydown` or keyup `event`. */
sendCharacter(char: string): Promise<void>;
/**
* Sends a keydown, keypress/input, and keyup event for each character in the text.
* @param text A text to type into a focused element.
* @param options Specifies the typing options.
*/
type(text: string, options?: { delay?: number }): Promise<void>;
/**
* Dispatches a keyup event.
* @param key Name of key to release, such as ArrowLeft.
*/
up(key: string): Promise<void>;
}
export interface MousePressOptions {
/**
* left, right, or middle.
* @default left
*/
button?: MouseButtons;
/**
* The number of clicks.
* @default 1
*/
clickCount?: number;
}
export interface Mouse {
/**
* Shortcut for `mouse.move`, `mouse.down` and `mouse.up`.
* @param x The x position.
* @param y The y position.
* @param options The click options.
*/
click(x: number, y: number, options?: ClickOptions): Promise<void>;
/**
* Dispatches a `mousedown` event.
* @param options The mouse press options.
*/
down(options?: MousePressOptions): Promise<void>;
/**
* Dispatches a `mousemove` event.
* @param x The x position.
* @param y The y position.
* @param options The mouse move options.
*/
move(x: number, y: number, options?: { steps: number }): Promise<void>;
/**
* Dispatches a `mouseup` event.
* @param options The mouse press options.
*/
up(options?: MousePressOptions): Promise<void>;
}
export interface Touchscreen {
/**
* Dispatches a touchstart and touchend event.
* @param x The x position.
* @param y The y position.
*/
tap(x: number, y: number): Promise<void>;
}
/**
* You can use `tracing.start` and `tracing.stop` to create a trace file which can be opened in Chrome DevTools or timeline viewer.
*/
export interface Tracing {
start(options: TracingStartOptions): Promise<void>;
stop(): Promise<Buffer>;
}
export interface TracingStartOptions {
path: string;
screenshots?: boolean;
categories?: string[];
}
export type DialogType = "alert" | "beforeunload" | "confirm" | "prompt";
/** Dialog objects are dispatched by page via the 'dialog' event. */
export interface Dialog {
/**
* Accepts the dialog.
* @param promptText A text to enter in prompt. Does not cause any effects if the dialog's type is not prompt.
*/
accept(promptText?: string): Promise<void>;
/** If dialog is prompt, returns default prompt value. Otherwise, returns empty string. */
defaultValue(): string;
/** Dismiss the dialog */
dismiss(): Promise<void>;
/** Returns the message displayed in the dialog. */
message(): string;
/** The dialog type. Dialog's type, can be one of `alert`, `beforeunload`, `confirm` or `prompt`. */
type(): DialogType;
}
export type ConsoleMessageType = "log"
| "debug"
| "info"
| "error"
| "warning"
| "dir"
| "dirxml"
| "table"
| "trace"
| "clear"
| "startGroup"
| "startGroupCollapsed"
| "endGroup"
| "assert"
| "profile"
| "profileEnd"
| "count"
| "timeEnd";
export interface ConsoleMessageLocation {
/**
* URL of the resource if known.
*/
url?: string;
/**
* Line number in the resource if known
*/
lineNumber?: number;
/**
* Column number in the resource if known.
*/
columnNumber?: number;
}
/** ConsoleMessage objects are dispatched by page via the 'console' event. */
export interface ConsoleMessage {
/** The message arguments. */
args(): JSHandle[];
/** The location the message originated from */
location(): ConsoleMessageLocation;
/** The message text. */
text(): string;
type(): ConsoleMessageType;
}
export interface AuthOptions {
username: string;
password: string;
}
export type MouseButtons = "left" | "right" | "middle";
export interface ClickOptions {
/** @default MouseButtons.Left */
button?: MouseButtons;
/** @default 1 */
clickCount?: number;
/**
* Time to wait between mousedown and mouseup in milliseconds.
* @default 0
*/
delay?: number;
}
export type SameSiteSetting = "Strict" | "Lax";
/** Represents a browser cookie. */
export interface Cookie {
/** The cookie name. */
name: string;
/** The cookie value. */
value: string;
/** The cookie domain. */
domain: string;
/** The cookie path. */
path: string;
/** The cookie Unix expiration time in seconds. */
expires: number;
/** The cookie size */
size: number;
/** The cookie http only flag. */
httpOnly: boolean;
/** The session cookie flag. */
session: boolean;
/** The cookie secure flag. */
secure: boolean;
/** The cookie same site definition. */
sameSite: SameSiteSetting;
}
export interface DeleteCookie {
/** The cookie name. */
name: string;
url?: string;
domain?: string;
path?: string;
}
export interface SetCookie {
/** The cookie name. */
name: string;
/** The cookie value. */
value: string;
/** 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. */
url?: string;
/** The cookie domain. */
domain?: string;
/** The cookie path. */
path?: string;
/** The cookie Unix expiration time in seconds. */
expires?: number;
/** The cookie http only flag. */
httpOnly?: boolean;
/** The session cookie flag. */
session?: boolean;
/** The cookie secure flag. */
secure?: boolean;
/** The cookie same site definition. */
sameSite?: SameSiteSetting;
}
export interface Viewport {
/** The page width in pixels. */
width: number;
/** The page height in pixels. */
height: number;
/**
* Specify device scale factor (can be thought of as dpr).
* @default 1
*/
deviceScaleFactor?: number;
/**
* Whether the `meta viewport` tag is taken into account.
* @default false
*/
isMobile?: boolean;
/**
* Specifies if viewport supports touch events.
* @default false
*/
hasTouch?: boolean;
/**
* Specifies if viewport is in landscape mode.
* @default false
*/
isLandscape?: boolean;
}
/** Page emulation options. */
export interface EmulateOptions {
/** The viewport emulation options. */
viewport: Viewport;
/** The emulated user-agent. */
userAgent: string;
}
export type EvaluateFn<T = any> = string | ((arg1: T, ...args: any[]) => any);
export type EvaluateFnReturnType<T extends EvaluateFn> = T extends ((...args: any[]) => infer R) ? R : unknown;
export type LoadEvent =
| "load"
| "domcontentloaded"
| "networkidle0"
| "networkidle2";
export interface Timeoutable {
/**
* Maximum navigation time in milliseconds, pass 0 to disable timeout.
* @default 30000
*/
timeout?: number;
}
/** The navigation options. */
export interface NavigationOptions extends Timeoutable {
/**
* When to consider navigation succeeded.
* @default load Navigation is consider when the `load` event is fired.
*/
waitUntil?: LoadEvent | LoadEvent[];
}
/**
* Navigation options for `page.goto`.
*/
export interface DirectNavigationOptions extends NavigationOptions {
/**
* Referer header value.
* If provided it will take preference over the referer header value set by
* [page.setExtraHTTPHeaders()](#pagesetextrahttpheadersheaders).
*/
referer?: string;
}
/** Accepts values labeled with units. If number, treat as pixels. */
export type LayoutDimension = string | number;
export type PDFFormat =
| "Letter"
| "Legal"
| "Tabloid"
| "Ledger"
| "A0"
| "A1"
| "A2"
| "A3"
| "A4"
| "A5"
| "A6";
export interface PDFOptions {
/**
* The file path to save the PDF to.
* If `path` is a relative path, then it is resolved relative to current working directory.
* If no path is provided, the PDF won't be saved to the disk.
*/
path?: string;
/**
* Scale of the webpage rendering.
* @default 1
*/
scale?: number;
/**
* Display header and footer.
* @default false
*/
displayHeaderFooter?: boolean;
/**
* HTML template for the print header. Should be valid HTML markup with following classes used to inject printing values into them:
* - `date` formatted print date
* - `title` document title
* - `url` document location
* - `pageNumber` current page number
* - `totalPages` total pages in the document
*/
headerTemplate?: string;
/**
* HTML template for the print footer. Should be valid HTML markup with following classes used to inject printing values into them:
* - `date` formatted print date
* - `title` document title
* - `url` document location
* - `pageNumber` current page number
* - `totalPages` total pages in the document
*/
footerTemplate?: string;
/**
* Print background graphics.
* @default false
*/
printBackground?: boolean;
/**
* Paper orientation.
* @default false
*/
landscape?: boolean;
/**
* Paper ranges to print, e.g., '1-5, 8, 11-13'.
* @default '' which means print all pages.
*/
pageRanges?: string;
/**
* Paper format. If set, takes priority over width or height options.
* @default 'Letter'
*/
format?: PDFFormat;
/** Paper width. */
width?: LayoutDimension;
/** Paper height. */
height?: LayoutDimension;
/** Paper margins, defaults to none. */
margin?: {
/** Top margin. */
top?: LayoutDimension;
/** Right margin. */
right?: LayoutDimension;
/** Bottom margin. */
bottom?: LayoutDimension;
/** Left margin. */
left?: LayoutDimension;
};
/**
* Give any CSS @page size declared in the page priority over what is declared in width and
* height or format options.
* @default false which will scale the content to fit the paper size.
*/
preferCSSPageSize?: boolean;
}
/** Defines the screenshot options. */
export interface ScreenshotOptions {
/**
* The file path to save the image to. The screenshot type will be inferred from file extension.
* If `path` is a relative path, then it is resolved relative to current working directory.
* If no path is provided, the image won't be saved to the disk.
*/
path?: string;
/**
* The screenshot type.
* @default png
*/
type?: "jpeg" | "png";
/** The quality of the image, between 0-100. Not applicable to png images. */
quality?: number;
/**
* When true, takes a screenshot of the full scrollable page.
* @default false
*/
fullPage?: boolean;
/**
* An object which specifies clipping region of the page.
*/
clip?: BoundingBox;
/**
* Hides default white background and allows capturing screenshots with transparency.
* @default false
*/
omitBackground?: boolean;
/**
* The encoding of the image, can be either base64 or binary.
* @default binary
*/
encoding?: "base64" | "binary";
}
export interface BinaryScreenShotOptions extends ScreenshotOptions {
encoding?: "binary";
}
export interface Base64ScreenShotOptions extends ScreenshotOptions {
encoding: "base64";
}
/** Options for `addStyleTag` */
export interface StyleTagOptions {
/** Url of the <link> tag. */
url?: string;
/** 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. */
path?: string;
/** Raw CSS content to be injected into frame. */
content?: string;
}
/** Options for `addScriptTag` */
export interface ScriptTagOptions {
/** Url of a script to be added. */
url?: string;
/** 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. */
path?: string;
/** Raw JavaScript content to be injected into frame. */
content?: string;
/** Script type. Use 'module' in order to load a Javascript ES6 module. */
type?: string;
}
export interface PageFnOptions extends Timeoutable {
polling?: "raf" | "mutation" | number;
}
export interface BoundingBox {
/** The x-coordinate of top-left corner. */
x: number;
/** The y-coordinate of top-left corner. */
y: number;
/** The width. */
width: number;
/** The height. */
height: number;
}
export interface BoxModel {
/** Content box, represented as an array of {x, y} points. */
content: Box[];
/** Padding box, represented as an array of {x, y} points. */
padding: Box[];
/** Border box, represented as an array of {x, y} points. */
border: Box[];
/** Margin box, represented as an array of {x, y} points. */
margin: Box[];
width: number;
height: number;
}
export interface Box {
x: number;
y: number;
}
/**
* The Worker class represents a WebWorker.
* The events workercreated and workerdestroyed are emitted on the page object to signal the worker lifecycle.
*/
export interface Worker extends JSEvalable {
executionContext(): Promise<ExecutionContext>;
url(): string;
}
/**
* Represents an in-page DOM element. ElementHandles can be created with the page.$ method.
*/
export interface ElementHandle<E extends Element = Element> extends JSHandle<E>, Evalable {
/**
* The method runs element.querySelector within the page.
* If no element matches the selector, the return value resolve to null.
* @param selector A selector to query element for
* @since 0.13.0
*/
$(selector: string): Promise<ElementHandle | null>;
/**
* The method runs element.querySelectorAll within the page.
* If no elements match the selector, the return value resolve to [].
* @param selector A selector to query element for
* @since 0.13.0
*/
$$(selector: string): Promise<ElementHandle[]>;
/**
* @param selector XPath expression to evaluate.
*/
$x(expression: string): Promise<ElementHandle[]>;
/**
* 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.
*/
boundingBox(): Promise<BoundingBox | null>;
/**
* This method returns boxes of the element, or null if the element is not visible.
* Boxes are represented as an array of points; each Point is an object {x, y}. Box points are sorted clock-wise.
*/
boxModel(): Promise<BoxModel | null>;
/**
* This method scrolls element into view if needed, and then uses page.mouse to click in the center of the element.
* If the element is detached from DOM, the method throws an error.
* @param options Specifies the options.
* @since 0.9.0
*/
click(options?: ClickOptions): Promise<void>;
/**
* @returns Resolves to the content frame for element handles referencing iframe nodes, or null otherwise.
* @since 1.2.0
*/
contentFrame(): Promise<Frame | null>;
/**
* Calls focus on the element.
*/
focus(): Promise<void>;
/**
* This method scrolls element into view if needed, and then uses page.mouse to hover over the center of the element.
* If the element is detached from DOM, the method throws an error.
*/
hover(): Promise<void>;
/**
* Resolves to true if the element is visible in the current viewport.
*/
isIntersectingViewport(): Promise<boolean>;
/**
* Focuses the element, and then uses keyboard.down and keyboard.up.
* @param key Name of key to press, such as ArrowLeft. See USKeyboardLayout for a list of all key names.
* @param options The text and delay options.
*/
press(key: string, options?: { text?: string, delay?: number }): Promise<void>;
/**
* This method scrolls element into view if needed, and then uses page.screenshot to take a screenshot of the element.
* If the element is detached from DOM, the method throws an error.
* @param options Same options as in page.screenshot.
*/
screenshot(options?: Base64ScreenShotOptions): Promise<string>;
screenshot(options?: BinaryScreenShotOptions): Promise<Buffer>;
screenshot(options?: ScreenshotOptions): Promise<string | Buffer>;
/**
* Triggers a change and input event once all the provided options have been selected. If there's no <select> element
* matching selector, the method throws an error.
* @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.
* @returns An array of option values that have been successfully selected.
* @since 1.12.0
*/
select(...values: string[]): Promise<string[]>;
/**
* This method scrolls element into view if needed, and then uses touchscreen.tap to tap in the center of the element.
* If the element is detached from DOM, the method throws an error.
*/
tap(): Promise<void>;
toString(): string;
/**
* Focuses the element, and then sends a keydown, keypress/input, and keyup event for each character in the text.
* @param text A text to type into a focused element.
* @param options The typing options.
*/
type(text: string, options?: { delay: number }): Promise<void>;
/**
* This method expects elementHandle to point to an input element.
* @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.
*/
uploadFile(...filePaths: string[]): Promise<void>;
}
/** The class represents a context for JavaScript execution. */
export interface ExecutionContext extends JSEvalable {
queryObjects(prototypeHandle: JSHandle): JSHandle;
}
/** JSHandle represents an in-page JavaScript object. */
export interface JSHandle<T = any> extends JSEvalable<T> {
/**
* Returns a ElementHandle
*/
asElement(): ElementHandle | null;
/**
* Stops referencing the element handle.
*/
dispose(): Promise<void>;
/**
* Gets the execution context.
*/
executionContext(): ExecutionContext;
/**
* Returns a map with property names as keys and JSHandle instances for the property values.
*/
getProperties(): Promise<Map<string, JSHandle>>;
/**
* Fetches a single property from the objectHandle.
* @param propertyName The property to get.
*/
getProperty(propertyName: string): Promise<JSHandle>;
/**
* Returns a JSON representation of the object.
* The JSON is generated by running JSON.stringify on the object in page and consequent JSON.parse in puppeteer.
* @throws The method will throw if the referenced object is not stringifiable.
*/
jsonValue(): Promise<unknown>;
}
export interface Metrics {
/** The timestamp when the metrics sample was taken. */
Timestamp: number;
/** Number of documents in the page. */
Documents: number;
/** Number of frames in the page. */
Frames: number;
/** Number of events in the page. */
JSEventListeners: number;
/** Number of DOM nodes in the page. */
Nodes: number;
/** Total number of full or partial page layout. */
LayoutCount: number;
/** Total number of page style recalculations. */
RecalcStyleCount: number;
/** Combined durations of all page layouts. */
LayoutDuration: number;
/** Combined duration of all page style recalculations. */
RecalcStyleDuration: number;
/** Combined duration of JavaScript execution. */
ScriptDuration: number;
/** Combined duration of all tasks performed by the browser. */
TaskDuration: number;
/** Used JavaScript heap size. */
JSHeapUsedSize: number;
/** Total JavaScript heap size. */
JSHeapTotalSize: number;
}
export type Headers = Record<string, string>;
export type HttpMethod =
| "GET"
| "POST"
| "PATCH"
| "PUT"
| "DELETE"
| "OPTIONS";
export type ResourceType =
| "document"
| "stylesheet"
| "image"
| "media"
| "font"
| "script"
| "texttrack"
| "xhr"
| "fetch"
| "eventsource"
| "websocket"
| "manifest"
| "other";
export type ErrorCode =
| "aborted"
| "accessdenied"
| "addressunreachable"
| "blockedbyclient"
| "blockedbyresponse"
| "connectionaborted"
| "connectionclosed"
| "connectionfailed"
| "connectionrefused"
| "connectionreset"
| "internetdisconnected"
| "namenotresolved"
| "timedout"
| "failed";
export interface Overrides {
url?: string;
method?: HttpMethod;
postData?: string;
headers?: Headers;
}
/** Represents a page request. */
export interface Request {
/**
* Aborts request.
* To use this, request interception should be enabled with `page.setRequestInterception`.
* @throws An exception is immediately thrown if the request interception is not enabled.
*/
abort(errorCode?: ErrorCode): Promise<void>;
/**
* Continues request with optional request overrides.
* To use this, request interception should be enabled with `page.setRequestInterception`.
* @throws An exception is immediately thrown if the request interception is not enabled.
*/
continue(overrides?: Overrides): Promise<void>;
/**
* @returns An object if the request failed, null otherwise.
*/
failure(): { errorText: string; } | null;
/**
* @returns The `Frame` object that initiated the request, or `null` if navigating to error pages