UNPKG

271 kBTypeScriptView Raw
1/// <reference types="node" />
2
3import type { ChildProcess } from 'child_process';
4import type { ParseSelector } from 'typed-query-selector/parser.js';
5import { PassThrough } from 'stream';
6import { Protocol } from 'devtools-protocol';
7import type { ProtocolMapping } from 'devtools-protocol/types/protocol-mapping.js';
8import { Session } from 'chromium-bidi/lib/cjs/protocol/protocol.js';
9
10/**
11 * The Accessibility class provides methods for inspecting the browser's
12 * accessibility tree. The accessibility tree is used by assistive technology
13 * such as {@link https://en.wikipedia.org/wiki/Screen_reader | screen readers} or
14 * {@link https://en.wikipedia.org/wiki/Switch_access | switches}.
15 *
16 * @remarks
17 *
18 * Accessibility is a very platform-specific thing. On different platforms,
19 * there are different screen readers that might have wildly different output.
20 *
21 * Blink - Chrome's rendering engine - has a concept of "accessibility tree",
22 * which is then translated into different platform-specific APIs. Accessibility
23 * namespace gives users access to the Blink Accessibility Tree.
24 *
25 * Most of the accessibility tree gets filtered out when converting from Blink
26 * AX Tree to Platform-specific AX-Tree or by assistive technologies themselves.
27 * By default, Puppeteer tries to approximate this filtering, exposing only
28 * the "interesting" nodes of the tree.
29 *
30 * @public
31 */
32export declare class Accessibility {
33 #private;
34
35 /**
36 * Captures the current state of the accessibility tree.
37 * The returned object represents the root accessible node of the page.
38 *
39 * @remarks
40 *
41 * **NOTE** The Chrome accessibility tree contains nodes that go unused on
42 * most platforms and by most screen readers. Puppeteer will discard them as
43 * well for an easier to process tree, unless `interestingOnly` is set to
44 * `false`.
45 *
46 * @example
47 * An example of dumping the entire accessibility tree:
48 *
49 * ```ts
50 * const snapshot = await page.accessibility.snapshot();
51 * console.log(snapshot);
52 * ```
53 *
54 * @example
55 * An example of logging the focused node's name:
56 *
57 * ```ts
58 * const snapshot = await page.accessibility.snapshot();
59 * const node = findFocusedNode(snapshot);
60 * console.log(node && node.name);
61 *
62 * function findFocusedNode(node) {
63 * if (node.focused) return node;
64 * for (const child of node.children || []) {
65 * const foundNode = findFocusedNode(child);
66 * return foundNode;
67 * }
68 * return null;
69 * }
70 * ```
71 *
72 * @returns An AXNode object representing the snapshot.
73 */
74 snapshot(options?: SnapshotOptions): Promise<SerializedAXNode | null>;
75 private serializeTree;
76 private collectInterestingNodes;
77}
78
79/**
80 * @public
81 */
82export declare interface ActionOptions {
83 /**
84 * A signal to abort the locator action.
85 */
86 signal?: AbortSignal;
87}
88
89/**
90 * @public
91 */
92export declare type ActionResult = 'continue' | 'abort' | 'respond';
93
94/**
95 * @public
96 */
97export declare interface AutofillData {
98 creditCard: {
99 number: string;
100 name: string;
101 expiryMonth: string;
102 expiryYear: string;
103 cvc: string;
104 };
105}
106
107/**
108 * @public
109 */
110export declare type Awaitable<T> = T | PromiseLike<T>;
111
112/**
113 * @public
114 */
115export declare type AwaitableIterable<T> = Iterable<T> | AsyncIterable<T>;
116
117/**
118 * @public
119 */
120export declare type AwaitablePredicate<T> = (value: T) => Awaitable<boolean>;
121
122/**
123 * @public
124 */
125export declare type AwaitedLocator<T> = T extends Locator<infer S> ? S : never;
126
127/**
128 * @public
129 */
130export declare interface BoundingBox extends Point {
131 /**
132 * the width of the element in pixels.
133 */
134 width: number;
135 /**
136 * the height of the element in pixels.
137 */
138 height: number;
139}
140
141/**
142 * @public
143 */
144export declare interface BoxModel {
145 content: Quad;
146 padding: Quad;
147 border: Quad;
148 margin: Quad;
149 width: number;
150 height: number;
151}
152
153/**
154 * {@link Browser} represents a browser instance that is either:
155 *
156 * - connected to via {@link Puppeteer.connect} or
157 * - launched by {@link PuppeteerNode.launch}.
158 *
159 * {@link Browser} {@link EventEmitter.emit | emits} various events which are
160 * documented in the {@link BrowserEvent} enum.
161 *
162 * @example Using a {@link Browser} to create a {@link Page}:
163 *
164 * ```ts
165 * import puppeteer from 'puppeteer';
166 *
167 * const browser = await puppeteer.launch();
168 * const page = await browser.newPage();
169 * await page.goto('https://example.com');
170 * await browser.close();
171 * ```
172 *
173 * @example Disconnecting from and reconnecting to a {@link Browser}:
174 *
175 * ```ts
176 * import puppeteer from 'puppeteer';
177 *
178 * const browser = await puppeteer.launch();
179 * // Store the endpoint to be able to reconnect to the browser.
180 * const browserWSEndpoint = browser.wsEndpoint();
181 * // Disconnect puppeteer from the browser.
182 * await browser.disconnect();
183 *
184 * // Use the endpoint to reestablish a connection
185 * const browser2 = await puppeteer.connect({browserWSEndpoint});
186 * // Close the browser.
187 * await browser2.close();
188 * ```
189 *
190 * @public
191 */
192export declare abstract class Browser extends EventEmitter<BrowserEvents> {
193
194 /**
195 * Gets the associated
196 * {@link https://nodejs.org/api/child_process.html#class-childprocess | ChildProcess}.
197 *
198 * @returns `null` if this instance was connected to via
199 * {@link Puppeteer.connect}.
200 */
201 abstract process(): ChildProcess | null;
202 /**
203 * Creates a new {@link BrowserContext | browser context}.
204 *
205 * This won't share cookies/cache with other {@link BrowserContext | browser contexts}.
206 *
207 * @example
208 *
209 * ```ts
210 * import puppeteer from 'puppeteer';
211 *
212 * const browser = await puppeteer.launch();
213 * // Create a new browser context.
214 * const context = await browser.createBrowserContext();
215 * // Create a new page in a pristine context.
216 * const page = await context.newPage();
217 * // Do stuff
218 * await page.goto('https://example.com');
219 * ```
220 */
221 abstract createBrowserContext(options?: BrowserContextOptions): Promise<BrowserContext>;
222 /**
223 * Gets a list of open {@link BrowserContext | browser contexts}.
224 *
225 * In a newly-created {@link Browser | browser}, this will return a single
226 * instance of {@link BrowserContext}.
227 */
228 abstract browserContexts(): BrowserContext[];
229 /**
230 * Gets the default {@link BrowserContext | browser context}.
231 *
232 * @remarks The default {@link BrowserContext | browser context} cannot be
233 * closed.
234 */
235 abstract defaultBrowserContext(): BrowserContext;
236 /**
237 * Gets the WebSocket URL to connect to this {@link Browser | browser}.
238 *
239 * This is usually used with {@link Puppeteer.connect}.
240 *
241 * You can find the debugger URL (`webSocketDebuggerUrl`) from
242 * `http://HOST:PORT/json/version`.
243 *
244 * See {@link https://chromedevtools.github.io/devtools-protocol/#how-do-i-access-the-browser-target | browser endpoint}
245 * for more information.
246 *
247 * @remarks The format is always `ws://HOST:PORT/devtools/browser/<id>`.
248 */
249 abstract wsEndpoint(): string;
250 /**
251 * Creates a new {@link Page | page} in the
252 * {@link Browser.defaultBrowserContext | default browser context}.
253 */
254 abstract newPage(): Promise<Page>;
255 /**
256 * Gets all active {@link Target | targets}.
257 *
258 * In case of multiple {@link BrowserContext | browser contexts}, this returns
259 * all {@link Target | targets} in all
260 * {@link BrowserContext | browser contexts}.
261 */
262 abstract targets(): Target[];
263 /**
264 * Gets the {@link Target | target} associated with the
265 * {@link Browser.defaultBrowserContext | default browser context}).
266 */
267 abstract target(): Target;
268 /**
269 * Waits until a {@link Target | target} matching the given `predicate`
270 * appears and returns it.
271 *
272 * This will look all open {@link BrowserContext | browser contexts}.
273 *
274 * @example Finding a target for a page opened via `window.open`:
275 *
276 * ```ts
277 * await page.evaluate(() => window.open('https://www.example.com/'));
278 * const newWindowTarget = await browser.waitForTarget(
279 * target => target.url() === 'https://www.example.com/',
280 * );
281 * ```
282 */
283 waitForTarget(predicate: (x: Target) => boolean | Promise<boolean>, options?: WaitForTargetOptions): Promise<Target>;
284 /**
285 * Gets a list of all open {@link Page | pages} inside this {@link Browser}.
286 *
287 * If there are multiple {@link BrowserContext | browser contexts}, this
288 * returns all {@link Page | pages} in all
289 * {@link BrowserContext | browser contexts}.
290 *
291 * @remarks Non-visible {@link Page | pages}, such as `"background_page"`,
292 * will not be listed here. You can find them using {@link Target.page}.
293 */
294 pages(): Promise<Page[]>;
295 /**
296 * Gets a string representing this {@link Browser | browser's} name and
297 * version.
298 *
299 * For headless browser, this is similar to `"HeadlessChrome/61.0.3153.0"`. For
300 * non-headless or new-headless, this is similar to `"Chrome/61.0.3153.0"`. For
301 * Firefox, it is similar to `"Firefox/116.0a1"`.
302 *
303 * The format of {@link Browser.version} might change with future releases of
304 * browsers.
305 */
306 abstract version(): Promise<string>;
307 /**
308 * Gets this {@link Browser | browser's} original user agent.
309 *
310 * {@link Page | Pages} can override the user agent with
311 * {@link Page.setUserAgent}.
312 *
313 */
314 abstract userAgent(): Promise<string>;
315 /**
316 * Closes this {@link Browser | browser} and all associated
317 * {@link Page | pages}.
318 */
319 abstract close(): Promise<void>;
320 /**
321 * Disconnects Puppeteer from this {@link Browser | browser}, but leaves the
322 * process running.
323 */
324 abstract disconnect(): Promise<void>;
325 /**
326 * Returns all cookies in the default {@link BrowserContext}.
327 *
328 * @remarks
329 *
330 * Shortcut for
331 * {@link BrowserContext.cookies | browser.defaultBrowserContext().cookies()}.
332 */
333 cookies(): Promise<Cookie[]>;
334 /**
335 * Sets cookies in the default {@link BrowserContext}.
336 *
337 * @remarks
338 *
339 * Shortcut for
340 * {@link BrowserContext.setCookie | browser.defaultBrowserContext().setCookie()}.
341 */
342 setCookie(...cookies: Cookie[]): Promise<void>;
343 /**
344 * Removes cookies from the default {@link BrowserContext}.
345 *
346 * @remarks
347 *
348 * Shortcut for
349 * {@link BrowserContext.deleteCookie | browser.defaultBrowserContext().deleteCookie()}.
350 */
351 deleteCookie(...cookies: Cookie[]): Promise<void>;
352 /**
353 * Whether Puppeteer is connected to this {@link Browser | browser}.
354 *
355 * @deprecated Use {@link Browser | Browser.connected}.
356 */
357 isConnected(): boolean;
358 /**
359 * Whether Puppeteer is connected to this {@link Browser | browser}.
360 */
361 abstract get connected(): boolean;
362
363
364
365 /**
366 * Get debug information from Puppeteer.
367 *
368 * @remarks
369 *
370 * Currently, includes pending protocol calls. In the future, we might add more info.
371 *
372 * @public
373 * @experimental
374 */
375 abstract get debugInfo(): DebugInfo;
376}
377
378/**
379 * {@link BrowserContext} represents individual user contexts within a
380 * {@link Browser | browser}.
381 *
382 * When a {@link Browser | browser} is launched, it has at least one default
383 * {@link BrowserContext | browser context}. Others can be created
384 * using {@link Browser.createBrowserContext}. Each context has isolated storage
385 * (cookies/localStorage/etc.)
386 *
387 * {@link BrowserContext} {@link EventEmitter | emits} various events which are
388 * documented in the {@link BrowserContextEvent} enum.
389 *
390 * If a {@link Page | page} opens another {@link Page | page}, e.g. using
391 * `window.open`, the popup will belong to the parent {@link Page.browserContext
392 * | page's browser context}.
393 *
394 * @example Creating a new {@link BrowserContext | browser context}:
395 *
396 * ```ts
397 * // Create a new browser context
398 * const context = await browser.createBrowserContext();
399 * // Create a new page inside context.
400 * const page = await context.newPage();
401 * // ... do stuff with page ...
402 * await page.goto('https://example.com');
403 * // Dispose context once it's no longer needed.
404 * await context.close();
405 * ```
406 *
407 * @remarks
408 *
409 * In Chrome all non-default contexts are incognito,
410 * and {@link Browser.defaultBrowserContext | default browser context}
411 * might be incognito if you provide the `--incognito` argument when launching
412 * the browser.
413 *
414 * @public
415 */
416export declare abstract class BrowserContext extends EventEmitter<BrowserContextEvents> {
417 #private;
418
419 /**
420 * Gets all active {@link Target | targets} inside this
421 * {@link BrowserContext | browser context}.
422 */
423 abstract targets(): Target[];
424
425
426 /**
427 * Waits until a {@link Target | target} matching the given `predicate`
428 * appears and returns it.
429 *
430 * This will look all open {@link BrowserContext | browser contexts}.
431 *
432 * @example Finding a target for a page opened via `window.open`:
433 *
434 * ```ts
435 * await page.evaluate(() => window.open('https://www.example.com/'));
436 * const newWindowTarget = await browserContext.waitForTarget(
437 * target => target.url() === 'https://www.example.com/',
438 * );
439 * ```
440 */
441 waitForTarget(predicate: (x: Target) => boolean | Promise<boolean>, options?: WaitForTargetOptions): Promise<Target>;
442 /**
443 * Gets a list of all open {@link Page | pages} inside this
444 * {@link BrowserContext | browser context}.
445 *
446 * @remarks Non-visible {@link Page | pages}, such as `"background_page"`,
447 * will not be listed here. You can find them using {@link Target.page}.
448 */
449 abstract pages(): Promise<Page[]>;
450 /**
451 * Grants this {@link BrowserContext | browser context} the given
452 * `permissions` within the given `origin`.
453 *
454 * @example Overriding permissions in the
455 * {@link Browser.defaultBrowserContext | default browser context}:
456 *
457 * ```ts
458 * const context = browser.defaultBrowserContext();
459 * await context.overridePermissions('https://html5demos.com', [
460 * 'geolocation',
461 * ]);
462 * ```
463 *
464 * @param origin - The origin to grant permissions to, e.g.
465 * "https://example.com".
466 * @param permissions - An array of permissions to grant. All permissions that
467 * are not listed here will be automatically denied.
468 */
469 abstract overridePermissions(origin: string, permissions: Permission[]): Promise<void>;
470 /**
471 * Clears all permission overrides for this
472 * {@link BrowserContext | browser context}.
473 *
474 * @example Clearing overridden permissions in the
475 * {@link Browser.defaultBrowserContext | default browser context}:
476 *
477 * ```ts
478 * const context = browser.defaultBrowserContext();
479 * context.overridePermissions('https://example.com', ['clipboard-read']);
480 * // do stuff ..
481 * context.clearPermissionOverrides();
482 * ```
483 */
484 abstract clearPermissionOverrides(): Promise<void>;
485 /**
486 * Creates a new {@link Page | page} in this
487 * {@link BrowserContext | browser context}.
488 */
489 abstract newPage(): Promise<Page>;
490 /**
491 * Gets the {@link Browser | browser} associated with this
492 * {@link BrowserContext | browser context}.
493 */
494 abstract browser(): Browser;
495 /**
496 * Closes this {@link BrowserContext | browser context} and all associated
497 * {@link Page | pages}.
498 *
499 * @remarks The
500 * {@link Browser.defaultBrowserContext | default browser context} cannot be
501 * closed.
502 */
503 abstract close(): Promise<void>;
504 /**
505 * Gets all cookies in the browser context.
506 */
507 abstract cookies(): Promise<Cookie[]>;
508 /**
509 * Sets a cookie in the browser context.
510 */
511 abstract setCookie(...cookies: CookieData[]): Promise<void>;
512 /**
513 * Removes cookie in the browser context
514 * @param cookies - {@link Cookie | cookie} to remove
515 */
516 deleteCookie(...cookies: Cookie[]): Promise<void>;
517 /**
518 * Whether this {@link BrowserContext | browser context} is closed.
519 */
520 get closed(): boolean;
521 /**
522 * Identifier for this {@link BrowserContext | browser context}.
523 */
524 get id(): string | undefined;
525
526
527}
528
529/**
530 * @public
531 */
532export declare const enum BrowserContextEvent {
533 /**
534 * Emitted when the url of a target inside the browser context changes.
535 * Contains a {@link Target} instance.
536 */
537 TargetChanged = "targetchanged",
538 /**
539 * Emitted when a target is created within the browser context, for example
540 * when a new page is opened by
541 * {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/open | window.open}
542 * or by {@link BrowserContext.newPage | browserContext.newPage}
543 *
544 * Contains a {@link Target} instance.
545 */
546 TargetCreated = "targetcreated",
547 /**
548 * Emitted when a target is destroyed within the browser context, for example
549 * when a page is closed. Contains a {@link Target} instance.
550 */
551 TargetDestroyed = "targetdestroyed"
552}
553
554/**
555 * @public
556 */
557export declare interface BrowserContextEvents extends Record<EventType, unknown> {
558 [BrowserContextEvent.TargetChanged]: Target;
559 [BrowserContextEvent.TargetCreated]: Target;
560 [BrowserContextEvent.TargetDestroyed]: Target;
561}
562
563/**
564 * @public
565 */
566export declare interface BrowserContextOptions {
567 /**
568 * Proxy server with optional port to use for all requests.
569 * Username and password can be set in `Page.authenticate`.
570 */
571 proxyServer?: string;
572 /**
573 * Bypass the proxy for the given list of hosts.
574 */
575 proxyBypassList?: string[];
576 /**
577 * Behavior definition for when downloading a file.
578 *
579 * @remarks
580 * If not set, the default behavior will be used.
581 */
582 downloadBehavior?: DownloadBehavior;
583}
584
585/**
586 * All the events a {@link Browser | browser instance} may emit.
587 *
588 * @public
589 */
590export declare const enum BrowserEvent {
591 /**
592 * Emitted when Puppeteer gets disconnected from the browser instance. This
593 * might happen because either:
594 *
595 * - The browser closes/crashes or
596 * - {@link Browser.disconnect} was called.
597 */
598 Disconnected = "disconnected",
599 /**
600 * Emitted when the URL of a target changes. Contains a {@link Target}
601 * instance.
602 *
603 * @remarks Note that this includes target changes in all browser
604 * contexts.
605 */
606 TargetChanged = "targetchanged",
607 /**
608 * Emitted when a target is created, for example when a new page is opened by
609 * {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/open | window.open}
610 * or by {@link Browser.newPage | browser.newPage}
611 *
612 * Contains a {@link Target} instance.
613 *
614 * @remarks Note that this includes target creations in all browser
615 * contexts.
616 */
617 TargetCreated = "targetcreated",
618 /**
619 * Emitted when a target is destroyed, for example when a page is closed.
620 * Contains a {@link Target} instance.
621 *
622 * @remarks Note that this includes target destructions in all browser
623 * contexts.
624 */
625 TargetDestroyed = "targetdestroyed",
626
627}
628
629/**
630 * @public
631 */
632export declare interface BrowserEvents extends Record<EventType, unknown> {
633 [BrowserEvent.Disconnected]: undefined;
634 [BrowserEvent.TargetCreated]: Target;
635 [BrowserEvent.TargetDestroyed]: Target;
636 [BrowserEvent.TargetChanged]: Target;
637
638}
639
640/**
641 * Describes a launcher - a class that is able to create and launch a browser instance.
642 *
643 * @public
644 */
645export declare abstract class BrowserLauncher {
646 #private;
647
648
649 get browser(): SupportedBrowser;
650 launch(options?: LaunchOptions): Promise<Browser>;
651 abstract executablePath(channel?: ChromeReleaseChannel, validatePath?: boolean): string;
652 abstract defaultArgs(object: LaunchOptions): string[];
653
654
655
656
657
658
659
660
661
662
663}
664
665/**
666 * @public
667 */
668export declare type CDPEvents = {
669 [Property in keyof ProtocolMapping.Events]: ProtocolMapping.Events[Property][0];
670};
671
672/**
673 * The `CDPSession` instances are used to talk raw Chrome Devtools Protocol.
674 *
675 * @remarks
676 *
677 * Protocol methods can be called with {@link CDPSession.send} method and protocol
678 * events can be subscribed to with `CDPSession.on` method.
679 *
680 * Useful links: {@link https://chromedevtools.github.io/devtools-protocol/ | DevTools Protocol Viewer}
681 * and {@link https://github.com/aslushnikov/getting-started-with-cdp/blob/HEAD/README.md | Getting Started with DevTools Protocol}.
682 *
683 * @example
684 *
685 * ```ts
686 * const client = await page.createCDPSession();
687 * await client.send('Animation.enable');
688 * client.on('Animation.animationCreated', () =>
689 * console.log('Animation created!'),
690 * );
691 * const response = await client.send('Animation.getPlaybackRate');
692 * console.log('playback rate is ' + response.playbackRate);
693 * await client.send('Animation.setPlaybackRate', {
694 * playbackRate: response.playbackRate / 2,
695 * });
696 * ```
697 *
698 * @public
699 */
700export declare abstract class CDPSession extends EventEmitter<CDPSessionEvents> {
701
702 abstract connection(): Connection | undefined;
703
704 abstract send<T extends keyof ProtocolMapping.Commands>(method: T, params?: ProtocolMapping.Commands[T]['paramsType'][0], options?: CommandOptions): Promise<ProtocolMapping.Commands[T]['returnType']>;
705 /**
706 * Detaches the cdpSession from the target. Once detached, the cdpSession object
707 * won't emit any events and can't be used to send messages.
708 */
709 abstract detach(): Promise<void>;
710 /**
711 * Returns the session's id.
712 */
713 abstract id(): string;
714}
715
716/**
717 * Events that the CDPSession class emits.
718 *
719 * @public
720 */
721export declare namespace CDPSessionEvent {
722
723
724
725 const SessionAttached: "sessionattached";
726 const SessionDetached: "sessiondetached";
727}
728
729/**
730 * @public
731 */
732export declare interface CDPSessionEvents extends CDPEvents, Record<EventType, unknown> {
733
734
735
736 [CDPSessionEvent.SessionAttached]: CDPSession;
737 [CDPSessionEvent.SessionDetached]: CDPSession;
738}
739
740/**
741 * @public
742 */
743export declare interface ChromeHeadlessShellSettings {
744 /**
745 * Tells Puppeteer to not download the browser during installation.
746 *
747 * Can be overridden by `PUPPETEER_CHROME_HEADLESS_SHELL_SKIP_DOWNLOAD`
748 * or `PUPPETEER_SKIP_CHROME_HEADLESS_SHELL_DOWNLOAD`.
749 *
750 * @defaultValue false
751 */
752 skipDownload?: boolean;
753 /**
754 * Specifies the URL prefix that is used to download the browser.
755 *
756 * Can be overridden by `PUPPETEER_CHROME_HEADLESS_SHELL_DOWNLOAD_BASE_URL`.
757 *
758 * @remarks
759 * This must include the protocol and may even need a path prefix.
760 * This must **not** include a trailing slash similar to the default.
761 *
762 * @defaultValue https://storage.googleapis.com/chrome-for-testing-public
763 */
764 downloadBaseUrl?: string;
765 /**
766 * Specifies a certain version of the browser you'd like Puppeteer to use.
767 *
768 * Can be overridden by `PUPPETEER_CHROME_HEADLESS_SHELL_VERSION`.
769 *
770 * See {@link PuppeteerNode.launch | puppeteer.launch} on how executable path
771 * is inferred.
772 *
773 * @example 119.0.6045.105
774 * @defaultValue The pinned browser version supported by the current Puppeteer
775 * version.
776 */
777 version?: string;
778}
779
780/**
781 * @public
782 */
783export declare type ChromeReleaseChannel = 'chrome' | 'chrome-beta' | 'chrome-canary' | 'chrome-dev';
784
785/**
786 * @public
787 */
788export declare interface ChromeSettings {
789 /**
790 * Tells Puppeteer to not download the browser during installation.
791 *
792 * Can be overridden by `PUPPETEER_CHROME_SKIP_DOWNLOAD`.
793 *
794 * @defaultValue false
795 */
796 skipDownload?: boolean;
797 /**
798 * Specifies the URL prefix that is used to download the browser.
799 *
800 * Can be overridden by `PUPPETEER_CHROME_DOWNLOAD_BASE_URL`.
801 *
802 * @remarks
803 * This must include the protocol and may even need a path prefix.
804 * This must **not** include a trailing slash similar to the default.
805 *
806 * @defaultValue https://storage.googleapis.com/chrome-for-testing-public
807 */
808 downloadBaseUrl?: string;
809 /**
810 * Specifies a certain version of the browser you'd like Puppeteer to use.
811 *
812 * Can be overridden by `PUPPETEER_CHROME_VERSION`
813 * or `PUPPETEER_SKIP_CHROME_DOWNLOAD`.
814 *
815 * See {@link PuppeteerNode.launch | puppeteer.launch} on how executable path
816 * is inferred.
817 *
818 * @example 119.0.6045.105
819 * @defaultValue The pinned browser version supported by the current Puppeteer
820 * version.
821 */
822 version?: string;
823}
824
825/**
826 * @public
827 */
828export declare interface ClickOptions extends MouseClickOptions {
829 /**
830 * Offset for the clickable point relative to the top-left corner of the border box.
831 */
832 offset?: Offset;
833}
834
835/**
836 * @public
837 */
838export declare interface CommandOptions {
839 timeout: number;
840}
841
842/**
843 * @public
844 */
845export declare interface CommonEventEmitter<Events extends Record<EventType, unknown>> {
846 on<Key extends keyof Events>(type: Key, handler: Handler<Events[Key]>): this;
847 off<Key extends keyof Events>(type: Key, handler?: Handler<Events[Key]>): this;
848 emit<Key extends keyof Events>(type: Key, event: Events[Key]): boolean;
849 once<Key extends keyof Events>(type: Key, handler: Handler<Events[Key]>): this;
850 listenerCount(event: keyof Events): number;
851 removeAllListeners(event?: keyof Events): this;
852}
853
854/**
855 * Defines options to configure Puppeteer's behavior during installation and
856 * runtime.
857 *
858 * See individual properties for more information.
859 *
860 * @public
861 */
862export declare interface Configuration {
863 /**
864 * Defines the directory to be used by Puppeteer for caching.
865 *
866 * Can be overridden by `PUPPETEER_CACHE_DIR`.
867 *
868 * @defaultValue `path.join(os.homedir(), '.cache', 'puppeteer')`
869 */
870 cacheDirectory?: string;
871 /**
872 * Specifies an executable path to be used in
873 * {@link PuppeteerNode.launch | puppeteer.launch}.
874 *
875 * Can be overridden by `PUPPETEER_EXECUTABLE_PATH`.
876 *
877 * @defaultValue **Auto-computed.**
878 */
879 executablePath?: string;
880 /**
881 * Specifies which browser you'd like Puppeteer to use.
882 *
883 * Can be overridden by `PUPPETEER_BROWSER`.
884 *
885 * @defaultValue `chrome`
886 */
887 defaultBrowser?: SupportedBrowser;
888 /**
889 * Defines the directory to be used by Puppeteer for creating temporary files.
890 *
891 * Can be overridden by `PUPPETEER_TMP_DIR`.
892 *
893 * @defaultValue `os.tmpdir()`
894 */
895 temporaryDirectory?: string;
896 /**
897 * Tells Puppeteer to not download during installation.
898 *
899 * Can be overridden by `PUPPETEER_SKIP_DOWNLOAD`.
900 */
901 skipDownload?: boolean;
902 /**
903 * Tells Puppeteer to log at the given level.
904 *
905 * @defaultValue `warn`
906 */
907 logLevel?: 'silent' | 'error' | 'warn';
908 /**
909 * Defines experimental options for Puppeteer.
910 */
911 experiments?: ExperimentsConfiguration;
912 chrome?: ChromeSettings;
913 ['chrome-headless-shell']?: ChromeHeadlessShellSettings;
914 firefox?: FirefoxSettings;
915}
916
917/**
918 * @public
919 */
920export declare const
921/**
922* @public
923*/
924/**
925 * @public
926 */
927connect: (options: Puppeteer_2.ConnectOptions) => Promise<Puppeteer_2.Browser>;
928
929/**
930 * @public
931 */
932export declare class Connection extends EventEmitter<CDPSessionEvents> {
933 #private;
934 constructor(url: string, transport: ConnectionTransport, delay?: number, timeout?: number, rawErrors?: boolean);
935 static fromSession(session: CDPSession): Connection | undefined;
936
937 get timeout(): number;
938
939
940 /**
941 * @param sessionId - The session id
942 * @returns The current CDP session if it exists
943 */
944 session(sessionId: string): CDPSession | null;
945 url(): string;
946 send<T extends keyof ProtocolMapping.Commands>(method: T, params?: ProtocolMapping.Commands[T]['paramsType'][0], options?: CommandOptions): Promise<ProtocolMapping.Commands[T]['returnType']>;
947
948
949
950 dispose(): void;
951
952
953 /**
954 * @param targetInfo - The target info
955 * @returns The CDP session that is created
956 */
957 createSession(targetInfo: Protocol.Target.TargetInfo): Promise<CDPSession>;
958
959}
960
961/**
962 * @license
963 * Copyright 2020 Google Inc.
964 * SPDX-License-Identifier: Apache-2.0
965 */
966/**
967 * @public
968 */
969export declare interface ConnectionTransport {
970 send(message: string): void;
971 close(): void;
972 onmessage?: (message: string) => void;
973 onclose?: () => void;
974}
975
976/**
977 * Generic browser options that can be passed when launching any browser or when
978 * connecting to an existing browser instance.
979 * @public
980 */
981export declare interface ConnectOptions {
982 /**
983 * Whether to ignore HTTPS errors during navigation.
984 * @defaultValue `false`
985 */
986 acceptInsecureCerts?: boolean;
987 /**
988 * Sets the viewport for each page.
989 *
990 * @defaultValue '\{width: 800, height: 600\}'
991 */
992 defaultViewport?: Viewport | null;
993 /**
994 * Sets the download behavior for the context.
995 */
996 downloadBehavior?: DownloadBehavior;
997 /**
998 * Slows down Puppeteer operations by the specified amount of milliseconds to
999 * aid debugging.
1000 */
1001 slowMo?: number;
1002 /**
1003 * Callback to decide if Puppeteer should connect to a given target or not.
1004 */
1005 targetFilter?: TargetFilterCallback;
1006
1007 /**
1008 * @defaultValue Determined at run time:
1009 *
1010 * - Launching Chrome - 'cdp'.
1011 *
1012 * - Launching Firefox - 'webDriverBiDi'.
1013 *
1014 * - Connecting to a browser - 'cdp'.
1015 *
1016 * @public
1017 */
1018 protocol?: ProtocolType;
1019 /**
1020 * Timeout setting for individual protocol (CDP) calls.
1021 *
1022 * @defaultValue `180_000`
1023 */
1024 protocolTimeout?: number;
1025 browserWSEndpoint?: string;
1026 browserURL?: string;
1027 transport?: ConnectionTransport;
1028 /**
1029 * Headers to use for the web socket connection.
1030 * @remarks
1031 * Only works in the Node.js environment.
1032 */
1033 headers?: Record<string, string>;
1034 /**
1035 * WebDriver BiDi capabilities passed to BiDi `session.new`.
1036 *
1037 * @remarks
1038 * Only works for `protocol="webDriverBiDi"` and {@link Puppeteer.connect}.
1039 */
1040 capabilities?: SupportedWebDriverCapabilities;
1041}
1042
1043/**
1044 * ConsoleMessage objects are dispatched by page via the 'console' event.
1045 * @public
1046 */
1047export declare class ConsoleMessage {
1048 #private;
1049
1050 /**
1051 * The type of the console message.
1052 */
1053 type(): ConsoleMessageType;
1054 /**
1055 * The text of the console message.
1056 */
1057 text(): string;
1058 /**
1059 * An array of arguments passed to the console.
1060 */
1061 args(): JSHandle[];
1062 /**
1063 * The location of the console message.
1064 */
1065 location(): ConsoleMessageLocation;
1066 /**
1067 * The array of locations on the stack of the console message.
1068 */
1069 stackTrace(): ConsoleMessageLocation[];
1070}
1071
1072/**
1073 * @public
1074 */
1075export declare interface ConsoleMessageLocation {
1076 /**
1077 * URL of the resource if known or `undefined` otherwise.
1078 */
1079 url?: string;
1080 /**
1081 * 0-based line number in the resource if known or `undefined` otherwise.
1082 */
1083 lineNumber?: number;
1084 /**
1085 * 0-based column number in the resource if known or `undefined` otherwise.
1086 */
1087 columnNumber?: number;
1088}
1089
1090/**
1091 * The supported types for console messages.
1092 * @public
1093 */
1094export declare type ConsoleMessageType = 'log' | 'debug' | 'info' | 'error' | 'warn' | 'dir' | 'dirxml' | 'table' | 'trace' | 'clear' | 'startGroup' | 'startGroupCollapsed' | 'endGroup' | 'assert' | 'profile' | 'profileEnd' | 'count' | 'timeEnd' | 'verbose';
1095
1096/**
1097 * @public
1098 */
1099export declare interface ContinueRequestOverrides {
1100 /**
1101 * If set, the request URL will change. This is not a redirect.
1102 */
1103 url?: string;
1104 method?: string;
1105 postData?: string;
1106 headers?: Record<string, string>;
1107}
1108
1109export declare function convertCookiesPartitionKeyFromPuppeteerToCdp(partitionKey: CookiePartitionKey | string | undefined): Protocol.Network.CookiePartitionKey | undefined;
1110
1111/**
1112 * Represents a cookie object.
1113 *
1114 * @public
1115 */
1116export declare interface Cookie {
1117 /**
1118 * Cookie name.
1119 */
1120 name: string;
1121 /**
1122 * Cookie value.
1123 */
1124 value: string;
1125 /**
1126 * Cookie domain.
1127 */
1128 domain: string;
1129 /**
1130 * Cookie path.
1131 */
1132 path: string;
1133 /**
1134 * Cookie expiration date as the number of seconds since the UNIX epoch. Set to `-1` for
1135 * session cookies
1136 */
1137 expires: number;
1138 /**
1139 * Cookie size.
1140 */
1141 size: number;
1142 /**
1143 * True if cookie is http-only.
1144 */
1145 httpOnly: boolean;
1146 /**
1147 * True if cookie is secure.
1148 */
1149 secure: boolean;
1150 /**
1151 * True in case of session cookie.
1152 */
1153 session: boolean;
1154 /**
1155 * Cookie SameSite type.
1156 */
1157 sameSite?: CookieSameSite;
1158 /**
1159 * Cookie Priority. Supported only in Chrome.
1160 */
1161 priority?: CookiePriority;
1162 /**
1163 * True if cookie is SameParty. Supported only in Chrome.
1164 */
1165 sameParty?: boolean;
1166 /**
1167 * Cookie source scheme type. Supported only in Chrome.
1168 */
1169 sourceScheme?: CookieSourceScheme;
1170 /**
1171 * Cookie partition key. In Chrome, it is the top-level site the
1172 * partitioned cookie is available in. In Firefox, it matches the
1173 * source origin
1174 * (https://w3c.github.io/webdriver-bidi/#type-storage-PartitionKey).
1175 */
1176 partitionKey?: CookiePartitionKey | string;
1177 /**
1178 * True if cookie partition key is opaque. Supported only in Chrome.
1179 */
1180 partitionKeyOpaque?: boolean;
1181}
1182
1183/**
1184 * Cookie parameter object used to set cookies in the browser-level cookies
1185 * API.
1186 *
1187 * @public
1188 */
1189export declare interface CookieData {
1190 /**
1191 * Cookie name.
1192 */
1193 name: string;
1194 /**
1195 * Cookie value.
1196 */
1197 value: string;
1198 /**
1199 * Cookie domain.
1200 */
1201 domain: string;
1202 /**
1203 * Cookie path.
1204 */
1205 path?: string;
1206 /**
1207 * True if cookie is secure.
1208 */
1209 secure?: boolean;
1210 /**
1211 * True if cookie is http-only.
1212 */
1213 httpOnly?: boolean;
1214 /**
1215 * Cookie SameSite type.
1216 */
1217 sameSite?: CookieSameSite;
1218 /**
1219 * Cookie expiration date, session cookie if not set
1220 */
1221 expires?: number;
1222 /**
1223 * Cookie Priority. Supported only in Chrome.
1224 */
1225 priority?: CookiePriority;
1226 /**
1227 * True if cookie is SameParty. Supported only in Chrome.
1228 */
1229 sameParty?: boolean;
1230 /**
1231 * Cookie source scheme type. Supported only in Chrome.
1232 */
1233 sourceScheme?: CookieSourceScheme;
1234 /**
1235 * Cookie partition key. In Chrome, it matches the top-level site the
1236 * partitioned cookie is available in. In Firefox, it matches the
1237 * source origin
1238 * (https://w3c.github.io/webdriver-bidi/#type-storage-PartitionKey).
1239 */
1240 partitionKey?: CookiePartitionKey | string;
1241}
1242
1243/**
1244 * Cookie parameter object used to set cookies in the page-level cookies
1245 * API.
1246 *
1247 * @public
1248 */
1249export declare interface CookieParam {
1250 /**
1251 * Cookie name.
1252 */
1253 name: string;
1254 /**
1255 * Cookie value.
1256 */
1257 value: string;
1258 /**
1259 * The request-URI to associate with the setting of the cookie. This value can affect
1260 * the default domain, path, and source scheme values of the created cookie.
1261 */
1262 url?: string;
1263 /**
1264 * Cookie domain.
1265 */
1266 domain?: string;
1267 /**
1268 * Cookie path.
1269 */
1270 path?: string;
1271 /**
1272 * True if cookie is secure.
1273 */
1274 secure?: boolean;
1275 /**
1276 * True if cookie is http-only.
1277 */
1278 httpOnly?: boolean;
1279 /**
1280 * Cookie SameSite type.
1281 */
1282 sameSite?: CookieSameSite;
1283 /**
1284 * Cookie expiration date, session cookie if not set
1285 */
1286 expires?: number;
1287 /**
1288 * Cookie Priority. Supported only in Chrome.
1289 */
1290 priority?: CookiePriority;
1291 /**
1292 * True if cookie is SameParty. Supported only in Chrome.
1293 */
1294 sameParty?: boolean;
1295 /**
1296 * Cookie source scheme type. Supported only in Chrome.
1297 */
1298 sourceScheme?: CookieSourceScheme;
1299 /**
1300 * Cookie partition key. In Chrome, it matches the top-level site the
1301 * partitioned cookie is available in. In Firefox, it matches the
1302 * source origin
1303 * (https://w3c.github.io/webdriver-bidi/#type-storage-PartitionKey).
1304 */
1305 partitionKey?: CookiePartitionKey | string;
1306}
1307
1308/**
1309 * Represents a cookie partition key in Chrome.
1310 *
1311 * @public
1312 */
1313export declare interface CookiePartitionKey {
1314 /**
1315 * The site of the top-level URL the browser was visiting at the start of the request
1316 * to the endpoint that set the cookie.
1317 *
1318 * In Chrome, maps to the CDP's `topLevelSite` partition key.
1319 */
1320 sourceOrigin: string;
1321 /**
1322 * Indicates if the cookie has any ancestors that are cross-site to
1323 * the topLevelSite.
1324 *
1325 * Supported only in Chrome.
1326 */
1327 hasCrossSiteAncestor?: boolean;
1328}
1329
1330/**
1331 * Represents the cookie's 'Priority' status:
1332 * https://tools.ietf.org/html/draft-west-cookie-priority-00
1333 *
1334 * @public
1335 */
1336export declare type CookiePriority = 'Low' | 'Medium' | 'High';
1337
1338/**
1339 * @license
1340 * Copyright 2024 Google Inc.
1341 * SPDX-License-Identifier: Apache-2.0
1342 */
1343/**
1344 * Represents the cookie's 'SameSite' status:
1345 * https://tools.ietf.org/html/draft-west-first-party-cookies
1346 *
1347 * @public
1348 */
1349export declare type CookieSameSite = 'Strict' | 'Lax' | 'None';
1350
1351/**
1352 * Represents the source scheme of the origin that originally set the cookie. A value of
1353 * "Unset" allows protocol clients to emulate legacy cookie scope for the scheme.
1354 * This is a temporary ability and it will be removed in the future.
1355 *
1356 * @public
1357 */
1358export declare type CookieSourceScheme = 'Unset' | 'NonSecure' | 'Secure';
1359
1360/**
1361 * The Coverage class provides methods to gather information about parts of
1362 * JavaScript and CSS that were used by the page.
1363 *
1364 * @remarks
1365 * To output coverage in a form consumable by {@link https://github.com/istanbuljs | Istanbul},
1366 * see {@link https://github.com/istanbuljs/puppeteer-to-istanbul | puppeteer-to-istanbul}.
1367 *
1368 * @example
1369 * An example of using JavaScript and CSS coverage to get percentage of initially
1370 * executed code:
1371 *
1372 * ```ts
1373 * // Enable both JavaScript and CSS coverage
1374 * await Promise.all([
1375 * page.coverage.startJSCoverage(),
1376 * page.coverage.startCSSCoverage(),
1377 * ]);
1378 * // Navigate to page
1379 * await page.goto('https://example.com');
1380 * // Disable both JavaScript and CSS coverage
1381 * const [jsCoverage, cssCoverage] = await Promise.all([
1382 * page.coverage.stopJSCoverage(),
1383 * page.coverage.stopCSSCoverage(),
1384 * ]);
1385 * let totalBytes = 0;
1386 * let usedBytes = 0;
1387 * const coverage = [...jsCoverage, ...cssCoverage];
1388 * for (const entry of coverage) {
1389 * totalBytes += entry.text.length;
1390 * for (const range of entry.ranges) usedBytes += range.end - range.start - 1;
1391 * }
1392 * console.log(`Bytes used: ${(usedBytes / totalBytes) * 100}%`);
1393 * ```
1394 *
1395 * @public
1396 */
1397export declare class Coverage {
1398 #private;
1399
1400
1401 /**
1402 * @param options - Set of configurable options for coverage defaults to
1403 * `resetOnNavigation : true, reportAnonymousScripts : false,`
1404 * `includeRawScriptCoverage : false, useBlockCoverage : true`
1405 * @returns Promise that resolves when coverage is started.
1406 *
1407 * @remarks
1408 * Anonymous scripts are ones that don't have an associated url. These are
1409 * scripts that are dynamically created on the page using `eval` or
1410 * `new Function`. If `reportAnonymousScripts` is set to `true`, anonymous
1411 * scripts URL will start with `debugger://VM` (unless a magic //# sourceURL
1412 * comment is present, in which case that will the be URL).
1413 */
1414 startJSCoverage(options?: JSCoverageOptions): Promise<void>;
1415 /**
1416 * Promise that resolves to the array of coverage reports for
1417 * all scripts.
1418 *
1419 * @remarks
1420 * JavaScript Coverage doesn't include anonymous scripts by default.
1421 * However, scripts with sourceURLs are reported.
1422 */
1423 stopJSCoverage(): Promise<JSCoverageEntry[]>;
1424 /**
1425 * @param options - Set of configurable options for coverage, defaults to
1426 * `resetOnNavigation : true`
1427 * @returns Promise that resolves when coverage is started.
1428 */
1429 startCSSCoverage(options?: CSSCoverageOptions): Promise<void>;
1430 /**
1431 * Promise that resolves to the array of coverage reports
1432 * for all stylesheets.
1433 *
1434 * @remarks
1435 * CSS Coverage doesn't include dynamically injected style tags
1436 * without sourceURLs.
1437 */
1438 stopCSSCoverage(): Promise<CoverageEntry[]>;
1439}
1440
1441/**
1442 * The CoverageEntry class represents one entry of the coverage report.
1443 * @public
1444 */
1445export declare interface CoverageEntry {
1446 /**
1447 * The URL of the style sheet or script.
1448 */
1449 url: string;
1450 /**
1451 * The content of the style sheet or script.
1452 */
1453 text: string;
1454 /**
1455 * The covered range as start and end positions.
1456 */
1457 ranges: Array<{
1458 start: number;
1459 end: number;
1460 }>;
1461}
1462
1463/**
1464 * @public
1465 */
1466export declare interface Credentials {
1467 username: string;
1468 password: string;
1469}
1470
1471/**
1472 * @public
1473 */
1474export declare class CSSCoverage {
1475 #private;
1476 constructor(client: CDPSession);
1477
1478 start(options?: {
1479 resetOnNavigation?: boolean;
1480 }): Promise<void>;
1481 stop(): Promise<CoverageEntry[]>;
1482}
1483
1484/**
1485 * Set of configurable options for CSS coverage.
1486 * @public
1487 */
1488export declare interface CSSCoverageOptions {
1489 /**
1490 * Whether to reset coverage on every navigation.
1491 */
1492 resetOnNavigation?: boolean;
1493}
1494
1495/**
1496 * @public
1497 */
1498export declare interface CustomQueryHandler {
1499 /**
1500 * Searches for a {@link https://developer.mozilla.org/en-US/docs/Web/API/Node | Node} matching the given `selector` from {@link https://developer.mozilla.org/en-US/docs/Web/API/Node | node}.
1501 */
1502 queryOne?: (node: Node, selector: string) => Node | null;
1503 /**
1504 * Searches for some {@link https://developer.mozilla.org/en-US/docs/Web/API/Node | Nodes} matching the given `selector` from {@link https://developer.mozilla.org/en-US/docs/Web/API/Node | node}.
1505 */
1506 queryAll?: (node: Node, selector: string) => Iterable<Node>;
1507}
1508
1509declare interface CustomQuerySelector {
1510 querySelector(root: Node, selector: string): Awaitable<Node | null>;
1511 querySelectorAll(root: Node, selector: string): AwaitableIterable<Node>;
1512}
1513
1514/**
1515 * This class mimics the injected {@link CustomQuerySelectorRegistry}.
1516 */
1517declare class CustomQuerySelectorRegistry {
1518 #private;
1519 register(name: string, handler: CustomQueryHandler): void;
1520 unregister(name: string): void;
1521 get(name: string): CustomQuerySelector | undefined;
1522 clear(): void;
1523}
1524
1525declare namespace CustomQuerySelectors {
1526 export {
1527 CustomQuerySelector,
1528 customQuerySelectors
1529 }
1530}
1531
1532declare const customQuerySelectors: CustomQuerySelectorRegistry;
1533
1534/**
1535 * @public
1536 * @experimental
1537 */
1538export declare interface DebugInfo {
1539 pendingProtocolErrors: Error[];
1540}
1541
1542/**
1543 * The default cooperative request interception resolution priority
1544 *
1545 * @public
1546 */
1547export declare const DEFAULT_INTERCEPT_RESOLUTION_PRIORITY = 0;
1548
1549/**
1550 * @public
1551 */
1552export declare const
1553/**
1554* @public
1555*/
1556/**
1557 * @public
1558 */
1559defaultArgs: (options?: Puppeteer_2.LaunchOptions) => string[];
1560
1561/**
1562 * @public
1563 */
1564export declare interface DeleteCookiesRequest {
1565 /**
1566 * Name of the cookies to remove.
1567 */
1568 name: string;
1569 /**
1570 * If specified, deletes all the cookies with the given name where domain and path match
1571 * provided URL. Otherwise, deletes only cookies related to the current page's domain.
1572 */
1573 url?: string;
1574 /**
1575 * If specified, deletes only cookies with the exact domain.
1576 */
1577 domain?: string;
1578 /**
1579 * If specified, deletes only cookies with the exact path.
1580 */
1581 path?: string;
1582 /**
1583 * If specified, deletes cookies in the given partition key. In
1584 * Chrome, partitionKey matches the top-level site the partitioned
1585 * cookie is available in. In Firefox, it matches the source origin
1586 * (https://w3c.github.io/webdriver-bidi/#type-storage-PartitionKey).
1587 */
1588 partitionKey?: CookiePartitionKey | string;
1589}
1590
1591/**
1592 * @public
1593 */
1594export declare interface Device {
1595 userAgent: string;
1596 viewport: Viewport;
1597}
1598
1599/**
1600 * Device request prompts let you respond to the page requesting for a device
1601 * through an API like WebBluetooth.
1602 *
1603 * @remarks
1604 * `DeviceRequestPrompt` instances are returned via the
1605 * {@link Page.waitForDevicePrompt} method.
1606 *
1607 * @example
1608 *
1609 * ```ts
1610 * const [devicePrompt] = Promise.all([
1611 * page.waitForDevicePrompt(),
1612 * page.click('#connect-bluetooth'),
1613 * ]);
1614 * await devicePrompt.select(
1615 * await devicePrompt.waitForDevice(({name}) => name.includes('My Device')),
1616 * );
1617 * ```
1618 *
1619 * @public
1620 */
1621export declare class DeviceRequestPrompt {
1622 #private;
1623 /**
1624 * Current list of selectable devices.
1625 */
1626 devices: DeviceRequestPromptDevice[];
1627
1628 /**
1629 * Resolve to the first device in the prompt matching a filter.
1630 */
1631 waitForDevice(filter: (device: DeviceRequestPromptDevice) => boolean, options?: WaitTimeoutOptions): Promise<DeviceRequestPromptDevice>;
1632 /**
1633 * Select a device in the prompt's list.
1634 */
1635 select(device: DeviceRequestPromptDevice): Promise<void>;
1636 /**
1637 * Cancel the prompt.
1638 */
1639 cancel(): Promise<void>;
1640}
1641
1642/**
1643 * Device in a request prompt.
1644 *
1645 * @public
1646 */
1647export declare class DeviceRequestPromptDevice {
1648 /**
1649 * Device id during a prompt.
1650 */
1651 id: string;
1652 /**
1653 * Device name as it appears in a prompt.
1654 */
1655 name: string;
1656
1657}
1658
1659/**
1660 * Dialog instances are dispatched by the {@link Page} via the `dialog` event.
1661 *
1662 * @remarks
1663 *
1664 * @example
1665 *
1666 * ```ts
1667 * import puppeteer from 'puppeteer';
1668 *
1669 * (async () => {
1670 * const browser = await puppeteer.launch();
1671 * const page = await browser.newPage();
1672 * page.on('dialog', async dialog => {
1673 * console.log(dialog.message());
1674 * await dialog.dismiss();
1675 * await browser.close();
1676 * });
1677 * page.evaluate(() => alert('1'));
1678 * })();
1679 * ```
1680 *
1681 * @public
1682 */
1683export declare abstract class Dialog {
1684 #private;
1685
1686
1687 /**
1688 * The type of the dialog.
1689 */
1690 type(): Protocol.Page.DialogType;
1691 /**
1692 * The message displayed in the dialog.
1693 */
1694 message(): string;
1695 /**
1696 * The default value of the prompt, or an empty string if the dialog
1697 * is not a `prompt`.
1698 */
1699 defaultValue(): string;
1700
1701 /**
1702 * A promise that resolves when the dialog has been accepted.
1703 *
1704 * @param promptText - optional text that will be entered in the dialog
1705 * prompt. Has no effect if the dialog's type is not `prompt`.
1706 *
1707 */
1708 accept(promptText?: string): Promise<void>;
1709 /**
1710 * A promise which will resolve once the dialog has been dismissed
1711 */
1712 dismiss(): Promise<void>;
1713}
1714
1715/**
1716 * @public
1717 */
1718export declare interface DownloadBehavior {
1719 /**
1720 * Whether to allow all or deny all download requests, or use default behavior if
1721 * available.
1722 *
1723 * @remarks
1724 * Setting this to `allowAndName` will name all files according to their download guids.
1725 */
1726 policy: DownloadPolicy;
1727 /**
1728 * The default path to save downloaded files to.
1729 *
1730 * @remarks
1731 * Setting this is required if behavior is set to `allow` or `allowAndName`.
1732 */
1733 downloadPath?: string;
1734}
1735
1736/**
1737 * @license
1738 * Copyright 2024 Google Inc.
1739 * SPDX-License-Identifier: Apache-2.0
1740 */
1741/**
1742 * @public
1743 */
1744export declare type DownloadPolicy = 'deny' | 'allow' | 'allowAndName' | 'default';
1745
1746/**
1747 * @public
1748 */
1749export declare type ElementFor<TagName extends keyof HTMLElementTagNameMap | keyof SVGElementTagNameMap> = TagName extends keyof HTMLElementTagNameMap ? HTMLElementTagNameMap[TagName] : TagName extends keyof SVGElementTagNameMap ? SVGElementTagNameMap[TagName] : never;
1750
1751/**
1752 * ElementHandle represents an in-page DOM element.
1753 *
1754 * @remarks
1755 * ElementHandles can be created with the {@link Page.$} method.
1756 *
1757 * ```ts
1758 * import puppeteer from 'puppeteer';
1759 *
1760 * (async () => {
1761 * const browser = await puppeteer.launch();
1762 * const page = await browser.newPage();
1763 * await page.goto('https://example.com');
1764 * const hrefElement = await page.$('a');
1765 * await hrefElement.click();
1766 * // ...
1767 * })();
1768 * ```
1769 *
1770 * ElementHandle prevents the DOM element from being garbage-collected unless the
1771 * handle is {@link JSHandle.dispose | disposed}. ElementHandles are auto-disposed
1772 * when their origin frame gets navigated.
1773 *
1774 * ElementHandle instances can be used as arguments in {@link Page.$eval} and
1775 * {@link Page.evaluate} methods.
1776 *
1777 * If you're using TypeScript, ElementHandle takes a generic argument that
1778 * denotes the type of element the handle is holding within. For example, if you
1779 * have a handle to a `<select>` element, you can type it as
1780 * `ElementHandle<HTMLSelectElement>` and you get some nicer type checks.
1781 *
1782 * @public
1783 */
1784export declare abstract class ElementHandle<ElementType extends Node = Element> extends JSHandle<ElementType> {
1785 #private;
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801 /**
1802 * Frame corresponding to the current handle.
1803 */
1804 abstract get frame(): Frame;
1805 /**
1806 * Queries the current element for an element matching the given selector.
1807 *
1808 * @param selector -
1809 * {@link https://pptr.dev/guides/page-interactions#selectors | selector}
1810 * to query the page for.
1811 * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors | CSS selectors}
1812 * can be passed as-is and a
1813 * {@link https://pptr.dev/guides/page-interactions#non-css-selectors | Puppeteer-specific selector syntax}
1814 * allows quering by
1815 * {@link https://pptr.dev/guides/page-interactions#text-selectors--p-text | text},
1816 * {@link https://pptr.dev/guides/page-interactions#aria-selectors--p-aria | a11y role and name},
1817 * and
1818 * {@link https://pptr.dev/guides/page-interactions#xpath-selectors--p-xpath | xpath}
1819 * and
1820 * {@link https://pptr.dev/guides/page-interactions#querying-elements-in-shadow-dom | combining these queries across shadow roots}.
1821 * Alternatively, you can specify the selector type using a
1822 * {@link https://pptr.dev/guides/page-interactions#prefixed-selector-syntax | prefix}.
1823 * @returns A {@link ElementHandle | element handle} to the first element
1824 * matching the given selector. Otherwise, `null`.
1825 */
1826 $<Selector extends string>(selector: Selector): Promise<ElementHandle<NodeFor<Selector>> | null>;
1827 /**
1828 * Queries the current element for all elements matching the given selector.
1829 *
1830 * @param selector -
1831 * {@link https://pptr.dev/guides/page-interactions#selectors | selector}
1832 * to query the page for.
1833 * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors | CSS selectors}
1834 * can be passed as-is and a
1835 * {@link https://pptr.dev/guides/page-interactions#non-css-selectors | Puppeteer-specific selector syntax}
1836 * allows quering by
1837 * {@link https://pptr.dev/guides/page-interactions#text-selectors--p-text | text},
1838 * {@link https://pptr.dev/guides/page-interactions#aria-selectors--p-aria | a11y role and name},
1839 * and
1840 * {@link https://pptr.dev/guides/page-interactions#xpath-selectors--p-xpath | xpath}
1841 * and
1842 * {@link https://pptr.dev/guides/page-interactions#querying-elements-in-shadow-dom | combining these queries across shadow roots}.
1843 * Alternatively, you can specify the selector type using a
1844 * {@link https://pptr.dev/guides/page-interactions#prefixed-selector-syntax | prefix}.
1845 * @returns An array of {@link ElementHandle | element handles} that point to
1846 * elements matching the given selector.
1847 */
1848 $$<Selector extends string>(selector: Selector, options?: QueryOptions): Promise<Array<ElementHandle<NodeFor<Selector>>>>;
1849 /**
1850 * Runs the given function on the first element matching the given selector in
1851 * the current element.
1852 *
1853 * If the given function returns a promise, then this method will wait till
1854 * the promise resolves.
1855 *
1856 * @example
1857 *
1858 * ```ts
1859 * const tweetHandle = await page.$('.tweet');
1860 * expect(await tweetHandle.$eval('.like', node => node.innerText)).toBe(
1861 * '100',
1862 * );
1863 * expect(await tweetHandle.$eval('.retweets', node => node.innerText)).toBe(
1864 * '10',
1865 * );
1866 * ```
1867 *
1868 * @param selector -
1869 * {@link https://pptr.dev/guides/page-interactions#selectors | selector}
1870 * to query the page for.
1871 * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors | CSS selectors}
1872 * can be passed as-is and a
1873 * {@link https://pptr.dev/guides/page-interactions#non-css-selectors | Puppeteer-specific selector syntax}
1874 * allows quering by
1875 * {@link https://pptr.dev/guides/page-interactions#text-selectors--p-text | text},
1876 * {@link https://pptr.dev/guides/page-interactions#aria-selectors--p-aria | a11y role and name},
1877 * and
1878 * {@link https://pptr.dev/guides/page-interactions#xpath-selectors--p-xpath | xpath}
1879 * and
1880 * {@link https://pptr.dev/guides/page-interactions#querying-elements-in-shadow-dom | combining these queries across shadow roots}.
1881 * Alternatively, you can specify the selector type using a
1882 * {@link https://pptr.dev/guides/page-interactions#prefixed-selector-syntax | prefix}.
1883 * @param pageFunction - The function to be evaluated in this element's page's
1884 * context. The first element matching the selector will be passed in as the
1885 * first argument.
1886 * @param args - Additional arguments to pass to `pageFunction`.
1887 * @returns A promise to the result of the function.
1888 */
1889 $eval<Selector extends string, Params extends unknown[], Func extends EvaluateFuncWith<NodeFor<Selector>, Params> = EvaluateFuncWith<NodeFor<Selector>, Params>>(selector: Selector, pageFunction: Func | string, ...args: Params): Promise<Awaited<ReturnType<Func>>>;
1890 /**
1891 * Runs the given function on an array of elements matching the given selector
1892 * in the current element.
1893 *
1894 * If the given function returns a promise, then this method will wait till
1895 * the promise resolves.
1896 *
1897 * @example
1898 * HTML:
1899 *
1900 * ```html
1901 * <div class="feed">
1902 * <div class="tweet">Hello!</div>
1903 * <div class="tweet">Hi!</div>
1904 * </div>
1905 * ```
1906 *
1907 * JavaScript:
1908 *
1909 * ```ts
1910 * const feedHandle = await page.$('.feed');
1911 * expect(
1912 * await feedHandle.$$eval('.tweet', nodes => nodes.map(n => n.innerText)),
1913 * ).toEqual(['Hello!', 'Hi!']);
1914 * ```
1915 *
1916 * @param selector -
1917 * {@link https://pptr.dev/guides/page-interactions#selectors | selector}
1918 * to query the page for.
1919 * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors | CSS selectors}
1920 * can be passed as-is and a
1921 * {@link https://pptr.dev/guides/page-interactions#non-css-selectors | Puppeteer-specific selector syntax}
1922 * allows quering by
1923 * {@link https://pptr.dev/guides/page-interactions#text-selectors--p-text | text},
1924 * {@link https://pptr.dev/guides/page-interactions#aria-selectors--p-aria | a11y role and name},
1925 * and
1926 * {@link https://pptr.dev/guides/page-interactions#xpath-selectors--p-xpath | xpath}
1927 * and
1928 * {@link https://pptr.dev/guides/page-interactions#querying-elements-in-shadow-dom | combining these queries across shadow roots}.
1929 * Alternatively, you can specify the selector type using a
1930 * {@link https://pptr.dev/guides/page-interactions#prefixed-selector-syntax | prefix}.
1931 * @param pageFunction - The function to be evaluated in the element's page's
1932 * context. An array of elements matching the given selector will be passed to
1933 * the function as its first argument.
1934 * @param args - Additional arguments to pass to `pageFunction`.
1935 * @returns A promise to the result of the function.
1936 */
1937 $$eval<Selector extends string, Params extends unknown[], Func extends EvaluateFuncWith<Array<NodeFor<Selector>>, Params> = EvaluateFuncWith<Array<NodeFor<Selector>>, Params>>(selector: Selector, pageFunction: Func | string, ...args: Params): Promise<Awaited<ReturnType<Func>>>;
1938 /**
1939 * Wait for an element matching the given selector to appear in the current
1940 * element.
1941 *
1942 * Unlike {@link Frame.waitForSelector}, this method does not work across
1943 * navigations or if the element is detached from DOM.
1944 *
1945 * @example
1946 *
1947 * ```ts
1948 * import puppeteer from 'puppeteer';
1949 *
1950 * (async () => {
1951 * const browser = await puppeteer.launch();
1952 * const page = await browser.newPage();
1953 * let currentURL;
1954 * page
1955 * .mainFrame()
1956 * .waitForSelector('img')
1957 * .then(() => console.log('First URL with image: ' + currentURL));
1958 *
1959 * for (currentURL of [
1960 * 'https://example.com',
1961 * 'https://google.com',
1962 * 'https://bbc.com',
1963 * ]) {
1964 * await page.goto(currentURL);
1965 * }
1966 * await browser.close();
1967 * })();
1968 * ```
1969 *
1970 * @param selector - The selector to query and wait for.
1971 * @param options - Options for customizing waiting behavior.
1972 * @returns An element matching the given selector.
1973 * @throws Throws if an element matching the given selector doesn't appear.
1974 */
1975 waitForSelector<Selector extends string>(selector: Selector, options?: WaitForSelectorOptions): Promise<ElementHandle<NodeFor<Selector>> | null>;
1976 /**
1977 * An element is considered to be visible if all of the following is
1978 * true:
1979 *
1980 * - the element has
1981 * {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle | computed styles}.
1982 *
1983 * - the element has a non-empty
1984 * {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect | bounding client rect}.
1985 *
1986 * - the element's {@link https://developer.mozilla.org/en-US/docs/Web/CSS/visibility | visibility}
1987 * is not `hidden` or `collapse`.
1988 */
1989 isVisible(): Promise<boolean>;
1990 /**
1991 * An element is considered to be hidden if at least one of the following is true:
1992 *
1993 * - the element has no
1994 * {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle | computed styles}.
1995 *
1996 * - the element has an empty
1997 * {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect | bounding client rect}.
1998 *
1999 * - the element's {@link https://developer.mozilla.org/en-US/docs/Web/CSS/visibility | visibility}
2000 * is `hidden` or `collapse`.
2001 */
2002 isHidden(): Promise<boolean>;
2003 /**
2004 * Converts the current handle to the given element type.
2005 *
2006 * @example
2007 *
2008 * ```ts
2009 * const element: ElementHandle<Element> = await page.$(
2010 * '.class-name-of-anchor',
2011 * );
2012 * // DO NOT DISPOSE `element`, this will be always be the same handle.
2013 * const anchor: ElementHandle<HTMLAnchorElement> =
2014 * await element.toElement('a');
2015 * ```
2016 *
2017 * @param tagName - The tag name of the desired element type.
2018 * @throws An error if the handle does not match. **The handle will not be
2019 * automatically disposed.**
2020 */
2021 toElement<K extends keyof HTMLElementTagNameMap | keyof SVGElementTagNameMap>(tagName: K): Promise<HandleFor<ElementFor<K>>>;
2022 /**
2023 * Resolves the frame associated with the element, if any. Always exists for
2024 * HTMLIFrameElements.
2025 */
2026 abstract contentFrame(this: ElementHandle<HTMLIFrameElement>): Promise<Frame>;
2027 abstract contentFrame(): Promise<Frame | null>;
2028 /**
2029 * Returns the middle point within an element unless a specific offset is provided.
2030 */
2031 clickablePoint(offset?: Offset): Promise<Point>;
2032 /**
2033 * This method scrolls element into view if needed, and then
2034 * uses {@link Page.mouse} to hover over the center of the element.
2035 * If the element is detached from DOM, the method throws an error.
2036 */
2037 hover(this: ElementHandle<Element>): Promise<void>;
2038 /**
2039 * This method scrolls element into view if needed, and then
2040 * uses {@link Page.mouse} to click in the center of the element.
2041 * If the element is detached from DOM, the method throws an error.
2042 */
2043 click(this: ElementHandle<Element>, options?: Readonly<ClickOptions>): Promise<void>;
2044 /**
2045 * Drags an element over the given element or point.
2046 *
2047 * @returns DEPRECATED. When drag interception is enabled, the drag payload is
2048 * returned.
2049 */
2050 drag(this: ElementHandle<Element>, target: Point | ElementHandle<Element>): Promise<Protocol.Input.DragData | void>;
2051 /**
2052 * @deprecated Do not use. `dragenter` will automatically be performed during dragging.
2053 */
2054 dragEnter(this: ElementHandle<Element>, data?: Protocol.Input.DragData): Promise<void>;
2055 /**
2056 * @deprecated Do not use. `dragover` will automatically be performed during dragging.
2057 */
2058 dragOver(this: ElementHandle<Element>, data?: Protocol.Input.DragData): Promise<void>;
2059 /**
2060 * Drops the given element onto the current one.
2061 */
2062 drop(this: ElementHandle<Element>, element: ElementHandle<Element>): Promise<void>;
2063 /**
2064 * @deprecated No longer supported.
2065 */
2066 drop(this: ElementHandle<Element>, data?: Protocol.Input.DragData): Promise<void>;
2067 /**
2068 * @deprecated Use `ElementHandle.drop` instead.
2069 */
2070 dragAndDrop(this: ElementHandle<Element>, target: ElementHandle<Node>, options?: {
2071 delay: number;
2072 }): Promise<void>;
2073 /**
2074 * Triggers a `change` and `input` event once all the provided options have been
2075 * selected. If there's no `<select>` element matching `selector`, the method
2076 * throws an error.
2077 *
2078 * @example
2079 *
2080 * ```ts
2081 * handle.select('blue'); // single selection
2082 * handle.select('red', 'green', 'blue'); // multiple selections
2083 * ```
2084 *
2085 * @param values - Values of options to select. If the `<select>` has the
2086 * `multiple` attribute, all values are considered, otherwise only the first
2087 * one is taken into account.
2088 */
2089 select(...values: string[]): Promise<string[]>;
2090 /**
2091 * Sets the value of an
2092 * {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input | input element}
2093 * to the given file paths.
2094 *
2095 * @remarks This will not validate whether the file paths exists. Also, if a
2096 * path is relative, then it is resolved against the
2097 * {@link https://nodejs.org/api/process.html#process_process_cwd | current working directory}.
2098 * For locals script connecting to remote chrome environments, paths must be
2099 * absolute.
2100 */
2101 abstract uploadFile(this: ElementHandle<HTMLInputElement>, ...paths: string[]): Promise<void>;
2102
2103 /**
2104 * This method scrolls element into view if needed, and then uses
2105 * {@link Touchscreen.tap} to tap in the center of the element.
2106 * If the element is detached from DOM, the method throws an error.
2107 */
2108 tap(this: ElementHandle<Element>): Promise<void>;
2109 /**
2110 * This method scrolls the element into view if needed, and then
2111 * starts a touch in the center of the element.
2112 * @returns A {@link TouchHandle} representing the touch that was started
2113 */
2114 touchStart(this: ElementHandle<Element>): Promise<TouchHandle>;
2115 /**
2116 * This method scrolls the element into view if needed, and then
2117 * moves the touch to the center of the element.
2118 * @param touch - An optional {@link TouchHandle}. If provided, this touch
2119 * will be moved. If not provided, the first active touch will be moved.
2120 */
2121 touchMove(this: ElementHandle<Element>, touch?: TouchHandle): Promise<void>;
2122 touchEnd(this: ElementHandle<Element>): Promise<void>;
2123 /**
2124 * Calls {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus | focus} on the element.
2125 */
2126 focus(): Promise<void>;
2127 /**
2128 * Focuses the element, and then sends a `keydown`, `keypress`/`input`, and
2129 * `keyup` event for each character in the text.
2130 *
2131 * To press a special key, like `Control` or `ArrowDown`,
2132 * use {@link ElementHandle.press}.
2133 *
2134 * @example
2135 *
2136 * ```ts
2137 * await elementHandle.type('Hello'); // Types instantly
2138 * await elementHandle.type('World', {delay: 100}); // Types slower, like a user
2139 * ```
2140 *
2141 * @example
2142 * An example of typing into a text field and then submitting the form:
2143 *
2144 * ```ts
2145 * const elementHandle = await page.$('input');
2146 * await elementHandle.type('some text');
2147 * await elementHandle.press('Enter');
2148 * ```
2149 *
2150 * @param options - Delay in milliseconds. Defaults to 0.
2151 */
2152 type(text: string, options?: Readonly<KeyboardTypeOptions>): Promise<void>;
2153 /**
2154 * Focuses the element, and then uses {@link Keyboard.down} and {@link Keyboard.up}.
2155 *
2156 * @remarks
2157 * If `key` is a single character and no modifier keys besides `Shift`
2158 * are being held down, a `keypress`/`input` event will also be generated.
2159 * The `text` option can be specified to force an input event to be generated.
2160 *
2161 * **NOTE** Modifier keys DO affect `elementHandle.press`. Holding down `Shift`
2162 * will type the text in upper case.
2163 *
2164 * @param key - Name of key to press, such as `ArrowLeft`.
2165 * See {@link KeyInput} for a list of all key names.
2166 */
2167 press(key: KeyInput, options?: Readonly<KeyPressOptions>): Promise<void>;
2168 /**
2169 * This method returns the bounding box of the element (relative to the main frame),
2170 * or `null` if the element is {@link https://drafts.csswg.org/css-display-4/#box-generation | not part of the layout}
2171 * (example: `display: none`).
2172 */
2173 boundingBox(): Promise<BoundingBox | null>;
2174 /**
2175 * This method returns boxes of the element,
2176 * or `null` if the element is {@link https://drafts.csswg.org/css-display-4/#box-generation | not part of the layout}
2177 * (example: `display: none`).
2178 *
2179 * @remarks
2180 *
2181 * Boxes are represented as an array of points;
2182 * Each Point is an object `{x, y}`. Box points are sorted clock-wise.
2183 */
2184 boxModel(): Promise<BoxModel | null>;
2185 /**
2186 * This method scrolls element into view if needed, and then uses
2187 * {@link Page.(screenshot:2) } to take a screenshot of the element.
2188 * If the element is detached from DOM, the method throws an error.
2189 */
2190 screenshot(options: Readonly<ScreenshotOptions> & {
2191 encoding: 'base64';
2192 }): Promise<string>;
2193 screenshot(options?: Readonly<ScreenshotOptions>): Promise<Uint8Array>;
2194
2195
2196 /**
2197 * Resolves to true if the element is visible in the current viewport. If an
2198 * element is an SVG, we check if the svg owner element is in the viewport
2199 * instead. See https://crbug.com/963246.
2200 *
2201 * @param options - Threshold for the intersection between 0 (no intersection) and 1
2202 * (full intersection). Defaults to 1.
2203 */
2204 isIntersectingViewport(this: ElementHandle<Element>, options?: {
2205 threshold?: number;
2206 }): Promise<boolean>;
2207 /**
2208 * Scrolls the element into view using either the automation protocol client
2209 * or by calling element.scrollIntoView.
2210 */
2211 scrollIntoView(this: ElementHandle<Element>): Promise<void>;
2212 /**
2213 * If the element is a form input, you can use {@link ElementHandle.autofill}
2214 * to test if the form is compatible with the browser's autofill
2215 * implementation. Throws an error if the form cannot be autofilled.
2216 *
2217 * @remarks
2218 *
2219 * Currently, Puppeteer supports auto-filling credit card information only and
2220 * in Chrome in the new headless and headful modes only.
2221 *
2222 * ```ts
2223 * // Select an input on the credit card form.
2224 * const name = await page.waitForSelector('form #name');
2225 * // Trigger autofill with the desired data.
2226 * await name.autofill({
2227 * creditCard: {
2228 * number: '4444444444444444',
2229 * name: 'John Smith',
2230 * expiryMonth: '01',
2231 * expiryYear: '2030',
2232 * cvc: '123',
2233 * },
2234 * });
2235 * ```
2236 */
2237 abstract autofill(data: AutofillData): Promise<void>;
2238 /**
2239 * When connected using Chrome DevTools Protocol, it returns a
2240 * DOM.BackendNodeId for the element.
2241 */
2242 abstract backendNodeId(): Promise<number>;
2243}
2244
2245/**
2246 * @public
2247 */
2248export declare interface ElementScreenshotOptions extends ScreenshotOptions {
2249 /**
2250 * @defaultValue `true`
2251 */
2252 scrollIntoView?: boolean;
2253}
2254
2255/**
2256 * @public
2257 */
2258export declare type ErrorCode = 'aborted' | 'accessdenied' | 'addressunreachable' | 'blockedbyclient' | 'blockedbyresponse' | 'connectionaborted' | 'connectionclosed' | 'connectionfailed' | 'connectionrefused' | 'connectionreset' | 'internetdisconnected' | 'namenotresolved' | 'timedout' | 'failed';
2259
2260/**
2261 * @public
2262 */
2263export declare type EvaluateFunc<T extends unknown[]> = (...params: InnerParams<T>) => Awaitable<unknown>;
2264
2265/**
2266 * @public
2267 */
2268export declare type EvaluateFuncWith<V, T extends unknown[]> = (...params: [V, ...InnerParams<T>]) => Awaitable<unknown>;
2269
2270/**
2271 * The EventEmitter class that many Puppeteer classes extend.
2272 *
2273 * @remarks
2274 *
2275 * This allows you to listen to events that Puppeteer classes fire and act
2276 * accordingly. Therefore you'll mostly use {@link EventEmitter.on | on} and
2277 * {@link EventEmitter.off | off} to bind
2278 * and unbind to event listeners.
2279 *
2280 * @public
2281 */
2282export declare class EventEmitter<Events extends Record<EventType, unknown>> implements CommonEventEmitter<EventsWithWildcard<Events>> {
2283 #private;
2284
2285 /**
2286 * Bind an event listener to fire when an event occurs.
2287 * @param type - the event type you'd like to listen to. Can be a string or symbol.
2288 * @param handler - the function to be called when the event occurs.
2289 * @returns `this` to enable you to chain method calls.
2290 */
2291 on<Key extends keyof EventsWithWildcard<Events>>(type: Key, handler: Handler<EventsWithWildcard<Events>[Key]>): this;
2292 /**
2293 * Remove an event listener from firing.
2294 * @param type - the event type you'd like to stop listening to.
2295 * @param handler - the function that should be removed.
2296 * @returns `this` to enable you to chain method calls.
2297 */
2298 off<Key extends keyof EventsWithWildcard<Events>>(type: Key, handler?: Handler<EventsWithWildcard<Events>[Key]>): this;
2299 /**
2300 * Emit an event and call any associated listeners.
2301 *
2302 * @param type - the event you'd like to emit
2303 * @param eventData - any data you'd like to emit with the event
2304 * @returns `true` if there are any listeners, `false` if there are not.
2305 */
2306 emit<Key extends keyof EventsWithWildcard<Events>>(type: Key, event: EventsWithWildcard<Events>[Key]): boolean;
2307 /**
2308 * Like `on` but the listener will only be fired once and then it will be removed.
2309 * @param type - the event you'd like to listen to
2310 * @param handler - the handler function to run when the event occurs
2311 * @returns `this` to enable you to chain method calls.
2312 */
2313 once<Key extends keyof EventsWithWildcard<Events>>(type: Key, handler: Handler<EventsWithWildcard<Events>[Key]>): this;
2314 /**
2315 * Gets the number of listeners for a given event.
2316 *
2317 * @param type - the event to get the listener count for
2318 * @returns the number of listeners bound to the given event
2319 */
2320 listenerCount(type: keyof EventsWithWildcard<Events>): number;
2321 /**
2322 * Removes all listeners. If given an event argument, it will remove only
2323 * listeners for that event.
2324 *
2325 * @param type - the event to remove listeners for.
2326 * @returns `this` to enable you to chain method calls.
2327 */
2328 removeAllListeners(type?: keyof EventsWithWildcard<Events>): this;
2329
2330}
2331
2332/**
2333 * @public
2334 */
2335export declare type EventsWithWildcard<Events extends Record<EventType, unknown>> = Events & {
2336 '*': Events[keyof Events];
2337};
2338
2339/**
2340 * @public
2341 */
2342export declare type EventType = string | symbol;
2343
2344/**
2345 * @public
2346 */
2347export declare const
2348/**
2349* @public
2350*/
2351/**
2352 * @public
2353 */
2354executablePath: {
2355 (channel: Puppeteer_2.ChromeReleaseChannel): string;
2356 (options: Puppeteer_2.LaunchOptions): string;
2357 (): string;
2358};
2359
2360/**
2361 * Defines experiment options for Puppeteer.
2362 *
2363 * See individual properties for more information.
2364 *
2365 * @public
2366 */
2367export declare type ExperimentsConfiguration = Record<string, never>;
2368
2369/**
2370 * Experimental ExtensionTransport allows establishing a connection via
2371 * chrome.debugger API if Puppeteer runs in an extension. Since Chrome
2372 * DevTools Protocol is restricted for extensions, the transport
2373 * implements missing commands and events.
2374 *
2375 * @experimental
2376 * @public
2377 */
2378export declare class ExtensionTransport implements ConnectionTransport {
2379 #private;
2380 static connectTab(tabId: number): Promise<ExtensionTransport>;
2381 onmessage?: (message: string) => void;
2382 onclose?: () => void;
2383
2384 send(message: string): void;
2385 close(): void;
2386}
2387
2388/**
2389 * File choosers let you react to the page requesting for a file.
2390 *
2391 * @remarks
2392 * `FileChooser` instances are returned via the {@link Page.waitForFileChooser} method.
2393 *
2394 * In browsers, only one file chooser can be opened at a time.
2395 * All file choosers must be accepted or canceled. Not doing so will prevent
2396 * subsequent file choosers from appearing.
2397 *
2398 * @example
2399 *
2400 * ```ts
2401 * const [fileChooser] = await Promise.all([
2402 * page.waitForFileChooser(),
2403 * page.click('#upload-file-button'), // some button that triggers file selection
2404 * ]);
2405 * await fileChooser.accept(['/tmp/myfile.pdf']);
2406 * ```
2407 *
2408 * @public
2409 */
2410export declare class FileChooser {
2411 #private;
2412
2413 /**
2414 * Whether file chooser allow for
2415 * {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#attr-multiple | multiple}
2416 * file selection.
2417 */
2418 isMultiple(): boolean;
2419 /**
2420 * Accept the file chooser request with the given file paths.
2421 *
2422 * @remarks This will not validate whether the file paths exists. Also, if a
2423 * path is relative, then it is resolved against the
2424 * {@link https://nodejs.org/api/process.html#process_process_cwd | current working directory}.
2425 * For locals script connecting to remote chrome environments, paths must be
2426 * absolute.
2427 */
2428 accept(paths: string[]): Promise<void>;
2429 /**
2430 * Closes the file chooser without selecting any files.
2431 */
2432 cancel(): Promise<void>;
2433}
2434
2435/**
2436 * @public
2437 */
2438export declare interface FirefoxSettings {
2439 /**
2440 * Tells Puppeteer to not download the browser during installation.
2441 *
2442 * Can be overridden by `PUPPETEER_FIREFOX_SKIP_DOWNLOAD`.
2443 *
2444 * @defaultValue true
2445 */
2446 skipDownload?: boolean;
2447 /**
2448 * Specifies the URL prefix that is used to download the browser.
2449 *
2450 * Can be overridden by `PUPPETEER_FIREFOX_DOWNLOAD_BASE_URL`.
2451 *
2452 * @remarks
2453 * This must include the protocol and may even need a path prefix.
2454 * This must **not** include a trailing slash similar to the default.
2455 *
2456 * @defaultValue https://archive.mozilla.org/pub/firefox/releases
2457 */
2458 downloadBaseUrl?: string;
2459 /**
2460 * Specifies a certain version of the browser you'd like Puppeteer to use.
2461 *
2462 * Can be overridden by `PUPPETEER_FIREFOX_VERSION`.
2463 *
2464 * See {@link PuppeteerNode.launch | puppeteer.launch} on how executable path
2465 * is inferred.
2466 *
2467 * @example stable_129.0
2468 * @defaultValue The pinned browser version supported by the current Puppeteer
2469 * version.
2470 */
2471 version?: string;
2472}
2473
2474/**
2475 * @public
2476 */
2477export declare type FlattenHandle<T> = T extends HandleOr<infer U> ? U : never;
2478
2479/**
2480 * Represents a DOM frame.
2481 *
2482 * To understand frames, you can think of frames as `<iframe>` elements. Just
2483 * like iframes, frames can be nested, and when JavaScript is executed in a
2484 * frame, the JavaScript does not effect frames inside the ambient frame the
2485 * JavaScript executes in.
2486 *
2487 * @example
2488 * At any point in time, {@link Page | pages} expose their current frame
2489 * tree via the {@link Page.mainFrame} and {@link Frame.childFrames} methods.
2490 *
2491 * @example
2492 * An example of dumping frame tree:
2493 *
2494 * ```ts
2495 * import puppeteer from 'puppeteer';
2496 *
2497 * (async () => {
2498 * const browser = await puppeteer.launch();
2499 * const page = await browser.newPage();
2500 * await page.goto('https://www.google.com/chrome/browser/canary.html');
2501 * dumpFrameTree(page.mainFrame(), '');
2502 * await browser.close();
2503 *
2504 * function dumpFrameTree(frame, indent) {
2505 * console.log(indent + frame.url());
2506 * for (const child of frame.childFrames()) {
2507 * dumpFrameTree(child, indent + ' ');
2508 * }
2509 * }
2510 * })();
2511 * ```
2512 *
2513 * @example
2514 * An example of getting text from an iframe element:
2515 *
2516 * ```ts
2517 * const frame = page.frames().find(frame => frame.name() === 'myframe');
2518 * const text = await frame.$eval('.selector', element => element.textContent);
2519 * console.log(text);
2520 * ```
2521 *
2522 * @remarks
2523 * Frame lifecycles are controlled by three events that are all dispatched on
2524 * the parent {@link Frame.page | page}:
2525 *
2526 * - {@link PageEvent.FrameAttached}
2527 * - {@link PageEvent.FrameNavigated}
2528 * - {@link PageEvent.FrameDetached}
2529 *
2530 * @public
2531 */
2532export declare abstract class Frame extends EventEmitter<FrameEvents> {
2533 #private;
2534
2535
2536
2537
2538
2539 /**
2540 * The page associated with the frame.
2541 */
2542 abstract page(): Page;
2543 /**
2544 * Navigates the frame or page to the given `url`.
2545 *
2546 * @remarks
2547 * Navigation to `about:blank` or navigation to the same URL with a different
2548 * hash will succeed and return `null`.
2549 *
2550 * :::warning
2551 *
2552 * Headless shell mode doesn't support navigation to a PDF document. See the
2553 * {@link https://crbug.com/761295 | upstream issue}.
2554 *
2555 * :::
2556 *
2557 * In headless shell, this method will not throw an error when any valid HTTP
2558 * status code is returned by the remote server, including 404 "Not Found" and
2559 * 500 "Internal Server Error". The status code for such responses can be
2560 * retrieved by calling {@link HTTPResponse.status}.
2561 *
2562 * @param url - URL to navigate the frame to. The URL should include scheme,
2563 * e.g. `https://`
2564 * @param options - Options to configure waiting behavior.
2565 * @returns A promise which resolves to the main resource response. In case of
2566 * multiple redirects, the navigation will resolve with the response of the
2567 * last redirect.
2568 * @throws If:
2569 *
2570 * - there's an SSL error (e.g. in case of self-signed certificates).
2571 *
2572 * - target URL is invalid.
2573 *
2574 * - the timeout is exceeded during navigation.
2575 *
2576 * - the remote server does not respond or is unreachable.
2577 *
2578 * - the main resource failed to load.
2579 */
2580 abstract goto(url: string, options?: GoToOptions): Promise<HTTPResponse | null>;
2581 /**
2582 * Waits for the frame to navigate. It is useful for when you run code which
2583 * will indirectly cause the frame to navigate.
2584 *
2585 * Usage of the
2586 * {@link https://developer.mozilla.org/en-US/docs/Web/API/History_API | History API}
2587 * to change the URL is considered a navigation.
2588 *
2589 * @example
2590 *
2591 * ```ts
2592 * const [response] = await Promise.all([
2593 * // The navigation promise resolves after navigation has finished
2594 * frame.waitForNavigation(),
2595 * // Clicking the link will indirectly cause a navigation
2596 * frame.click('a.my-link'),
2597 * ]);
2598 * ```
2599 *
2600 * @param options - Options to configure waiting behavior.
2601 * @returns A promise which resolves to the main resource response.
2602 */
2603 abstract waitForNavigation(options?: WaitForOptions): Promise<HTTPResponse | null>;
2604
2605
2606
2607
2608
2609 /**
2610 * @returns The frame element associated with this frame (if any).
2611 */
2612 frameElement(): Promise<HandleFor<HTMLIFrameElement> | null>;
2613 /**
2614 * Behaves identically to {@link Page.evaluateHandle} except it's run within
2615 * the context of this frame.
2616 *
2617 * See {@link Page.evaluateHandle} for details.
2618 */
2619 evaluateHandle<Params extends unknown[], Func extends EvaluateFunc<Params> = EvaluateFunc<Params>>(pageFunction: Func | string, ...args: Params): Promise<HandleFor<Awaited<ReturnType<Func>>>>;
2620 /**
2621 * Behaves identically to {@link Page.evaluate} except it's run within
2622 * the context of this frame.
2623 *
2624 * See {@link Page.evaluate} for details.
2625 */
2626 evaluate<Params extends unknown[], Func extends EvaluateFunc<Params> = EvaluateFunc<Params>>(pageFunction: Func | string, ...args: Params): Promise<Awaited<ReturnType<Func>>>;
2627 /**
2628 * Creates a locator for the provided selector. See {@link Locator} for
2629 * details and supported actions.
2630 *
2631 * @param selector -
2632 * {@link https://pptr.dev/guides/page-interactions#selectors | selector}
2633 * to query the page for.
2634 * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors | CSS selectors}
2635 * can be passed as-is and a
2636 * {@link https://pptr.dev/guides/page-interactions#non-css-selectors | Puppeteer-specific selector syntax}
2637 * allows quering by
2638 * {@link https://pptr.dev/guides/page-interactions#text-selectors--p-text | text},
2639 * {@link https://pptr.dev/guides/page-interactions#aria-selectors--p-aria | a11y role and name},
2640 * and
2641 * {@link https://pptr.dev/guides/page-interactions#xpath-selectors--p-xpath | xpath}
2642 * and
2643 * {@link https://pptr.dev/guides/page-interactions#querying-elements-in-shadow-dom | combining these queries across shadow roots}.
2644 * Alternatively, you can specify the selector type using a
2645 * {@link https://pptr.dev/guides/page-interactions#prefixed-selector-syntax | prefix}.
2646 */
2647 locator<Selector extends string>(selector: Selector): Locator<NodeFor<Selector>>;
2648 /**
2649 * Creates a locator for the provided function. See {@link Locator} for
2650 * details and supported actions.
2651 */
2652 locator<Ret>(func: () => Awaitable<Ret>): Locator<Ret>;
2653 /**
2654 * Queries the frame for an element matching the given selector.
2655 *
2656 * @param selector -
2657 * {@link https://pptr.dev/guides/page-interactions#selectors | selector}
2658 * to query the page for.
2659 * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors | CSS selectors}
2660 * can be passed as-is and a
2661 * {@link https://pptr.dev/guides/page-interactions#non-css-selectors | Puppeteer-specific selector syntax}
2662 * allows quering by
2663 * {@link https://pptr.dev/guides/page-interactions#text-selectors--p-text | text},
2664 * {@link https://pptr.dev/guides/page-interactions#aria-selectors--p-aria | a11y role and name},
2665 * and
2666 * {@link https://pptr.dev/guides/page-interactions#xpath-selectors--p-xpath | xpath}
2667 * and
2668 * {@link https://pptr.dev/guides/page-interactions#querying-elements-in-shadow-dom | combining these queries across shadow roots}.
2669 * Alternatively, you can specify the selector type using a
2670 * {@link https://pptr.dev/guides/page-interactions#prefixed-selector-syntax | prefix}.
2671 *
2672 * @returns A {@link ElementHandle | element handle} to the first element
2673 * matching the given selector. Otherwise, `null`.
2674 */
2675 $<Selector extends string>(selector: Selector): Promise<ElementHandle<NodeFor<Selector>> | null>;
2676 /**
2677 * Queries the frame for all elements matching the given selector.
2678 *
2679 * @param selector -
2680 * {@link https://pptr.dev/guides/page-interactions#selectors | selector}
2681 * to query the page for.
2682 * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors | CSS selectors}
2683 * can be passed as-is and a
2684 * {@link https://pptr.dev/guides/page-interactions#non-css-selectors | Puppeteer-specific selector syntax}
2685 * allows quering by
2686 * {@link https://pptr.dev/guides/page-interactions#text-selectors--p-text | text},
2687 * {@link https://pptr.dev/guides/page-interactions#aria-selectors--p-aria | a11y role and name},
2688 * and
2689 * {@link https://pptr.dev/guides/page-interactions#xpath-selectors--p-xpath | xpath}
2690 * and
2691 * {@link https://pptr.dev/guides/page-interactions#querying-elements-in-shadow-dom | combining these queries across shadow roots}.
2692 * Alternatively, you can specify the selector type using a
2693 * {@link https://pptr.dev/guides/page-interactions#prefixed-selector-syntax | prefix}.
2694 *
2695 * @returns An array of {@link ElementHandle | element handles} that point to
2696 * elements matching the given selector.
2697 */
2698 $$<Selector extends string>(selector: Selector, options?: QueryOptions): Promise<Array<ElementHandle<NodeFor<Selector>>>>;
2699 /**
2700 * Runs the given function on the first element matching the given selector in
2701 * the frame.
2702 *
2703 * If the given function returns a promise, then this method will wait till
2704 * the promise resolves.
2705 *
2706 * @example
2707 *
2708 * ```ts
2709 * const searchValue = await frame.$eval('#search', el => el.value);
2710 * ```
2711 *
2712 * @param selector -
2713 * {@link https://pptr.dev/guides/page-interactions#selectors | selector}
2714 * to query the page for.
2715 * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors | CSS selectors}
2716 * can be passed as-is and a
2717 * {@link https://pptr.dev/guides/page-interactions#non-css-selectors | Puppeteer-specific selector syntax}
2718 * allows quering by
2719 * {@link https://pptr.dev/guides/page-interactions#text-selectors--p-text | text},
2720 * {@link https://pptr.dev/guides/page-interactions#aria-selectors--p-aria | a11y role and name},
2721 * and
2722 * {@link https://pptr.dev/guides/page-interactions#xpath-selectors--p-xpath | xpath}
2723 * and
2724 * {@link https://pptr.dev/guides/page-interactions#querying-elements-in-shadow-dom | combining these queries across shadow roots}.
2725 * Alternatively, you can specify the selector type using a
2726 * {@link https://pptr.dev/guides/page-interactions#prefixed-selector-syntax | prefix}.
2727 * @param pageFunction - The function to be evaluated in the frame's context.
2728 * The first element matching the selector will be passed to the function as
2729 * its first argument.
2730 * @param args - Additional arguments to pass to `pageFunction`.
2731 * @returns A promise to the result of the function.
2732 */
2733 $eval<Selector extends string, Params extends unknown[], Func extends EvaluateFuncWith<NodeFor<Selector>, Params> = EvaluateFuncWith<NodeFor<Selector>, Params>>(selector: Selector, pageFunction: string | Func, ...args: Params): Promise<Awaited<ReturnType<Func>>>;
2734 /**
2735 * Runs the given function on an array of elements matching the given selector
2736 * in the frame.
2737 *
2738 * If the given function returns a promise, then this method will wait till
2739 * the promise resolves.
2740 *
2741 * @example
2742 *
2743 * ```ts
2744 * const divsCounts = await frame.$$eval('div', divs => divs.length);
2745 * ```
2746 *
2747 * @param selector -
2748 * {@link https://pptr.dev/guides/page-interactions#selectors | selector}
2749 * to query the page for.
2750 * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors | CSS selectors}
2751 * can be passed as-is and a
2752 * {@link https://pptr.dev/guides/page-interactions#non-css-selectors | Puppeteer-specific selector syntax}
2753 * allows quering by
2754 * {@link https://pptr.dev/guides/page-interactions#text-selectors--p-text | text},
2755 * {@link https://pptr.dev/guides/page-interactions#aria-selectors--p-aria | a11y role and name},
2756 * and
2757 * {@link https://pptr.dev/guides/page-interactions#xpath-selectors--p-xpath | xpath}
2758 * and
2759 * {@link https://pptr.dev/guides/page-interactions#querying-elements-in-shadow-dom | combining these queries across shadow roots}.
2760 * Alternatively, you can specify the selector type using a
2761 * {@link https://pptr.dev/guides/page-interactions#prefixed-selector-syntax | prefix}.
2762 * @param pageFunction - The function to be evaluated in the frame's context.
2763 * An array of elements matching the given selector will be passed to the
2764 * function as its first argument.
2765 * @param args - Additional arguments to pass to `pageFunction`.
2766 * @returns A promise to the result of the function.
2767 */
2768 $$eval<Selector extends string, Params extends unknown[], Func extends EvaluateFuncWith<Array<NodeFor<Selector>>, Params> = EvaluateFuncWith<Array<NodeFor<Selector>>, Params>>(selector: Selector, pageFunction: string | Func, ...args: Params): Promise<Awaited<ReturnType<Func>>>;
2769 /**
2770 * Waits for an element matching the given selector to appear in the frame.
2771 *
2772 * This method works across navigations.
2773 *
2774 * @example
2775 *
2776 * ```ts
2777 * import puppeteer from 'puppeteer';
2778 *
2779 * (async () => {
2780 * const browser = await puppeteer.launch();
2781 * const page = await browser.newPage();
2782 * let currentURL;
2783 * page
2784 * .mainFrame()
2785 * .waitForSelector('img')
2786 * .then(() => console.log('First URL with image: ' + currentURL));
2787 *
2788 * for (currentURL of [
2789 * 'https://example.com',
2790 * 'https://google.com',
2791 * 'https://bbc.com',
2792 * ]) {
2793 * await page.goto(currentURL);
2794 * }
2795 * await browser.close();
2796 * })();
2797 * ```
2798 *
2799 * @param selector - The selector to query and wait for.
2800 * @param options - Options for customizing waiting behavior.
2801 * @returns An element matching the given selector.
2802 * @throws Throws if an element matching the given selector doesn't appear.
2803 */
2804 waitForSelector<Selector extends string>(selector: Selector, options?: WaitForSelectorOptions): Promise<ElementHandle<NodeFor<Selector>> | null>;
2805 /**
2806 * @example
2807 * The `waitForFunction` can be used to observe viewport size change:
2808 *
2809 * ```ts
2810 * import puppeteer from 'puppeteer';
2811 *
2812 * (async () => {
2813 * . const browser = await puppeteer.launch();
2814 * . const page = await browser.newPage();
2815 * . const watchDog = page.mainFrame().waitForFunction('window.innerWidth < 100');
2816 * . page.setViewport({width: 50, height: 50});
2817 * . await watchDog;
2818 * . await browser.close();
2819 * })();
2820 * ```
2821 *
2822 * To pass arguments from Node.js to the predicate of `page.waitForFunction` function:
2823 *
2824 * ```ts
2825 * const selector = '.foo';
2826 * await frame.waitForFunction(
2827 * selector => !!document.querySelector(selector),
2828 * {}, // empty options object
2829 * selector,
2830 * );
2831 * ```
2832 *
2833 * @param pageFunction - the function to evaluate in the frame context.
2834 * @param options - options to configure the polling method and timeout.
2835 * @param args - arguments to pass to the `pageFunction`.
2836 * @returns the promise which resolve when the `pageFunction` returns a truthy value.
2837 */
2838 waitForFunction<Params extends unknown[], Func extends EvaluateFunc<Params> = EvaluateFunc<Params>>(pageFunction: Func | string, options?: FrameWaitForFunctionOptions, ...args: Params): Promise<HandleFor<Awaited<ReturnType<Func>>>>;
2839 /**
2840 * The full HTML contents of the frame, including the DOCTYPE.
2841 */
2842 content(): Promise<string>;
2843 /**
2844 * Set the content of the frame.
2845 *
2846 * @param html - HTML markup to assign to the page.
2847 * @param options - Options to configure how long before timing out and at
2848 * what point to consider the content setting successful.
2849 */
2850 abstract setContent(html: string, options?: WaitForOptions): Promise<void>;
2851
2852 /**
2853 * The frame's `name` attribute as specified in the tag.
2854 *
2855 * @remarks
2856 * If the name is empty, it returns the `id` attribute instead.
2857 *
2858 * @remarks
2859 * This value is calculated once when the frame is created, and will not
2860 * update if the attribute is changed later.
2861 *
2862 * @deprecated Use
2863 *
2864 * ```ts
2865 * const element = await frame.frameElement();
2866 * const nameOrId = await element.evaluate(frame => frame.name ?? frame.id);
2867 * ```
2868 */
2869 name(): string;
2870 /**
2871 * The frame's URL.
2872 */
2873 abstract url(): string;
2874 /**
2875 * The parent frame, if any. Detached and main frames return `null`.
2876 */
2877 abstract parentFrame(): Frame | null;
2878 /**
2879 * An array of child frames.
2880 */
2881 abstract childFrames(): Frame[];
2882 /**
2883 * @returns `true` if the frame has detached. `false` otherwise.
2884 */
2885 abstract get detached(): boolean;
2886 /**
2887 * Is`true` if the frame has been detached. Otherwise, `false`.
2888 *
2889 * @deprecated Use the `detached` getter.
2890 */
2891 isDetached(): boolean;
2892
2893 /**
2894 * Adds a `<script>` tag into the page with the desired url or content.
2895 *
2896 * @param options - Options for the script.
2897 * @returns An {@link ElementHandle | element handle} to the injected
2898 * `<script>` element.
2899 */
2900 addScriptTag(options: FrameAddScriptTagOptions): Promise<ElementHandle<HTMLScriptElement>>;
2901 /**
2902 * Adds a `HTMLStyleElement` into the frame with the desired URL
2903 *
2904 * @returns An {@link ElementHandle | element handle} to the loaded `<style>`
2905 * element.
2906 */
2907 addStyleTag(options: Omit<FrameAddStyleTagOptions, 'url'>): Promise<ElementHandle<HTMLStyleElement>>;
2908 /**
2909 * Adds a `HTMLLinkElement` into the frame with the desired URL
2910 *
2911 * @returns An {@link ElementHandle | element handle} to the loaded `<link>`
2912 * element.
2913 */
2914 addStyleTag(options: FrameAddStyleTagOptions): Promise<ElementHandle<HTMLLinkElement>>;
2915 /**
2916 * Clicks the first element found that matches `selector`.
2917 *
2918 * @remarks
2919 * If `click()` triggers a navigation event and there's a separate
2920 * `page.waitForNavigation()` promise to be resolved, you may end up with a
2921 * race condition that yields unexpected results. The correct pattern for
2922 * click and wait for navigation is the following:
2923 *
2924 * ```ts
2925 * const [response] = await Promise.all([
2926 * page.waitForNavigation(waitOptions),
2927 * frame.click(selector, clickOptions),
2928 * ]);
2929 * ```
2930 *
2931 * @param selector - The selector to query for.
2932 */
2933 click(selector: string, options?: Readonly<ClickOptions>): Promise<void>;
2934 /**
2935 * Focuses the first element that matches the `selector`.
2936 *
2937 * @param selector - The selector to query for.
2938 * @throws Throws if there's no element matching `selector`.
2939 */
2940 focus(selector: string): Promise<void>;
2941 /**
2942 * Hovers the pointer over the center of the first element that matches the
2943 * `selector`.
2944 *
2945 * @param selector - The selector to query for.
2946 * @throws Throws if there's no element matching `selector`.
2947 */
2948 hover(selector: string): Promise<void>;
2949 /**
2950 * Selects a set of value on the first `<select>` element that matches the
2951 * `selector`.
2952 *
2953 * @example
2954 *
2955 * ```ts
2956 * frame.select('select#colors', 'blue'); // single selection
2957 * frame.select('select#colors', 'red', 'green', 'blue'); // multiple selections
2958 * ```
2959 *
2960 * @param selector - The selector to query for.
2961 * @param values - The array of values to select. If the `<select>` has the
2962 * `multiple` attribute, all values are considered, otherwise only the first
2963 * one is taken into account.
2964 * @returns the list of values that were successfully selected.
2965 * @throws Throws if there's no `<select>` matching `selector`.
2966 */
2967 select(selector: string, ...values: string[]): Promise<string[]>;
2968 /**
2969 * Taps the first element that matches the `selector`.
2970 *
2971 * @param selector - The selector to query for.
2972 * @throws Throws if there's no element matching `selector`.
2973 */
2974 tap(selector: string): Promise<void>;
2975 /**
2976 * Sends a `keydown`, `keypress`/`input`, and `keyup` event for each character
2977 * in the text.
2978 *
2979 * @remarks
2980 * To press a special key, like `Control` or `ArrowDown`, use
2981 * {@link Keyboard.press}.
2982 *
2983 * @example
2984 *
2985 * ```ts
2986 * await frame.type('#mytextarea', 'Hello'); // Types instantly
2987 * await frame.type('#mytextarea', 'World', {delay: 100}); // Types slower, like a user
2988 * ```
2989 *
2990 * @param selector - the selector for the element to type into. If there are
2991 * multiple the first will be used.
2992 * @param text - text to type into the element
2993 * @param options - takes one option, `delay`, which sets the time to wait
2994 * between key presses in milliseconds. Defaults to `0`.
2995 */
2996 type(selector: string, text: string, options?: Readonly<KeyboardTypeOptions>): Promise<void>;
2997 /**
2998 * The frame's title.
2999 */
3000 title(): Promise<string>;
3001
3002}
3003
3004/**
3005 * @public
3006 */
3007export declare interface FrameAddScriptTagOptions {
3008 /**
3009 * URL of the script to be added.
3010 */
3011 url?: string;
3012 /**
3013 * Path to a JavaScript file to be injected into the frame.
3014 *
3015 * @remarks
3016 * If `path` is a relative path, it is resolved relative to the current
3017 * working directory (`process.cwd()` in Node.js).
3018 */
3019 path?: string;
3020 /**
3021 * JavaScript to be injected into the frame.
3022 */
3023 content?: string;
3024 /**
3025 * Sets the `type` of the script. Use `module` in order to load an ES2015 module.
3026 */
3027 type?: string;
3028 /**
3029 * Sets the `id` of the script.
3030 */
3031 id?: string;
3032}
3033
3034/**
3035 * @public
3036 */
3037export declare interface FrameAddStyleTagOptions {
3038 /**
3039 * the URL of the CSS file to be added.
3040 */
3041 url?: string;
3042 /**
3043 * The path to a CSS file to be injected into the frame.
3044 * @remarks
3045 * If `path` is a relative path, it is resolved relative to the current
3046 * working directory (`process.cwd()` in Node.js).
3047 */
3048 path?: string;
3049 /**
3050 * Raw CSS content to be injected into the frame.
3051 */
3052 content?: string;
3053}
3054
3055/**
3056 * @public
3057 */
3058export declare interface FrameEvents extends Record<EventType, unknown> {
3059
3060
3061
3062
3063
3064
3065}
3066
3067/**
3068 * @public
3069 */
3070export declare interface FrameWaitForFunctionOptions {
3071 /**
3072 * An interval at which the `pageFunction` is executed, defaults to `raf`. If
3073 * `polling` is a number, then it is treated as an interval in milliseconds at
3074 * which the function would be executed. If `polling` is a string, then it can
3075 * be one of the following values:
3076 *
3077 * - `raf` - to constantly execute `pageFunction` in `requestAnimationFrame`
3078 * callback. This is the tightest polling mode which is suitable to observe
3079 * styling changes.
3080 *
3081 * - `mutation` - to execute `pageFunction` on every DOM mutation.
3082 */
3083 polling?: 'raf' | 'mutation' | number;
3084 /**
3085 * Maximum time to wait in milliseconds. Defaults to `30000` (30 seconds).
3086 * Pass `0` to disable the timeout. Puppeteer's default timeout can be changed
3087 * using {@link Page.setDefaultTimeout}.
3088 */
3089 timeout?: number;
3090 /**
3091 * A signal object that allows you to cancel a waitForFunction call.
3092 */
3093 signal?: AbortSignal;
3094}
3095
3096/**
3097 * @public
3098 */
3099export declare interface GeolocationOptions {
3100 /**
3101 * Latitude between `-90` and `90`.
3102 */
3103 longitude: number;
3104 /**
3105 * Longitude between `-180` and `180`.
3106 */
3107 latitude: number;
3108 /**
3109 * Optional non-negative accuracy value.
3110 */
3111 accuracy?: number;
3112}
3113
3114/**
3115 * @public
3116 */
3117export declare interface GoToOptions extends WaitForOptions {
3118 /**
3119 * If provided, it will take preference over the referer header value set by
3120 * {@link Page.setExtraHTTPHeaders | page.setExtraHTTPHeaders()}.
3121 */
3122 referer?: string;
3123 /**
3124 * If provided, it will take preference over the referer-policy header value
3125 * set by {@link Page.setExtraHTTPHeaders | page.setExtraHTTPHeaders()}.
3126 */
3127 referrerPolicy?: string;
3128}
3129
3130/**
3131 * @public
3132 */
3133export declare type HandleFor<T> = T extends Node ? ElementHandle<T> : JSHandle<T>;
3134
3135/**
3136 * @public
3137 */
3138export declare type HandleOr<T> = HandleFor<T> | JSHandle<T> | T;
3139
3140/**
3141 * @public
3142 */
3143export declare type Handler<T = unknown> = (event: T) => void;
3144
3145/**
3146 * Represents an HTTP request sent by a page.
3147 * @remarks
3148 *
3149 * Whenever the page sends a request, such as for a network resource, the
3150 * following events are emitted by Puppeteer's `page`:
3151 *
3152 * - `request`: emitted when the request is issued by the page.
3153 *
3154 * - `requestfinished` - emitted when the response body is downloaded and the
3155 * request is complete.
3156 *
3157 * If request fails at some point, then instead of `requestfinished` event the
3158 * `requestfailed` event is emitted.
3159 *
3160 * All of these events provide an instance of `HTTPRequest` representing the
3161 * request that occurred:
3162 *
3163 * ```
3164 * page.on('request', request => ...)
3165 * ```
3166 *
3167 * NOTE: HTTP Error responses, such as 404 or 503, are still successful
3168 * responses from HTTP standpoint, so request will complete with
3169 * `requestfinished` event.
3170 *
3171 * If request gets a 'redirect' response, the request is successfully finished
3172 * with the `requestfinished` event, and a new request is issued to a
3173 * redirected url.
3174 *
3175 * @public
3176 */
3177export declare abstract class HTTPRequest {
3178 #private;
3179
3180
3181
3182
3183
3184
3185
3186 /**
3187 * Warning! Using this client can break Puppeteer. Use with caution.
3188 *
3189 * @experimental
3190 */
3191 abstract get client(): CDPSession;
3192
3193 /**
3194 * The URL of the request
3195 */
3196 abstract url(): string;
3197 /**
3198 * The `ContinueRequestOverrides` that will be used
3199 * if the interception is allowed to continue (ie, `abort()` and
3200 * `respond()` aren't called).
3201 */
3202 continueRequestOverrides(): ContinueRequestOverrides;
3203 /**
3204 * The `ResponseForRequest` that gets used if the
3205 * interception is allowed to respond (ie, `abort()` is not called).
3206 */
3207 responseForRequest(): Partial<ResponseForRequest> | null;
3208 /**
3209 * The most recent reason for aborting the request
3210 */
3211 abortErrorReason(): Protocol.Network.ErrorReason | null;
3212 /**
3213 * An InterceptResolutionState object describing the current resolution
3214 * action and priority.
3215 *
3216 * InterceptResolutionState contains:
3217 * action: InterceptResolutionAction
3218 * priority?: number
3219 *
3220 * InterceptResolutionAction is one of: `abort`, `respond`, `continue`,
3221 * `disabled`, `none`, or `already-handled`.
3222 */
3223 interceptResolutionState(): InterceptResolutionState;
3224 /**
3225 * Is `true` if the intercept resolution has already been handled,
3226 * `false` otherwise.
3227 */
3228 isInterceptResolutionHandled(): boolean;
3229 /**
3230 * Adds an async request handler to the processing queue.
3231 * Deferred handlers are not guaranteed to execute in any particular order,
3232 * but they are guaranteed to resolve before the request interception
3233 * is finalized.
3234 */
3235 enqueueInterceptAction(pendingHandler: () => void | PromiseLike<unknown>): void;
3236
3237
3238
3239 /**
3240 * Awaits pending interception handlers and then decides how to fulfill
3241 * the request interception.
3242 */
3243 finalizeInterceptions(): Promise<void>;
3244 /**
3245 * Contains the request's resource type as it was perceived by the rendering
3246 * engine.
3247 */
3248 abstract resourceType(): ResourceType;
3249 /**
3250 * The method used (`GET`, `POST`, etc.)
3251 */
3252 abstract method(): string;
3253 /**
3254 * The request's post body, if any.
3255 */
3256 abstract postData(): string | undefined;
3257 /**
3258 * True when the request has POST data. Note that {@link HTTPRequest.postData}
3259 * might still be undefined when this flag is true when the data is too long
3260 * or not readily available in the decoded form. In that case, use
3261 * {@link HTTPRequest.fetchPostData}.
3262 */
3263 abstract hasPostData(): boolean;
3264 /**
3265 * Fetches the POST data for the request from the browser.
3266 */
3267 abstract fetchPostData(): Promise<string | undefined>;
3268 /**
3269 * An object with HTTP headers associated with the request. All
3270 * header names are lower-case.
3271 */
3272 abstract headers(): Record<string, string>;
3273 /**
3274 * A matching `HTTPResponse` object, or null if the response has not
3275 * been received yet.
3276 */
3277 abstract response(): HTTPResponse | null;
3278 /**
3279 * The frame that initiated the request, or null if navigating to
3280 * error pages.
3281 */
3282 abstract frame(): Frame | null;
3283 /**
3284 * True if the request is the driver of the current frame's navigation.
3285 */
3286 abstract isNavigationRequest(): boolean;
3287 /**
3288 * The initiator of the request.
3289 */
3290 abstract initiator(): Protocol.Network.Initiator | undefined;
3291 /**
3292 * A `redirectChain` is a chain of requests initiated to fetch a resource.
3293 * @remarks
3294 *
3295 * `redirectChain` is shared between all the requests of the same chain.
3296 *
3297 * For example, if the website `http://example.com` has a single redirect to
3298 * `https://example.com`, then the chain will contain one request:
3299 *
3300 * ```ts
3301 * const response = await page.goto('http://example.com');
3302 * const chain = response.request().redirectChain();
3303 * console.log(chain.length); // 1
3304 * console.log(chain[0].url()); // 'http://example.com'
3305 * ```
3306 *
3307 * If the website `https://google.com` has no redirects, then the chain will be empty:
3308 *
3309 * ```ts
3310 * const response = await page.goto('https://google.com');
3311 * const chain = response.request().redirectChain();
3312 * console.log(chain.length); // 0
3313 * ```
3314 *
3315 * @returns the chain of requests - if a server responds with at least a
3316 * single redirect, this chain will contain all requests that were redirected.
3317 */
3318 abstract redirectChain(): HTTPRequest[];
3319 /**
3320 * Access information about the request's failure.
3321 *
3322 * @remarks
3323 *
3324 * @example
3325 *
3326 * Example of logging all failed requests:
3327 *
3328 * ```ts
3329 * page.on('requestfailed', request => {
3330 * console.log(request.url() + ' ' + request.failure().errorText);
3331 * });
3332 * ```
3333 *
3334 * @returns `null` unless the request failed. If the request fails this can
3335 * return an object with `errorText` containing a human-readable error
3336 * message, e.g. `net::ERR_FAILED`. It is not guaranteed that there will be
3337 * failure text if the request fails.
3338 */
3339 abstract failure(): {
3340 errorText: string;
3341 } | null;
3342 /**
3343 * Continues request with optional request overrides.
3344 *
3345 * @example
3346 *
3347 * ```ts
3348 * await page.setRequestInterception(true);
3349 * page.on('request', request => {
3350 * // Override headers
3351 * const headers = Object.assign({}, request.headers(), {
3352 * foo: 'bar', // set "foo" header
3353 * origin: undefined, // remove "origin" header
3354 * });
3355 * request.continue({headers});
3356 * });
3357 * ```
3358 *
3359 * @param overrides - optional overrides to apply to the request.
3360 * @param priority - If provided, intercept is resolved using cooperative
3361 * handling rules. Otherwise, intercept is resolved immediately.
3362 *
3363 * @remarks
3364 *
3365 * To use this, request interception should be enabled with
3366 * {@link Page.setRequestInterception}.
3367 *
3368 * Exception is immediately thrown if the request interception is not enabled.
3369 */
3370 continue(overrides?: ContinueRequestOverrides, priority?: number): Promise<void>;
3371 /**
3372 * Fulfills a request with the given response.
3373 *
3374 * @example
3375 * An example of fulfilling all requests with 404 responses:
3376 *
3377 * ```ts
3378 * await page.setRequestInterception(true);
3379 * page.on('request', request => {
3380 * request.respond({
3381 * status: 404,
3382 * contentType: 'text/plain',
3383 * body: 'Not Found!',
3384 * });
3385 * });
3386 * ```
3387 *
3388 * NOTE: Mocking responses for dataURL requests is not supported.
3389 * Calling `request.respond` for a dataURL request is a noop.
3390 *
3391 * @param response - the response to fulfill the request with.
3392 * @param priority - If provided, intercept is resolved using
3393 * cooperative handling rules. Otherwise, intercept is resolved
3394 * immediately.
3395 *
3396 * @remarks
3397 *
3398 * To use this, request
3399 * interception should be enabled with {@link Page.setRequestInterception}.
3400 *
3401 * Exception is immediately thrown if the request interception is not enabled.
3402 */
3403 respond(response: Partial<ResponseForRequest>, priority?: number): Promise<void>;
3404 /**
3405 * Aborts a request.
3406 *
3407 * @param errorCode - optional error code to provide.
3408 * @param priority - If provided, intercept is resolved using
3409 * cooperative handling rules. Otherwise, intercept is resolved
3410 * immediately.
3411 *
3412 * @remarks
3413 *
3414 * To use this, request interception should be enabled with
3415 * {@link Page.setRequestInterception}. If it is not enabled, this method will
3416 * throw an exception immediately.
3417 */
3418 abort(errorCode?: ErrorCode, priority?: number): Promise<void>;
3419
3420}
3421
3422/**
3423 * The HTTPResponse class represents responses which are received by the
3424 * {@link Page} class.
3425 *
3426 * @public
3427 */
3428export declare abstract class HTTPResponse {
3429
3430 /**
3431 * The IP address and port number used to connect to the remote
3432 * server.
3433 */
3434 abstract remoteAddress(): RemoteAddress;
3435 /**
3436 * The URL of the response.
3437 */
3438 abstract url(): string;
3439 /**
3440 * True if the response was successful (status in the range 200-299).
3441 */
3442 ok(): boolean;
3443 /**
3444 * The status code of the response (e.g., 200 for a success).
3445 */
3446 abstract status(): number;
3447 /**
3448 * The status text of the response (e.g. usually an "OK" for a
3449 * success).
3450 */
3451 abstract statusText(): string;
3452 /**
3453 * An object with HTTP headers associated with the response. All
3454 * header names are lower-case.
3455 */
3456 abstract headers(): Record<string, string>;
3457 /**
3458 * {@link SecurityDetails} if the response was received over the
3459 * secure connection, or `null` otherwise.
3460 */
3461 abstract securityDetails(): SecurityDetails | null;
3462 /**
3463 * Timing information related to the response.
3464 */
3465 abstract timing(): Protocol.Network.ResourceTiming | null;
3466 /**
3467 * Promise which resolves to a buffer with response body.
3468 *
3469 * @remarks
3470 *
3471 * The buffer might be re-encoded by the browser
3472 * based on HTTP-headers or other heuristics. If the browser
3473 * failed to detect the correct encoding, the buffer might
3474 * be encoded incorrectly. See https://github.com/puppeteer/puppeteer/issues/6478.
3475 */
3476 abstract content(): Promise<Uint8Array>;
3477 /**
3478 * {@inheritDoc HTTPResponse.content}
3479 */
3480 buffer(): Promise<Buffer>;
3481 /**
3482 * Promise which resolves to a text (utf8) representation of response body.
3483 */
3484 text(): Promise<string>;
3485 /**
3486 * Promise which resolves to a JSON representation of response body.
3487 *
3488 * @remarks
3489 *
3490 * This method will throw if the response body is not parsable via
3491 * `JSON.parse`.
3492 */
3493 json(): Promise<any>;
3494 /**
3495 * A matching {@link HTTPRequest} object.
3496 */
3497 abstract request(): HTTPRequest;
3498 /**
3499 * True if the response was served from either the browser's disk
3500 * cache or memory cache.
3501 */
3502 abstract fromCache(): boolean;
3503 /**
3504 * True if the response was served by a service worker.
3505 */
3506 abstract fromServiceWorker(): boolean;
3507 /**
3508 * A {@link Frame} that initiated this response, or `null` if
3509 * navigating to error pages.
3510 */
3511 abstract frame(): Frame | null;
3512}
3513
3514/**
3515 * @public
3516 */
3517export declare type InnerParams<T extends unknown[]> = {
3518 [K in keyof T]: FlattenHandle<T[K]>;
3519};
3520
3521/**
3522 * @public
3523 */
3524export declare enum InterceptResolutionAction {
3525 Abort = "abort",
3526 Respond = "respond",
3527 Continue = "continue",
3528 Disabled = "disabled",
3529 None = "none",
3530 AlreadyHandled = "already-handled"
3531}
3532
3533/**
3534 * @public
3535 */
3536export declare interface InterceptResolutionState {
3537 action: InterceptResolutionAction;
3538 priority?: number;
3539}
3540
3541/**
3542 * @public
3543 */
3544export declare interface InternalNetworkConditions extends NetworkConditions {
3545 offline: boolean;
3546}
3547
3548/**
3549 * @public
3550 */
3551export declare class JSCoverage {
3552 #private;
3553
3554
3555 start(options?: {
3556 resetOnNavigation?: boolean;
3557 reportAnonymousScripts?: boolean;
3558 includeRawScriptCoverage?: boolean;
3559 useBlockCoverage?: boolean;
3560 }): Promise<void>;
3561 stop(): Promise<JSCoverageEntry[]>;
3562}
3563
3564/**
3565 * The CoverageEntry class for JavaScript
3566 * @public
3567 */
3568export declare interface JSCoverageEntry extends CoverageEntry {
3569 /**
3570 * Raw V8 script coverage entry.
3571 */
3572 rawScriptCoverage?: Protocol.Profiler.ScriptCoverage;
3573}
3574
3575/**
3576 * Set of configurable options for JS coverage.
3577 * @public
3578 */
3579export declare interface JSCoverageOptions {
3580 /**
3581 * Whether to reset coverage on every navigation.
3582 */
3583 resetOnNavigation?: boolean;
3584 /**
3585 * Whether anonymous scripts generated by the page should be reported.
3586 */
3587 reportAnonymousScripts?: boolean;
3588 /**
3589 * Whether the result includes raw V8 script coverage entries.
3590 */
3591 includeRawScriptCoverage?: boolean;
3592 /**
3593 * Whether to collect coverage information at the block level.
3594 * If true, coverage will be collected at the block level (this is the default).
3595 * If false, coverage will be collected at the function level.
3596 */
3597 useBlockCoverage?: boolean;
3598}
3599
3600/**
3601 * Represents a reference to a JavaScript object. Instances can be created using
3602 * {@link Page.evaluateHandle}.
3603 *
3604 * Handles prevent the referenced JavaScript object from being garbage-collected
3605 * unless the handle is purposely {@link JSHandle.dispose | disposed}. JSHandles
3606 * are auto-disposed when their associated frame is navigated away or the parent
3607 * context gets destroyed.
3608 *
3609 * Handles can be used as arguments for any evaluation function such as
3610 * {@link Page.$eval}, {@link Page.evaluate}, and {@link Page.evaluateHandle}.
3611 * They are resolved to their referenced object.
3612 *
3613 * @example
3614 *
3615 * ```ts
3616 * const windowHandle = await page.evaluateHandle(() => window);
3617 * ```
3618 *
3619 * @public
3620 */
3621export declare abstract class JSHandle<T = unknown> {
3622 move: () => this;
3623 /**
3624 * Used for nominally typing {@link JSHandle}.
3625 */
3626 _?: T;
3627
3628
3629
3630 /**
3631 * Evaluates the given function with the current handle as its first argument.
3632 */
3633 evaluate<Params extends unknown[], Func extends EvaluateFuncWith<T, Params> = EvaluateFuncWith<T, Params>>(pageFunction: Func | string, ...args: Params): Promise<Awaited<ReturnType<Func>>>;
3634 /**
3635 * Evaluates the given function with the current handle as its first argument.
3636 *
3637 */
3638 evaluateHandle<Params extends unknown[], Func extends EvaluateFuncWith<T, Params> = EvaluateFuncWith<T, Params>>(pageFunction: Func | string, ...args: Params): Promise<HandleFor<Awaited<ReturnType<Func>>>>;
3639 /**
3640 * Fetches a single property from the referenced object.
3641 */
3642 getProperty<K extends keyof T>(propertyName: HandleOr<K>): Promise<HandleFor<T[K]>>;
3643 getProperty(propertyName: string): Promise<JSHandle<unknown>>;
3644 /**
3645 * Gets a map of handles representing the properties of the current handle.
3646 *
3647 * @example
3648 *
3649 * ```ts
3650 * const listHandle = await page.evaluateHandle(() => document.body.children);
3651 * const properties = await listHandle.getProperties();
3652 * const children = [];
3653 * for (const property of properties.values()) {
3654 * const element = property.asElement();
3655 * if (element) {
3656 * children.push(element);
3657 * }
3658 * }
3659 * children; // holds elementHandles to all children of document.body
3660 * ```
3661 */
3662 getProperties(): Promise<Map<string, JSHandle>>;
3663 /**
3664 * A vanilla object representing the serializable portions of the
3665 * referenced object.
3666 * @throws Throws if the object cannot be serialized due to circularity.
3667 *
3668 * @remarks
3669 * If the object has a `toJSON` function, it **will not** be called.
3670 */
3671 abstract jsonValue(): Promise<T>;
3672 /**
3673 * Either `null` or the handle itself if the handle is an
3674 * instance of {@link ElementHandle}.
3675 */
3676 abstract asElement(): ElementHandle<Node> | null;
3677 /**
3678 * Releases the object referenced by the handle for garbage collection.
3679 */
3680 abstract dispose(): Promise<void>;
3681 /**
3682 * Returns a string representation of the JSHandle.
3683 *
3684 * @remarks
3685 * Useful during debugging.
3686 */
3687 abstract toString(): string;
3688
3689 /**
3690 * Provides access to the
3691 * {@link https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#type-RemoteObject | Protocol.Runtime.RemoteObject}
3692 * backing this handle.
3693 */
3694 abstract remoteObject(): Protocol.Runtime.RemoteObject;
3695
3696
3697}
3698
3699/**
3700 * Keyboard provides an api for managing a virtual keyboard.
3701 * The high level api is {@link Keyboard."type"},
3702 * which takes raw characters and generates proper keydown, keypress/input,
3703 * and keyup events on your page.
3704 *
3705 * @remarks
3706 * For finer control, you can use {@link Keyboard.down},
3707 * {@link Keyboard.up}, and {@link Keyboard.sendCharacter}
3708 * to manually fire events as if they were generated from a real keyboard.
3709 *
3710 * On macOS, keyboard shortcuts like `⌘ A` -\> Select All do not work.
3711 * See {@link https://github.com/puppeteer/puppeteer/issues/1313 | #1313}.
3712 *
3713 * @example
3714 * An example of holding down `Shift` in order to select and delete some text:
3715 *
3716 * ```ts
3717 * await page.keyboard.type('Hello World!');
3718 * await page.keyboard.press('ArrowLeft');
3719 *
3720 * await page.keyboard.down('Shift');
3721 * for (let i = 0; i < ' World'.length; i++)
3722 * await page.keyboard.press('ArrowLeft');
3723 * await page.keyboard.up('Shift');
3724 *
3725 * await page.keyboard.press('Backspace');
3726 * // Result text will end up saying 'Hello!'
3727 * ```
3728 *
3729 * @example
3730 * An example of pressing `A`
3731 *
3732 * ```ts
3733 * await page.keyboard.down('Shift');
3734 * await page.keyboard.press('KeyA');
3735 * await page.keyboard.up('Shift');
3736 * ```
3737 *
3738 * @public
3739 */
3740export declare abstract class Keyboard {
3741
3742 /**
3743 * Dispatches a `keydown` event.
3744 *
3745 * @remarks
3746 * If `key` is a single character and no modifier keys besides `Shift`
3747 * are being held down, a `keypress`/`input` event will also generated.
3748 * The `text` option can be specified to force an input event to be generated.
3749 * If `key` is a modifier key, `Shift`, `Meta`, `Control`, or `Alt`,
3750 * subsequent key presses will be sent with that modifier active.
3751 * To release the modifier key, use {@link Keyboard.up}.
3752 *
3753 * After the key is pressed once, subsequent calls to
3754 * {@link Keyboard.down} will have
3755 * {@link https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/repeat | repeat}
3756 * set to true. To release the key, use {@link Keyboard.up}.
3757 *
3758 * Modifier keys DO influence {@link Keyboard.down}.
3759 * Holding down `Shift` will type the text in upper case.
3760 *
3761 * @param key - Name of key to press, such as `ArrowLeft`.
3762 * See {@link KeyInput} for a list of all key names.
3763 *
3764 * @param options - An object of options. Accepts text which, if specified,
3765 * generates an input event with this text. Accepts commands which, if specified,
3766 * is the commands of keyboard shortcuts,
3767 * see {@link https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/editing/commands/editor_command_names.h | Chromium Source Code} for valid command names.
3768 */
3769 abstract down(key: KeyInput, options?: Readonly<KeyDownOptions>): Promise<void>;
3770 /**
3771 * Dispatches a `keyup` event.
3772 *
3773 * @param key - Name of key to release, such as `ArrowLeft`.
3774 * See {@link KeyInput | KeyInput}
3775 * for a list of all key names.
3776 */
3777 abstract up(key: KeyInput): Promise<void>;
3778 /**
3779 * Dispatches a `keypress` and `input` event.
3780 * This does not send a `keydown` or `keyup` event.
3781 *
3782 * @remarks
3783 * Modifier keys DO NOT effect {@link Keyboard.sendCharacter | Keyboard.sendCharacter}.
3784 * Holding down `Shift` will not type the text in upper case.
3785 *
3786 * @example
3787 *
3788 * ```ts
3789 * page.keyboard.sendCharacter('嗨');
3790 * ```
3791 *
3792 * @param char - Character to send into the page.
3793 */
3794 abstract sendCharacter(char: string): Promise<void>;
3795 /**
3796 * Sends a `keydown`, `keypress`/`input`,
3797 * and `keyup` event for each character in the text.
3798 *
3799 * @remarks
3800 * To press a special key, like `Control` or `ArrowDown`,
3801 * use {@link Keyboard.press}.
3802 *
3803 * Modifier keys DO NOT effect `keyboard.type`.
3804 * Holding down `Shift` will not type the text in upper case.
3805 *
3806 * @example
3807 *
3808 * ```ts
3809 * await page.keyboard.type('Hello'); // Types instantly
3810 * await page.keyboard.type('World', {delay: 100}); // Types slower, like a user
3811 * ```
3812 *
3813 * @param text - A text to type into a focused element.
3814 * @param options - An object of options. Accepts delay which,
3815 * if specified, is the time to wait between `keydown` and `keyup` in milliseconds.
3816 * Defaults to 0.
3817 */
3818 abstract type(text: string, options?: Readonly<KeyboardTypeOptions>): Promise<void>;
3819 /**
3820 * Shortcut for {@link Keyboard.down}
3821 * and {@link Keyboard.up}.
3822 *
3823 * @remarks
3824 * If `key` is a single character and no modifier keys besides `Shift`
3825 * are being held down, a `keypress`/`input` event will also generated.
3826 * The `text` option can be specified to force an input event to be generated.
3827 *
3828 * Modifier keys DO effect {@link Keyboard.press}.
3829 * Holding down `Shift` will type the text in upper case.
3830 *
3831 * @param key - Name of key to press, such as `ArrowLeft`.
3832 * See {@link KeyInput} for a list of all key names.
3833 *
3834 * @param options - An object of options. Accepts text which, if specified,
3835 * generates an input event with this text. Accepts delay which,
3836 * if specified, is the time to wait between `keydown` and `keyup` in milliseconds.
3837 * Defaults to 0. Accepts commands which, if specified,
3838 * is the commands of keyboard shortcuts,
3839 * see {@link https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/editing/commands/editor_command_names.h | Chromium Source Code} for valid command names.
3840 */
3841 abstract press(key: KeyInput, options?: Readonly<KeyPressOptions>): Promise<void>;
3842}
3843
3844/**
3845 * @public
3846 */
3847export declare interface KeyboardTypeOptions {
3848 delay?: number;
3849}
3850
3851/**
3852 * @public
3853 */
3854export declare interface KeyDownOptions {
3855 /**
3856 * @deprecated Do not use. This is automatically handled.
3857 */
3858 text?: string;
3859 /**
3860 * @deprecated Do not use. This is automatically handled.
3861 */
3862 commands?: string[];
3863}
3864
3865/**
3866 * All the valid keys that can be passed to functions that take user input, such
3867 * as {@link Keyboard.press | keyboard.press }
3868 *
3869 * @public
3870 */
3871export declare type KeyInput = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | 'Power' | 'Eject' | 'Abort' | 'Help' | 'Backspace' | 'Tab' | 'Numpad5' | 'NumpadEnter' | 'Enter' | '\r' | '\n' | 'ShiftLeft' | 'ShiftRight' | 'ControlLeft' | 'ControlRight' | 'AltLeft' | 'AltRight' | 'Pause' | 'CapsLock' | 'Escape' | 'Convert' | 'NonConvert' | 'Space' | 'Numpad9' | 'PageUp' | 'Numpad3' | 'PageDown' | 'End' | 'Numpad1' | 'Home' | 'Numpad7' | 'ArrowLeft' | 'Numpad4' | 'Numpad8' | 'ArrowUp' | 'ArrowRight' | 'Numpad6' | 'Numpad2' | 'ArrowDown' | 'Select' | 'Open' | 'PrintScreen' | 'Insert' | 'Numpad0' | 'Delete' | 'NumpadDecimal' | 'Digit0' | 'Digit1' | 'Digit2' | 'Digit3' | 'Digit4' | 'Digit5' | 'Digit6' | 'Digit7' | 'Digit8' | 'Digit9' | 'KeyA' | 'KeyB' | 'KeyC' | 'KeyD' | 'KeyE' | 'KeyF' | 'KeyG' | 'KeyH' | 'KeyI' | 'KeyJ' | 'KeyK' | 'KeyL' | 'KeyM' | 'KeyN' | 'KeyO' | 'KeyP' | 'KeyQ' | 'KeyR' | 'KeyS' | 'KeyT' | 'KeyU' | 'KeyV' | 'KeyW' | 'KeyX' | 'KeyY' | 'KeyZ' | 'MetaLeft' | 'MetaRight' | 'ContextMenu' | 'NumpadMultiply' | 'NumpadAdd' | 'NumpadSubtract' | 'NumpadDivide' | 'F1' | 'F2' | 'F3' | 'F4' | 'F5' | 'F6' | 'F7' | 'F8' | 'F9' | 'F10' | 'F11' | 'F12' | 'F13' | 'F14' | 'F15' | 'F16' | 'F17' | 'F18' | 'F19' | 'F20' | 'F21' | 'F22' | 'F23' | 'F24' | 'NumLock' | 'ScrollLock' | 'AudioVolumeMute' | 'AudioVolumeDown' | 'AudioVolumeUp' | 'MediaTrackNext' | 'MediaTrackPrevious' | 'MediaStop' | 'MediaPlayPause' | 'Semicolon' | 'Equal' | 'NumpadEqual' | 'Comma' | 'Minus' | 'Period' | 'Slash' | 'Backquote' | 'BracketLeft' | 'Backslash' | 'BracketRight' | 'Quote' | 'AltGraph' | 'Props' | 'Cancel' | 'Clear' | 'Shift' | 'Control' | 'Alt' | 'Accept' | 'ModeChange' | ' ' | 'Print' | 'Execute' | '\u0000' | 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z' | 'Meta' | '*' | '+' | '-' | '/' | ';' | '=' | ',' | '.' | '`' | '[' | '\\' | ']' | "'" | 'Attn' | 'CrSel' | 'ExSel' | 'EraseEof' | 'Play' | 'ZoomOut' | ')' | '!' | '@' | '#' | '$' | '%' | '^' | '&' | '(' | 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z' | ':' | '<' | '_' | '>' | '?' | '~' | '{' | '|' | '}' | '"' | 'SoftLeft' | 'SoftRight' | 'Camera' | 'Call' | 'EndCall' | 'VolumeDown' | 'VolumeUp';
3872
3873/**
3874 * @public
3875 */
3876export declare type KeyPressOptions = KeyDownOptions & KeyboardTypeOptions;
3877
3878/**
3879 * A list of devices to be used with {@link Page.emulate}.
3880 *
3881 * @example
3882 *
3883 * ```ts
3884 * import {KnownDevices} from 'puppeteer';
3885 * const iPhone = KnownDevices['iPhone 15 Pro'];
3886 *
3887 * (async () => {
3888 * const browser = await puppeteer.launch();
3889 * const page = await browser.newPage();
3890 * await page.emulate(iPhone);
3891 * await page.goto('https://www.google.com');
3892 * // other actions...
3893 * await browser.close();
3894 * })();
3895 * ```
3896 *
3897 * @public
3898 */
3899export declare const KnownDevices: Readonly<Record<"Blackberry PlayBook" | "Blackberry PlayBook landscape" | "BlackBerry Z30" | "BlackBerry Z30 landscape" | "Galaxy Note 3" | "Galaxy Note 3 landscape" | "Galaxy Note II" | "Galaxy Note II landscape" | "Galaxy S III" | "Galaxy S III landscape" | "Galaxy S5" | "Galaxy S5 landscape" | "Galaxy S8" | "Galaxy S8 landscape" | "Galaxy S9+" | "Galaxy S9+ landscape" | "Galaxy Tab S4" | "Galaxy Tab S4 landscape" | "iPad" | "iPad landscape" | "iPad (gen 6)" | "iPad (gen 6) landscape" | "iPad (gen 7)" | "iPad (gen 7) landscape" | "iPad Mini" | "iPad Mini landscape" | "iPad Pro" | "iPad Pro landscape" | "iPad Pro 11" | "iPad Pro 11 landscape" | "iPhone 4" | "iPhone 4 landscape" | "iPhone 5" | "iPhone 5 landscape" | "iPhone 6" | "iPhone 6 landscape" | "iPhone 6 Plus" | "iPhone 6 Plus landscape" | "iPhone 7" | "iPhone 7 landscape" | "iPhone 7 Plus" | "iPhone 7 Plus landscape" | "iPhone 8" | "iPhone 8 landscape" | "iPhone 8 Plus" | "iPhone 8 Plus landscape" | "iPhone SE" | "iPhone SE landscape" | "iPhone X" | "iPhone X landscape" | "iPhone XR" | "iPhone XR landscape" | "iPhone 11" | "iPhone 11 landscape" | "iPhone 11 Pro" | "iPhone 11 Pro landscape" | "iPhone 11 Pro Max" | "iPhone 11 Pro Max landscape" | "iPhone 12" | "iPhone 12 landscape" | "iPhone 12 Pro" | "iPhone 12 Pro landscape" | "iPhone 12 Pro Max" | "iPhone 12 Pro Max landscape" | "iPhone 12 Mini" | "iPhone 12 Mini landscape" | "iPhone 13" | "iPhone 13 landscape" | "iPhone 13 Pro" | "iPhone 13 Pro landscape" | "iPhone 13 Pro Max" | "iPhone 13 Pro Max landscape" | "iPhone 13 Mini" | "iPhone 13 Mini landscape" | "iPhone 14" | "iPhone 14 landscape" | "iPhone 14 Plus" | "iPhone 14 Plus landscape" | "iPhone 14 Pro" | "iPhone 14 Pro landscape" | "iPhone 14 Pro Max" | "iPhone 14 Pro Max landscape" | "iPhone 15" | "iPhone 15 landscape" | "iPhone 15 Plus" | "iPhone 15 Plus landscape" | "iPhone 15 Pro" | "iPhone 15 Pro landscape" | "iPhone 15 Pro Max" | "iPhone 15 Pro Max landscape" | "JioPhone 2" | "JioPhone 2 landscape" | "Kindle Fire HDX" | "Kindle Fire HDX landscape" | "LG Optimus L70" | "LG Optimus L70 landscape" | "Microsoft Lumia 550" | "Microsoft Lumia 950" | "Microsoft Lumia 950 landscape" | "Nexus 10" | "Nexus 10 landscape" | "Nexus 4" | "Nexus 4 landscape" | "Nexus 5" | "Nexus 5 landscape" | "Nexus 5X" | "Nexus 5X landscape" | "Nexus 6" | "Nexus 6 landscape" | "Nexus 6P" | "Nexus 6P landscape" | "Nexus 7" | "Nexus 7 landscape" | "Nokia Lumia 520" | "Nokia Lumia 520 landscape" | "Nokia N9" | "Nokia N9 landscape" | "Pixel 2" | "Pixel 2 landscape" | "Pixel 2 XL" | "Pixel 2 XL landscape" | "Pixel 3" | "Pixel 3 landscape" | "Pixel 4" | "Pixel 4 landscape" | "Pixel 4a (5G)" | "Pixel 4a (5G) landscape" | "Pixel 5" | "Pixel 5 landscape" | "Moto G4" | "Moto G4 landscape", Device>>;
3900
3901/**
3902 * @public
3903 */
3904export declare const
3905/**
3906* @public
3907*/
3908/**
3909 * @public
3910 */
3911launch: (options?: Puppeteer_2.LaunchOptions) => Promise<Puppeteer_2.Browser>;
3912
3913/**
3914 * Generic launch options that can be passed when launching any browser.
3915 * @public
3916 */
3917export declare interface LaunchOptions extends ConnectOptions {
3918 /**
3919 * If specified for Chrome, looks for a regular Chrome installation at a known
3920 * system location instead of using the bundled Chrome binary.
3921 */
3922 channel?: ChromeReleaseChannel;
3923 /**
3924 * Path to a browser executable to use instead of the bundled browser. Note
3925 * that Puppeteer is only guaranteed to work with the bundled browser, so use
3926 * this setting at your own risk.
3927 *
3928 * @remarks
3929 * When using this is recommended to set the `browser` property as well
3930 * as Puppeteer will default to `chrome` by default.
3931 */
3932 executablePath?: string;
3933 /**
3934 * If `true`, do not use `puppeteer.defaultArgs()` when creating a browser. If
3935 * an array is provided, these args will be filtered out. Use this with care -
3936 * you probably want the default arguments Puppeteer uses.
3937 * @defaultValue `false`
3938 */
3939 ignoreDefaultArgs?: boolean | string[];
3940 /**
3941 * Close the browser process on `Ctrl+C`.
3942 * @defaultValue `true`
3943 */
3944 handleSIGINT?: boolean;
3945 /**
3946 * Close the browser process on `SIGTERM`.
3947 * @defaultValue `true`
3948 */
3949 handleSIGTERM?: boolean;
3950 /**
3951 * Close the browser process on `SIGHUP`.
3952 * @defaultValue `true`
3953 */
3954 handleSIGHUP?: boolean;
3955 /**
3956 * Maximum time in milliseconds to wait for the browser to start.
3957 * Pass `0` to disable the timeout.
3958 * @defaultValue `30_000` (30 seconds).
3959 */
3960 timeout?: number;
3961 /**
3962 * If true, pipes the browser process stdout and stderr to `process.stdout`
3963 * and `process.stderr`.
3964 * @defaultValue `false`
3965 */
3966 dumpio?: boolean;
3967 /**
3968 * Specify environment variables that will be visible to the browser.
3969 * @defaultValue The contents of `process.env`.
3970 */
3971 env?: Record<string, string | undefined>;
3972 /**
3973 * Connect to a browser over a pipe instead of a WebSocket. Only supported
3974 * with Chrome.
3975 *
3976 * @defaultValue `false`
3977 */
3978 pipe?: boolean;
3979 /**
3980 * Which browser to launch.
3981 * @defaultValue `chrome`
3982 */
3983 browser?: SupportedBrowser;
3984 /**
3985 * {@link https://searchfox.org/mozilla-release/source/modules/libpref/init/all.js | Additional preferences } that can be passed when launching with Firefox.
3986 */
3987 extraPrefsFirefox?: Record<string, unknown>;
3988 /**
3989 * Whether to wait for the initial page to be ready.
3990 * Useful when a user explicitly disables that (e.g. `--no-startup-window` for Chrome).
3991 * @defaultValue `true`
3992 */
3993 waitForInitialPage?: boolean;
3994 /**
3995 * Whether to run the browser in headless mode.
3996 *
3997 * @remarks
3998 *
3999 * - `true` launches the browser in the
4000 * {@link https://developer.chrome.com/articles/new-headless/ | new headless}
4001 * mode.
4002 *
4003 * - `'shell'` launches
4004 * {@link https://developer.chrome.com/blog/chrome-headless-shell | shell}
4005 * known as the old headless mode.
4006 *
4007 * @defaultValue `true`
4008 */
4009 headless?: boolean | 'shell';
4010 /**
4011 * Path to a user data directory.
4012 * {@link https://chromium.googlesource.com/chromium/src/+/refs/heads/main/docs/user_data_dir.md | see the Chromium docs}
4013 * for more info.
4014 */
4015 userDataDir?: string;
4016 /**
4017 * Whether to auto-open a DevTools panel for each tab. If this is set to
4018 * `true`, then `headless` will be forced to `false`.
4019 * @defaultValue `false`
4020 */
4021 devtools?: boolean;
4022 /**
4023 * Specify the debugging port number to use
4024 */
4025 debuggingPort?: number;
4026 /**
4027 * Additional command line arguments to pass to the browser instance.
4028 */
4029 args?: string[];
4030}
4031
4032/**
4033 * Locators describe a strategy of locating objects and performing an action on
4034 * them. If the action fails because the object is not ready for the action, the
4035 * whole operation is retried. Various preconditions for a successful action are
4036 * checked automatically.
4037 *
4038 * See {@link https://pptr.dev/guides/page-interactions#locators} for details.
4039 *
4040 * @public
4041 */
4042export declare abstract class Locator<T> extends EventEmitter<LocatorEvents> {
4043 #private;
4044 /**
4045 * Creates a race between multiple locators trying to locate elements in
4046 * parallel but ensures that only a single element receives the action.
4047 *
4048 * @public
4049 */
4050 static race<Locators extends readonly unknown[] | []>(locators: Locators): Locator<AwaitedLocator<Locators[number]>>;
4051 /**
4052 * Used for nominally typing {@link Locator}.
4053 */
4054 _?: T;
4055
4056
4057
4058 get timeout(): number;
4059 /**
4060 * Creates a new locator instance by cloning the current locator and setting
4061 * the total timeout for the locator actions.
4062 *
4063 * Pass `0` to disable timeout.
4064 *
4065 * @defaultValue `Page.getDefaultTimeout()`
4066 */
4067 setTimeout(timeout: number): Locator<T>;
4068 /**
4069 * Creates a new locator instance by cloning the current locator with the
4070 * visibility property changed to the specified value.
4071 */
4072 setVisibility<NodeType extends Node>(this: Locator<NodeType>, visibility: VisibilityOption): Locator<NodeType>;
4073 /**
4074 * Creates a new locator instance by cloning the current locator and
4075 * specifying whether to wait for input elements to become enabled before the
4076 * action. Applicable to `click` and `fill` actions.
4077 *
4078 * @defaultValue `true`
4079 */
4080 setWaitForEnabled<NodeType extends Node>(this: Locator<NodeType>, value: boolean): Locator<NodeType>;
4081 /**
4082 * Creates a new locator instance by cloning the current locator and
4083 * specifying whether the locator should scroll the element into viewport if
4084 * it is not in the viewport already.
4085 *
4086 * @defaultValue `true`
4087 */
4088 setEnsureElementIsInTheViewport<ElementType extends Element>(this: Locator<ElementType>, value: boolean): Locator<ElementType>;
4089 /**
4090 * Creates a new locator instance by cloning the current locator and
4091 * specifying whether the locator has to wait for the element's bounding box
4092 * to be same between two consecutive animation frames.
4093 *
4094 * @defaultValue `true`
4095 */
4096 setWaitForStableBoundingBox<ElementType extends Element>(this: Locator<ElementType>, value: boolean): Locator<ElementType>;
4097
4098
4099
4100 /**
4101 * Clones the locator.
4102 */
4103 clone(): Locator<T>;
4104 /**
4105 * Waits for the locator to get a handle from the page.
4106 *
4107 * @public
4108 */
4109 waitHandle(options?: Readonly<ActionOptions>): Promise<HandleFor<T>>;
4110 /**
4111 * Waits for the locator to get the serialized value from the page.
4112 *
4113 * Note this requires the value to be JSON-serializable.
4114 *
4115 * @public
4116 */
4117 wait(options?: Readonly<ActionOptions>): Promise<T>;
4118 /**
4119 * Maps the locator using the provided mapper.
4120 *
4121 * @public
4122 */
4123 map<To>(mapper: Mapper<T, To>): Locator<To>;
4124 /**
4125 * Creates an expectation that is evaluated against located values.
4126 *
4127 * If the expectations do not match, then the locator will retry.
4128 *
4129 * @public
4130 */
4131 filter<S extends T>(predicate: Predicate<T, S>): Locator<S>;
4132
4133
4134 /**
4135 * Clicks the located element.
4136 */
4137 click<ElementType extends Element>(this: Locator<ElementType>, options?: Readonly<LocatorClickOptions>): Promise<void>;
4138 /**
4139 * Fills out the input identified by the locator using the provided value. The
4140 * type of the input is determined at runtime and the appropriate fill-out
4141 * method is chosen based on the type. `contenteditable`, select, textarea and
4142 * input elements are supported.
4143 */
4144 fill<ElementType extends Element>(this: Locator<ElementType>, value: string, options?: Readonly<ActionOptions>): Promise<void>;
4145 /**
4146 * Hovers over the located element.
4147 */
4148 hover<ElementType extends Element>(this: Locator<ElementType>, options?: Readonly<ActionOptions>): Promise<void>;
4149 /**
4150 * Scrolls the located element.
4151 */
4152 scroll<ElementType extends Element>(this: Locator<ElementType>, options?: Readonly<LocatorScrollOptions>): Promise<void>;
4153}
4154
4155/**
4156 * @public
4157 */
4158export declare type LocatorClickOptions = ClickOptions & ActionOptions;
4159
4160/**
4161 * All the events that a locator instance may emit.
4162 *
4163 * @public
4164 */
4165export declare enum LocatorEvent {
4166 /**
4167 * Emitted every time before the locator performs an action on the located element(s).
4168 */
4169 Action = "action"
4170}
4171
4172/**
4173 * @public
4174 */
4175export declare interface LocatorEvents extends Record<EventType, unknown> {
4176 [LocatorEvent.Action]: undefined;
4177}
4178
4179/**
4180 * @public
4181 */
4182export declare interface LocatorScrollOptions extends ActionOptions {
4183 scrollTop?: number;
4184 scrollLeft?: number;
4185}
4186
4187/**
4188 * @public
4189 */
4190export declare type LowerCasePaperFormat = 'letter' | 'legal' | 'tabloid' | 'ledger' | 'a0' | 'a1' | 'a2' | 'a3' | 'a4' | 'a5' | 'a6';
4191
4192/**
4193 * @public
4194 */
4195export declare type Mapper<From, To> = (value: From) => Awaitable<To>;
4196
4197/**
4198 * A media feature to emulate.
4199 *
4200 * @public
4201 */
4202export declare interface MediaFeature {
4203 /**
4204 * A name of the feature, for example, 'prefers-reduced-motion'.
4205 */
4206 name: string;
4207 /**
4208 * A value for the feature, for example, 'reduce'.
4209 */
4210 value: string;
4211}
4212
4213/**
4214 * @public
4215 */
4216export declare interface Metrics {
4217 Timestamp?: number;
4218 Documents?: number;
4219 Frames?: number;
4220 JSEventListeners?: number;
4221 Nodes?: number;
4222 LayoutCount?: number;
4223 RecalcStyleCount?: number;
4224 LayoutDuration?: number;
4225 RecalcStyleDuration?: number;
4226 ScriptDuration?: number;
4227 TaskDuration?: number;
4228 JSHeapUsedSize?: number;
4229 JSHeapTotalSize?: number;
4230}
4231
4232/**
4233 * The Mouse class operates in main-frame CSS pixels
4234 * relative to the top-left corner of the viewport.
4235 *
4236 * @remarks
4237 * Every `page` object has its own Mouse, accessible with {@link Page.mouse}.
4238 *
4239 * @example
4240 *
4241 * ```ts
4242 * // Using ‘page.mouse’ to trace a 100x100 square.
4243 * await page.mouse.move(0, 0);
4244 * await page.mouse.down();
4245 * await page.mouse.move(0, 100);
4246 * await page.mouse.move(100, 100);
4247 * await page.mouse.move(100, 0);
4248 * await page.mouse.move(0, 0);
4249 * await page.mouse.up();
4250 * ```
4251 *
4252 * **Note**: The mouse events trigger synthetic `MouseEvent`s.
4253 * This means that it does not fully replicate the functionality of what a normal user
4254 * would be able to do with their mouse.
4255 *
4256 * For example, dragging and selecting text is not possible using `page.mouse`.
4257 * Instead, you can use the {@link https://developer.mozilla.org/en-US/docs/Web/API/DocumentOrShadowRoot/getSelection | `DocumentOrShadowRoot.getSelection()`} functionality implemented in the platform.
4258 *
4259 * @example
4260 * For example, if you want to select all content between nodes:
4261 *
4262 * ```ts
4263 * await page.evaluate(
4264 * (from, to) => {
4265 * const selection = from.getRootNode().getSelection();
4266 * const range = document.createRange();
4267 * range.setStartBefore(from);
4268 * range.setEndAfter(to);
4269 * selection.removeAllRanges();
4270 * selection.addRange(range);
4271 * },
4272 * fromJSHandle,
4273 * toJSHandle,
4274 * );
4275 * ```
4276 *
4277 * If you then would want to copy-paste your selection, you can use the clipboard api:
4278 *
4279 * ```ts
4280 * // The clipboard api does not allow you to copy, unless the tab is focused.
4281 * await page.bringToFront();
4282 * await page.evaluate(() => {
4283 * // Copy the selected content to the clipboard
4284 * document.execCommand('copy');
4285 * // Obtain the content of the clipboard as a string
4286 * return navigator.clipboard.readText();
4287 * });
4288 * ```
4289 *
4290 * **Note**: If you want access to the clipboard API,
4291 * you have to give it permission to do so:
4292 *
4293 * ```ts
4294 * await browser
4295 * .defaultBrowserContext()
4296 * .overridePermissions('<your origin>', [
4297 * 'clipboard-read',
4298 * 'clipboard-write',
4299 * ]);
4300 * ```
4301 *
4302 * @public
4303 */
4304export declare abstract class Mouse {
4305
4306 /**
4307 * Resets the mouse to the default state: No buttons pressed; position at
4308 * (0,0).
4309 */
4310 abstract reset(): Promise<void>;
4311 /**
4312 * Moves the mouse to the given coordinate.
4313 *
4314 * @param x - Horizontal position of the mouse.
4315 * @param y - Vertical position of the mouse.
4316 * @param options - Options to configure behavior.
4317 */
4318 abstract move(x: number, y: number, options?: Readonly<MouseMoveOptions>): Promise<void>;
4319 /**
4320 * Presses the mouse.
4321 *
4322 * @param options - Options to configure behavior.
4323 */
4324 abstract down(options?: Readonly<MouseOptions>): Promise<void>;
4325 /**
4326 * Releases the mouse.
4327 *
4328 * @param options - Options to configure behavior.
4329 */
4330 abstract up(options?: Readonly<MouseOptions>): Promise<void>;
4331 /**
4332 * Shortcut for `mouse.move`, `mouse.down` and `mouse.up`.
4333 *
4334 * @param x - Horizontal position of the mouse.
4335 * @param y - Vertical position of the mouse.
4336 * @param options - Options to configure behavior.
4337 */
4338 abstract click(x: number, y: number, options?: Readonly<MouseClickOptions>): Promise<void>;
4339 /**
4340 * Dispatches a `mousewheel` event.
4341 * @param options - Optional: `MouseWheelOptions`.
4342 *
4343 * @example
4344 * An example of zooming into an element:
4345 *
4346 * ```ts
4347 * await page.goto(
4348 * 'https://mdn.mozillademos.org/en-US/docs/Web/API/Element/wheel_event$samples/Scaling_an_element_via_the_wheel?revision=1587366',
4349 * );
4350 *
4351 * const elem = await page.$('div');
4352 * const boundingBox = await elem.boundingBox();
4353 * await page.mouse.move(
4354 * boundingBox.x + boundingBox.width / 2,
4355 * boundingBox.y + boundingBox.height / 2,
4356 * );
4357 *
4358 * await page.mouse.wheel({deltaY: -100});
4359 * ```
4360 */
4361 abstract wheel(options?: Readonly<MouseWheelOptions>): Promise<void>;
4362 /**
4363 * Dispatches a `drag` event.
4364 * @param start - starting point for drag
4365 * @param target - point to drag to
4366 */
4367 abstract drag(start: Point, target: Point): Promise<Protocol.Input.DragData>;
4368 /**
4369 * Dispatches a `dragenter` event.
4370 * @param target - point for emitting `dragenter` event
4371 * @param data - drag data containing items and operations mask
4372 */
4373 abstract dragEnter(target: Point, data: Protocol.Input.DragData): Promise<void>;
4374 /**
4375 * Dispatches a `dragover` event.
4376 * @param target - point for emitting `dragover` event
4377 * @param data - drag data containing items and operations mask
4378 */
4379 abstract dragOver(target: Point, data: Protocol.Input.DragData): Promise<void>;
4380 /**
4381 * Performs a dragenter, dragover, and drop in sequence.
4382 * @param target - point to drop on
4383 * @param data - drag data containing items and operations mask
4384 */
4385 abstract drop(target: Point, data: Protocol.Input.DragData): Promise<void>;
4386 /**
4387 * Performs a drag, dragenter, dragover, and drop in sequence.
4388 * @param start - point to drag from
4389 * @param target - point to drop on
4390 * @param options - An object of options. Accepts delay which,
4391 * if specified, is the time to wait between `dragover` and `drop` in milliseconds.
4392 * Defaults to 0.
4393 */
4394 abstract dragAndDrop(start: Point, target: Point, options?: {
4395 delay?: number;
4396 }): Promise<void>;
4397}
4398
4399/**
4400 * Enum of valid mouse buttons.
4401 *
4402 * @public
4403 */
4404export declare const MouseButton: Readonly<{
4405 Left: "left";
4406 Right: "right";
4407 Middle: "middle";
4408 Back: "back";
4409 Forward: "forward";
4410}>;
4411
4412/**
4413 * @public
4414 */
4415export declare type MouseButton = (typeof MouseButton)[keyof typeof MouseButton];
4416
4417/**
4418 * @public
4419 */
4420export declare interface MouseClickOptions extends MouseOptions {
4421 /**
4422 * Time (in ms) to delay the mouse release after the mouse press.
4423 */
4424 delay?: number;
4425 /**
4426 * Number of clicks to perform.
4427 *
4428 * @defaultValue `1`
4429 */
4430 count?: number;
4431}
4432
4433/**
4434 * @public
4435 */
4436export declare interface MouseMoveOptions {
4437 /**
4438 * Determines the number of movements to make from the current mouse position
4439 * to the new one.
4440 *
4441 * @defaultValue `1`
4442 */
4443 steps?: number;
4444}
4445
4446/**
4447 * @public
4448 */
4449export declare interface MouseOptions {
4450 /**
4451 * Determines which button will be pressed.
4452 *
4453 * @defaultValue `'left'`
4454 */
4455 button?: MouseButton;
4456 /**
4457 * Determines the click count for the mouse event. This does not perform
4458 * multiple clicks.
4459 *
4460 * @deprecated Use {@link MouseClickOptions.count}.
4461 * @defaultValue `1`
4462 */
4463 clickCount?: number;
4464}
4465
4466/**
4467 * @public
4468 */
4469export declare interface MouseWheelOptions {
4470 deltaX?: number;
4471 deltaY?: number;
4472}
4473
4474/**
4475 * @public
4476 */
4477export declare interface Moveable {
4478 /**
4479 * Moves the resource when 'using'.
4480 */
4481 move(): this;
4482}
4483
4484/**
4485 * @public
4486 */
4487export declare interface NetworkConditions {
4488 /**
4489 * Download speed (bytes/s)
4490 */
4491 download: number;
4492 /**
4493 * Upload speed (bytes/s)
4494 */
4495 upload: number;
4496 /**
4497 * Latency (ms)
4498 */
4499 latency: number;
4500}
4501
4502/**
4503 * @public
4504 */
4505export declare interface NewDocumentScriptEvaluation {
4506 identifier: string;
4507}
4508
4509/**
4510 * @public
4511 */
4512export declare type NodeFor<ComplexSelector extends string> = ParseSelector<ComplexSelector>;
4513
4514/**
4515 * @public
4516 */
4517export declare interface Offset {
4518 /**
4519 * x-offset for the clickable point relative to the top-left corner of the border box.
4520 */
4521 x: number;
4522 /**
4523 * y-offset for the clickable point relative to the top-left corner of the border box.
4524 */
4525 y: number;
4526}
4527
4528/**
4529 * Page provides methods to interact with a single tab or
4530 * {@link https://developer.chrome.com/extensions/background_pages | extension background page}
4531 * in the browser.
4532 *
4533 * :::note
4534 *
4535 * One Browser instance might have multiple Page instances.
4536 *
4537 * :::
4538 *
4539 * @example
4540 * This example creates a page, navigates it to a URL, and then saves a screenshot:
4541 *
4542 * ```ts
4543 * import puppeteer from 'puppeteer';
4544 *
4545 * (async () => {
4546 * const browser = await puppeteer.launch();
4547 * const page = await browser.newPage();
4548 * await page.goto('https://example.com');
4549 * await page.screenshot({path: 'screenshot.png'});
4550 * await browser.close();
4551 * })();
4552 * ```
4553 *
4554 * The Page class extends from Puppeteer's {@link EventEmitter} class and will
4555 * emit various events which are documented in the {@link PageEvent} enum.
4556 *
4557 * @example
4558 * This example logs a message for a single page `load` event:
4559 *
4560 * ```ts
4561 * page.once('load', () => console.log('Page loaded!'));
4562 * ```
4563 *
4564 * To unsubscribe from events use the {@link EventEmitter.off} method:
4565 *
4566 * ```ts
4567 * function logRequest(interceptedRequest) {
4568 * console.log('A request was made:', interceptedRequest.url());
4569 * }
4570 * page.on('request', logRequest);
4571 * // Sometime later...
4572 * page.off('request', logRequest);
4573 * ```
4574 *
4575 * @public
4576 */
4577export declare abstract class Page extends EventEmitter<PageEvents> {
4578 #private;
4579
4580
4581
4582 /**
4583 * `true` if the service worker are being bypassed, `false` otherwise.
4584 */
4585 abstract isServiceWorkerBypassed(): boolean;
4586 /**
4587 * `true` if drag events are being intercepted, `false` otherwise.
4588 *
4589 * @deprecated We no longer support intercepting drag payloads. Use the new
4590 * drag APIs found on {@link ElementHandle} to drag (or just use the
4591 * {@link Page.mouse}).
4592 */
4593 abstract isDragInterceptionEnabled(): boolean;
4594 /**
4595 * `true` if the page has JavaScript enabled, `false` otherwise.
4596 */
4597 abstract isJavaScriptEnabled(): boolean;
4598
4599
4600 /**
4601 * This method is typically coupled with an action that triggers file
4602 * choosing.
4603 *
4604 * :::caution
4605 *
4606 * This must be called before the file chooser is launched. It will not return
4607 * a currently active file chooser.
4608 *
4609 * :::
4610 *
4611 * :::caution
4612 *
4613 * Interception of file dialogs triggered via DOM APIs such as
4614 * window.showOpenFilePicker is currently not supported.
4615 *
4616 * :::
4617 *
4618 * @remarks
4619 * In the "headful" browser, this method results in the native file picker
4620 * dialog `not showing up` for the user.
4621 *
4622 * @example
4623 * The following example clicks a button that issues a file chooser
4624 * and then responds with `/tmp/myfile.pdf` as if a user has selected this file.
4625 *
4626 * ```ts
4627 * const [fileChooser] = await Promise.all([
4628 * page.waitForFileChooser(),
4629 * page.click('#upload-file-button'),
4630 * // some button that triggers file selection
4631 * ]);
4632 * await fileChooser.accept(['/tmp/myfile.pdf']);
4633 * ```
4634 */
4635 abstract waitForFileChooser(options?: WaitTimeoutOptions): Promise<FileChooser>;
4636 /**
4637 * Sets the page's geolocation.
4638 *
4639 * @remarks
4640 * Consider using {@link BrowserContext.overridePermissions} to grant
4641 * permissions for the page to read its geolocation.
4642 *
4643 * @example
4644 *
4645 * ```ts
4646 * await page.setGeolocation({latitude: 59.95, longitude: 30.31667});
4647 * ```
4648 */
4649 abstract setGeolocation(options: GeolocationOptions): Promise<void>;
4650 /**
4651 * A target this page was created from.
4652 *
4653 * @deprecated Use {@link Page.createCDPSession} directly.
4654 */
4655 abstract target(): Target;
4656 /**
4657 * Get the browser the page belongs to.
4658 */
4659 abstract browser(): Browser;
4660 /**
4661 * Get the browser context that the page belongs to.
4662 */
4663 abstract browserContext(): BrowserContext;
4664 /**
4665 * The page's main frame.
4666 */
4667 abstract mainFrame(): Frame;
4668 /**
4669 * Creates a Chrome Devtools Protocol session attached to the page.
4670 */
4671 abstract createCDPSession(): Promise<CDPSession>;
4672 /**
4673 * {@inheritDoc Keyboard}
4674 */
4675 abstract get keyboard(): Keyboard;
4676 /**
4677 * {@inheritDoc Touchscreen}
4678 */
4679 abstract get touchscreen(): Touchscreen;
4680 /**
4681 * {@inheritDoc Coverage}
4682 */
4683 abstract get coverage(): Coverage;
4684 /**
4685 * {@inheritDoc Tracing}
4686 */
4687 abstract get tracing(): Tracing;
4688 /**
4689 * {@inheritDoc Accessibility}
4690 */
4691 get accessibility(): Accessibility;
4692 /**
4693 * An array of all frames attached to the page.
4694 */
4695 abstract frames(): Frame[];
4696 /**
4697 * All of the dedicated {@link
4698 * https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API |
4699 * WebWorkers} associated with the page.
4700 *
4701 * @remarks
4702 * This does not contain ServiceWorkers
4703 */
4704 abstract workers(): WebWorker[];
4705 /**
4706 * Activating request interception enables {@link HTTPRequest.abort},
4707 * {@link HTTPRequest.continue} and {@link HTTPRequest.respond} methods. This
4708 * provides the capability to modify network requests that are made by a page.
4709 *
4710 * Once request interception is enabled, every request will stall unless it's
4711 * continued, responded or aborted; or completed using the browser cache.
4712 *
4713 * See the
4714 * {@link https://pptr.dev/guides/network-interception|Request interception guide}
4715 * for more details.
4716 *
4717 * @example
4718 * An example of a naïve request interceptor that aborts all image requests:
4719 *
4720 * ```ts
4721 * import puppeteer from 'puppeteer';
4722 * (async () => {
4723 * const browser = await puppeteer.launch();
4724 * const page = await browser.newPage();
4725 * await page.setRequestInterception(true);
4726 * page.on('request', interceptedRequest => {
4727 * if (
4728 * interceptedRequest.url().endsWith('.png') ||
4729 * interceptedRequest.url().endsWith('.jpg')
4730 * )
4731 * interceptedRequest.abort();
4732 * else interceptedRequest.continue();
4733 * });
4734 * await page.goto('https://example.com');
4735 * await browser.close();
4736 * })();
4737 * ```
4738 *
4739 * @param value - Whether to enable request interception.
4740 */
4741 abstract setRequestInterception(value: boolean): Promise<void>;
4742 /**
4743 * Toggles ignoring of service worker for each request.
4744 *
4745 * @param bypass - Whether to bypass service worker and load from network.
4746 */
4747 abstract setBypassServiceWorker(bypass: boolean): Promise<void>;
4748 /**
4749 * @param enabled - Whether to enable drag interception.
4750 *
4751 * @deprecated We no longer support intercepting drag payloads. Use the new
4752 * drag APIs found on {@link ElementHandle} to drag (or just use the
4753 * {@link Page.mouse}).
4754 */
4755 abstract setDragInterception(enabled: boolean): Promise<void>;
4756 /**
4757 * Sets the network connection to offline.
4758 *
4759 * It does not change the parameters used in {@link Page.emulateNetworkConditions}
4760 *
4761 * @param enabled - When `true`, enables offline mode for the page.
4762 */
4763 abstract setOfflineMode(enabled: boolean): Promise<void>;
4764 /**
4765 * This does not affect WebSockets and WebRTC PeerConnections (see
4766 * https://crbug.com/563644). To set the page offline, you can use
4767 * {@link Page.setOfflineMode}.
4768 *
4769 * A list of predefined network conditions can be used by importing
4770 * {@link PredefinedNetworkConditions}.
4771 *
4772 * @example
4773 *
4774 * ```ts
4775 * import {PredefinedNetworkConditions} from 'puppeteer';
4776 * const slow3G = PredefinedNetworkConditions['Slow 3G'];
4777 *
4778 * (async () => {
4779 * const browser = await puppeteer.launch();
4780 * const page = await browser.newPage();
4781 * await page.emulateNetworkConditions(slow3G);
4782 * await page.goto('https://www.google.com');
4783 * // other actions...
4784 * await browser.close();
4785 * })();
4786 * ```
4787 *
4788 * @param networkConditions - Passing `null` disables network condition
4789 * emulation.
4790 */
4791 abstract emulateNetworkConditions(networkConditions: NetworkConditions | null): Promise<void>;
4792 /**
4793 * This setting will change the default maximum navigation time for the
4794 * following methods and related shortcuts:
4795 *
4796 * - {@link Page.goBack | page.goBack(options)}
4797 *
4798 * - {@link Page.goForward | page.goForward(options)}
4799 *
4800 * - {@link Page.goto | page.goto(url,options)}
4801 *
4802 * - {@link Page.reload | page.reload(options)}
4803 *
4804 * - {@link Page.setContent | page.setContent(html,options)}
4805 *
4806 * - {@link Page.waitForNavigation | page.waitForNavigation(options)}
4807 * @param timeout - Maximum navigation time in milliseconds.
4808 */
4809 abstract setDefaultNavigationTimeout(timeout: number): void;
4810 /**
4811 * @param timeout - Maximum time in milliseconds.
4812 */
4813 abstract setDefaultTimeout(timeout: number): void;
4814 /**
4815 * Maximum time in milliseconds.
4816 */
4817 abstract getDefaultTimeout(): number;
4818 /**
4819 * Maximum navigation time in milliseconds.
4820 */
4821 abstract getDefaultNavigationTimeout(): number;
4822 /**
4823 * Creates a locator for the provided selector. See {@link Locator} for
4824 * details and supported actions.
4825 *
4826 * @param selector -
4827 * {@link https://pptr.dev/guides/page-interactions#selectors | selector}
4828 * to query the page for.
4829 * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors | CSS selectors}
4830 * can be passed as-is and a
4831 * {@link https://pptr.dev/guides/page-interactions#non-css-selectors | Puppeteer-specific selector syntax}
4832 * allows quering by
4833 * {@link https://pptr.dev/guides/page-interactions#text-selectors--p-text | text},
4834 * {@link https://pptr.dev/guides/page-interactions#aria-selectors--p-aria | a11y role and name},
4835 * and
4836 * {@link https://pptr.dev/guides/page-interactions#xpath-selectors--p-xpath | xpath}
4837 * and
4838 * {@link https://pptr.dev/guides/page-interactions#querying-elements-in-shadow-dom | combining these queries across shadow roots}.
4839 * Alternatively, you can specify the selector type using a
4840 * {@link https://pptr.dev/guides/page-interactions#prefixed-selector-syntax | prefix}.
4841 */
4842 locator<Selector extends string>(selector: Selector): Locator<NodeFor<Selector>>;
4843 /**
4844 * Creates a locator for the provided function. See {@link Locator} for
4845 * details and supported actions.
4846 *
4847 * @param selector -
4848 * {@link https://pptr.dev/guides/page-interactions#selectors | selector}
4849 * to query the page for.
4850 * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors | CSS selectors}
4851 * can be passed as-is and a
4852 * {@link https://pptr.dev/guides/page-interactions#non-css-selectors | Puppeteer-specific selector syntax}
4853 * allows quering by
4854 * {@link https://pptr.dev/guides/page-interactions#text-selectors--p-text | text},
4855 * {@link https://pptr.dev/guides/page-interactions#aria-selectors--p-aria | a11y role and name},
4856 * and
4857 * {@link https://pptr.dev/guides/page-interactions#xpath-selectors--p-xpath | xpath}
4858 * and
4859 * {@link https://pptr.dev/guides/page-interactions#querying-elements-in-shadow-dom | combining these queries across shadow roots}.
4860 * Alternatively, you can specify the selector type using a
4861 * {@link https://pptr.dev/guides/page-interactions#prefixed-selector-syntax | prefix}.
4862 */
4863 locator<Ret>(func: () => Awaitable<Ret>): Locator<Ret>;
4864
4865 /**
4866 * Finds the first element that matches the selector. If no element matches
4867 * the selector, the return value resolves to `null`.
4868 *
4869 * @param selector -
4870 * {@link https://pptr.dev/guides/page-interactions#selectors | selector}
4871 * to query the page for.
4872 * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors | CSS selectors}
4873 * can be passed as-is and a
4874 * {@link https://pptr.dev/guides/page-interactions#non-css-selectors | Puppeteer-specific selector syntax}
4875 * allows quering by
4876 * {@link https://pptr.dev/guides/page-interactions#text-selectors--p-text | text},
4877 * {@link https://pptr.dev/guides/page-interactions#aria-selectors--p-aria | a11y role and name},
4878 * and
4879 * {@link https://pptr.dev/guides/page-interactions#xpath-selectors--p-xpath | xpath}
4880 * and
4881 * {@link https://pptr.dev/guides/page-interactions#querying-elements-in-shadow-dom | combining these queries across shadow roots}.
4882 * Alternatively, you can specify the selector type using a
4883 * {@link https://pptr.dev/guides/page-interactions#prefixed-selector-syntax | prefix}.
4884 *
4885 * @remarks
4886 *
4887 * Shortcut for {@link Frame.$ | Page.mainFrame().$(selector) }.
4888 */
4889 $<Selector extends string>(selector: Selector): Promise<ElementHandle<NodeFor<Selector>> | null>;
4890 /**
4891 * Finds elements on the page that match the selector. If no elements
4892 * match the selector, the return value resolves to `[]`.
4893 *
4894 * @param selector -
4895 * {@link https://pptr.dev/guides/page-interactions#selectors | selector}
4896 * to query the page for.
4897 * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors | CSS selectors}
4898 * can be passed as-is and a
4899 * {@link https://pptr.dev/guides/page-interactions#non-css-selectors | Puppeteer-specific selector syntax}
4900 * allows quering by
4901 * {@link https://pptr.dev/guides/page-interactions#text-selectors--p-text | text},
4902 * {@link https://pptr.dev/guides/page-interactions#aria-selectors--p-aria | a11y role and name},
4903 * and
4904 * {@link https://pptr.dev/guides/page-interactions#xpath-selectors--p-xpath | xpath}
4905 * and
4906 * {@link https://pptr.dev/guides/page-interactions#querying-elements-in-shadow-dom | combining these queries across shadow roots}.
4907 * Alternatively, you can specify the selector type using a
4908 * {@link https://pptr.dev/guides/page-interactions#prefixed-selector-syntax | prefix}.
4909 *
4910 * @remarks
4911 *
4912 * Shortcut for {@link Frame.$$ | Page.mainFrame().$$(selector) }.
4913 */
4914 $$<Selector extends string>(selector: Selector, options?: QueryOptions): Promise<Array<ElementHandle<NodeFor<Selector>>>>;
4915 /**
4916 * @remarks
4917 *
4918 * The only difference between {@link Page.evaluate | page.evaluate} and
4919 * `page.evaluateHandle` is that `evaluateHandle` will return the value
4920 * wrapped in an in-page object.
4921 *
4922 * If the function passed to `page.evaluateHandle` returns a Promise, the
4923 * function will wait for the promise to resolve and return its value.
4924 *
4925 * You can pass a string instead of a function (although functions are
4926 * recommended as they are easier to debug and use with TypeScript):
4927 *
4928 * @example
4929 *
4930 * ```ts
4931 * const aHandle = await page.evaluateHandle('document');
4932 * ```
4933 *
4934 * @example
4935 * {@link JSHandle} instances can be passed as arguments to the `pageFunction`:
4936 *
4937 * ```ts
4938 * const aHandle = await page.evaluateHandle(() => document.body);
4939 * const resultHandle = await page.evaluateHandle(
4940 * body => body.innerHTML,
4941 * aHandle,
4942 * );
4943 * console.log(await resultHandle.jsonValue());
4944 * await resultHandle.dispose();
4945 * ```
4946 *
4947 * Most of the time this function returns a {@link JSHandle},
4948 * but if `pageFunction` returns a reference to an element,
4949 * you instead get an {@link ElementHandle} back:
4950 *
4951 * @example
4952 *
4953 * ```ts
4954 * const button = await page.evaluateHandle(() =>
4955 * document.querySelector('button'),
4956 * );
4957 * // can call `click` because `button` is an `ElementHandle`
4958 * await button.click();
4959 * ```
4960 *
4961 * The TypeScript definitions assume that `evaluateHandle` returns
4962 * a `JSHandle`, but if you know it's going to return an
4963 * `ElementHandle`, pass it as the generic argument:
4964 *
4965 * ```ts
4966 * const button = await page.evaluateHandle<ElementHandle>(...);
4967 * ```
4968 *
4969 * @param pageFunction - a function that is run within the page
4970 * @param args - arguments to be passed to the pageFunction
4971 */
4972 evaluateHandle<Params extends unknown[], Func extends EvaluateFunc<Params> = EvaluateFunc<Params>>(pageFunction: Func | string, ...args: Params): Promise<HandleFor<Awaited<ReturnType<Func>>>>;
4973 /**
4974 * This method iterates the JavaScript heap and finds all objects with the
4975 * given prototype.
4976 *
4977 * @example
4978 *
4979 * ```ts
4980 * // Create a Map object
4981 * await page.evaluate(() => (window.map = new Map()));
4982 * // Get a handle to the Map object prototype
4983 * const mapPrototype = await page.evaluateHandle(() => Map.prototype);
4984 * // Query all map instances into an array
4985 * const mapInstances = await page.queryObjects(mapPrototype);
4986 * // Count amount of map objects in heap
4987 * const count = await page.evaluate(maps => maps.length, mapInstances);
4988 * await mapInstances.dispose();
4989 * await mapPrototype.dispose();
4990 * ```
4991 *
4992 * @param prototypeHandle - a handle to the object prototype.
4993 * @returns Promise which resolves to a handle to an array of objects with
4994 * this prototype.
4995 */
4996 abstract queryObjects<Prototype>(prototypeHandle: JSHandle<Prototype>): Promise<JSHandle<Prototype[]>>;
4997 /**
4998 * This method finds the first element within the page that matches the selector
4999 * and passes the result as the first argument to the `pageFunction`.
5000 *
5001 * @remarks
5002 *
5003 * If no element is found matching `selector`, the method will throw an error.
5004 *
5005 * If `pageFunction` returns a promise `$eval` will wait for the promise to
5006 * resolve and then return its value.
5007 *
5008 * @example
5009 *
5010 * ```ts
5011 * const searchValue = await page.$eval('#search', el => el.value);
5012 * const preloadHref = await page.$eval('link[rel=preload]', el => el.href);
5013 * const html = await page.$eval('.main-container', el => el.outerHTML);
5014 * ```
5015 *
5016 * If you are using TypeScript, you may have to provide an explicit type to the
5017 * first argument of the `pageFunction`.
5018 * By default it is typed as `Element`, but you may need to provide a more
5019 * specific sub-type:
5020 *
5021 * @example
5022 *
5023 * ```ts
5024 * // if you don't provide HTMLInputElement here, TS will error
5025 * // as `value` is not on `Element`
5026 * const searchValue = await page.$eval(
5027 * '#search',
5028 * (el: HTMLInputElement) => el.value,
5029 * );
5030 * ```
5031 *
5032 * The compiler should be able to infer the return type
5033 * from the `pageFunction` you provide. If it is unable to, you can use the generic
5034 * type to tell the compiler what return type you expect from `$eval`:
5035 *
5036 * @example
5037 *
5038 * ```ts
5039 * // The compiler can infer the return type in this case, but if it can't
5040 * // or if you want to be more explicit, provide it as the generic type.
5041 * const searchValue = await page.$eval<string>(
5042 * '#search',
5043 * (el: HTMLInputElement) => el.value,
5044 * );
5045 * ```
5046 *
5047 * @param selector -
5048 * {@link https://pptr.dev/guides/page-interactions#selectors | selector}
5049 * to query the page for.
5050 * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors | CSS selectors}
5051 * can be passed as-is and a
5052 * {@link https://pptr.dev/guides/page-interactions#non-css-selectors | Puppeteer-specific selector syntax}
5053 * allows quering by
5054 * {@link https://pptr.dev/guides/page-interactions#text-selectors--p-text | text},
5055 * {@link https://pptr.dev/guides/page-interactions#aria-selectors--p-aria | a11y role and name},
5056 * and
5057 * {@link https://pptr.dev/guides/page-interactions#xpath-selectors--p-xpath | xpath}
5058 * and
5059 * {@link https://pptr.dev/guides/page-interactions#querying-elements-in-shadow-dom | combining these queries across shadow roots}.
5060 * Alternatively, you can specify the selector type using a
5061 * {@link https://pptr.dev/guides/page-interactions#prefixed-selector-syntax | prefix}.
5062 * @param pageFunction - the function to be evaluated in the page context.
5063 * Will be passed the result of the element matching the selector as its
5064 * first argument.
5065 * @param args - any additional arguments to pass through to `pageFunction`.
5066 *
5067 * @returns The result of calling `pageFunction`. If it returns an element it
5068 * is wrapped in an {@link ElementHandle}, else the raw value itself is
5069 * returned.
5070 */
5071 $eval<Selector extends string, Params extends unknown[], Func extends EvaluateFuncWith<NodeFor<Selector>, Params> = EvaluateFuncWith<NodeFor<Selector>, Params>>(selector: Selector, pageFunction: Func | string, ...args: Params): Promise<Awaited<ReturnType<Func>>>;
5072 /**
5073 * This method returns all elements matching the selector and passes the
5074 * resulting array as the first argument to the `pageFunction`.
5075 *
5076 * @remarks
5077 * If `pageFunction` returns a promise `$$eval` will wait for the promise to
5078 * resolve and then return its value.
5079 *
5080 * @example
5081 *
5082 * ```ts
5083 * // get the amount of divs on the page
5084 * const divCount = await page.$$eval('div', divs => divs.length);
5085 *
5086 * // get the text content of all the `.options` elements:
5087 * const options = await page.$$eval('div > span.options', options => {
5088 * return options.map(option => option.textContent);
5089 * });
5090 * ```
5091 *
5092 * If you are using TypeScript, you may have to provide an explicit type to the
5093 * first argument of the `pageFunction`.
5094 * By default it is typed as `Element[]`, but you may need to provide a more
5095 * specific sub-type:
5096 *
5097 * @example
5098 *
5099 * ```ts
5100 * await page.$$eval('input', elements => {
5101 * return elements.map(e => e.value);
5102 * });
5103 * ```
5104 *
5105 * The compiler should be able to infer the return type
5106 * from the `pageFunction` you provide. If it is unable to, you can use the generic
5107 * type to tell the compiler what return type you expect from `$$eval`:
5108 *
5109 * @example
5110 *
5111 * ```ts
5112 * const allInputValues = await page.$$eval('input', elements =>
5113 * elements.map(e => e.textContent),
5114 * );
5115 * ```
5116 *
5117 * @param selector -
5118 * {@link https://pptr.dev/guides/page-interactions#selectors | selector}
5119 * to query the page for.
5120 * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors | CSS selectors}
5121 * can be passed as-is and a
5122 * {@link https://pptr.dev/guides/page-interactions#non-css-selectors | Puppeteer-specific selector syntax}
5123 * allows quering by
5124 * {@link https://pptr.dev/guides/page-interactions#text-selectors--p-text | text},
5125 * {@link https://pptr.dev/guides/page-interactions#aria-selectors--p-aria | a11y role and name},
5126 * and
5127 * {@link https://pptr.dev/guides/page-interactions#xpath-selectors--p-xpath | xpath}
5128 * and
5129 * {@link https://pptr.dev/guides/page-interactions#querying-elements-in-shadow-dom | combining these queries across shadow roots}.
5130 * Alternatively, you can specify the selector type using a
5131 * {@link https://pptr.dev/guides/page-interactions#prefixed-selector-syntax | prefix}.
5132 * @param pageFunction - the function to be evaluated in the page context.
5133 * Will be passed an array of matching elements as its first argument.
5134 * @param args - any additional arguments to pass through to `pageFunction`.
5135 *
5136 * @returns The result of calling `pageFunction`. If it returns an element it
5137 * is wrapped in an {@link ElementHandle}, else the raw value itself is
5138 * returned.
5139 */
5140 $$eval<Selector extends string, Params extends unknown[], Func extends EvaluateFuncWith<Array<NodeFor<Selector>>, Params> = EvaluateFuncWith<Array<NodeFor<Selector>>, Params>>(selector: Selector, pageFunction: Func | string, ...args: Params): Promise<Awaited<ReturnType<Func>>>;
5141 /**
5142 * If no URLs are specified, this method returns cookies for the
5143 * current page URL. If URLs are specified, only cookies for those
5144 * URLs are returned.
5145 *
5146 * @deprecated Page-level cookie API is deprecated. Use
5147 * {@link Browser.cookies} or {@link BrowserContext.cookies} instead.
5148 */
5149 abstract cookies(...urls: string[]): Promise<Cookie[]>;
5150 /**
5151 * @deprecated Page-level cookie API is deprecated. Use
5152 * {@link Browser.deleteCookie} or {@link BrowserContext.deleteCookie}
5153 * instead.
5154 */
5155 abstract deleteCookie(...cookies: DeleteCookiesRequest[]): Promise<void>;
5156 /**
5157 * @example
5158 *
5159 *```ts
5160 * await page.setCookie(cookieObject1, cookieObject2);
5161 *```
5162 *
5163 * @deprecated Page-level cookie API is deprecated. Use
5164 * {@link Browser.setCookie} or {@link BrowserContext.setCookie}
5165 * instead.
5166 */
5167 abstract setCookie(...cookies: CookieParam[]): Promise<void>;
5168 /**
5169 * Adds a `<script>` tag into the page with the desired URL or content.
5170 *
5171 * @remarks
5172 * Shortcut for
5173 * {@link Frame.addScriptTag | page.mainFrame().addScriptTag(options)}.
5174 *
5175 * @param options - Options for the script.
5176 * @returns An {@link ElementHandle | element handle} to the injected
5177 * `<script>` element.
5178 */
5179 addScriptTag(options: FrameAddScriptTagOptions): Promise<ElementHandle<HTMLScriptElement>>;
5180 /**
5181 * Adds a `<link rel="stylesheet">` tag into the page with the desired URL or
5182 * a `<style type="text/css">` tag with the content.
5183 *
5184 * Shortcut for
5185 * {@link Frame.(addStyleTag:2) | page.mainFrame().addStyleTag(options)}.
5186 *
5187 * @returns An {@link ElementHandle | element handle} to the injected `<link>`
5188 * or `<style>` element.
5189 */
5190 addStyleTag(options: Omit<FrameAddStyleTagOptions, 'url'>): Promise<ElementHandle<HTMLStyleElement>>;
5191 addStyleTag(options: FrameAddStyleTagOptions): Promise<ElementHandle<HTMLLinkElement>>;
5192 /**
5193 * The method adds a function called `name` on the page's `window` object.
5194 * When called, the function executes `puppeteerFunction` in node.js and
5195 * returns a `Promise` which resolves to the return value of
5196 * `puppeteerFunction`.
5197 *
5198 * If the puppeteerFunction returns a `Promise`, it will be awaited.
5199 *
5200 * :::note
5201 *
5202 * Functions installed via `page.exposeFunction` survive navigations.
5203 *
5204 * :::
5205 *
5206 * @example
5207 * An example of adding an `md5` function into the page:
5208 *
5209 * ```ts
5210 * import puppeteer from 'puppeteer';
5211 * import crypto from 'crypto';
5212 *
5213 * (async () => {
5214 * const browser = await puppeteer.launch();
5215 * const page = await browser.newPage();
5216 * page.on('console', msg => console.log(msg.text()));
5217 * await page.exposeFunction('md5', text =>
5218 * crypto.createHash('md5').update(text).digest('hex'),
5219 * );
5220 * await page.evaluate(async () => {
5221 * // use window.md5 to compute hashes
5222 * const myString = 'PUPPETEER';
5223 * const myHash = await window.md5(myString);
5224 * console.log(`md5 of ${myString} is ${myHash}`);
5225 * });
5226 * await browser.close();
5227 * })();
5228 * ```
5229 *
5230 * @example
5231 * An example of adding a `window.readfile` function into the page:
5232 *
5233 * ```ts
5234 * import puppeteer from 'puppeteer';
5235 * import fs from 'fs';
5236 *
5237 * (async () => {
5238 * const browser = await puppeteer.launch();
5239 * const page = await browser.newPage();
5240 * page.on('console', msg => console.log(msg.text()));
5241 * await page.exposeFunction('readfile', async filePath => {
5242 * return new Promise((resolve, reject) => {
5243 * fs.readFile(filePath, 'utf8', (err, text) => {
5244 * if (err) reject(err);
5245 * else resolve(text);
5246 * });
5247 * });
5248 * });
5249 * await page.evaluate(async () => {
5250 * // use window.readfile to read contents of a file
5251 * const content = await window.readfile('/etc/hosts');
5252 * console.log(content);
5253 * });
5254 * await browser.close();
5255 * })();
5256 * ```
5257 *
5258 * @param name - Name of the function on the window object
5259 * @param pptrFunction - Callback function which will be called in Puppeteer's
5260 * context.
5261 */
5262 abstract exposeFunction(name: string, pptrFunction: Function | {
5263 default: Function;
5264 }): Promise<void>;
5265 /**
5266 * The method removes a previously added function via ${@link Page.exposeFunction}
5267 * called `name` from the page's `window` object.
5268 */
5269 abstract removeExposedFunction(name: string): Promise<void>;
5270 /**
5271 * Provide credentials for `HTTP authentication`.
5272 *
5273 * :::note
5274 *
5275 * Request interception will be turned on behind the scenes to
5276 * implement authentication. This might affect performance.
5277 *
5278 * :::
5279 *
5280 * @remarks
5281 * To disable authentication, pass `null`.
5282 */
5283 abstract authenticate(credentials: Credentials | null): Promise<void>;
5284 /**
5285 * The extra HTTP headers will be sent with every request the page initiates.
5286 *
5287 * :::tip
5288 *
5289 * All HTTP header names are lowercased. (HTTP headers are
5290 * case-insensitive, so this shouldn’t impact your server code.)
5291 *
5292 * :::
5293 *
5294 * :::note
5295 *
5296 * page.setExtraHTTPHeaders does not guarantee the order of headers in
5297 * the outgoing requests.
5298 *
5299 * :::
5300 *
5301 * @param headers - An object containing additional HTTP headers to be sent
5302 * with every request. All header values must be strings.
5303 */
5304 abstract setExtraHTTPHeaders(headers: Record<string, string>): Promise<void>;
5305 /**
5306 * @param userAgent - Specific user agent to use in this page
5307 * @param userAgentData - Specific user agent client hint data to use in this
5308 * page
5309 * @returns Promise which resolves when the user agent is set.
5310 */
5311 abstract setUserAgent(userAgent: string, userAgentMetadata?: Protocol.Emulation.UserAgentMetadata): Promise<void>;
5312 /**
5313 * Object containing metrics as key/value pairs.
5314 *
5315 * @returns
5316 *
5317 * - `Timestamp` : The timestamp when the metrics sample was taken.
5318 *
5319 * - `Documents` : Number of documents in the page.
5320 *
5321 * - `Frames` : Number of frames in the page.
5322 *
5323 * - `JSEventListeners` : Number of events in the page.
5324 *
5325 * - `Nodes` : Number of DOM nodes in the page.
5326 *
5327 * - `LayoutCount` : Total number of full or partial page layout.
5328 *
5329 * - `RecalcStyleCount` : Total number of page style recalculations.
5330 *
5331 * - `LayoutDuration` : Combined durations of all page layouts.
5332 *
5333 * - `RecalcStyleDuration` : Combined duration of all page style
5334 * recalculations.
5335 *
5336 * - `ScriptDuration` : Combined duration of JavaScript execution.
5337 *
5338 * - `TaskDuration` : Combined duration of all tasks performed by the browser.
5339 *
5340 * - `JSHeapUsedSize` : Used JavaScript heap size.
5341 *
5342 * - `JSHeapTotalSize` : Total JavaScript heap size.
5343 *
5344 * @remarks
5345 * All timestamps are in monotonic time: monotonically increasing time
5346 * in seconds since an arbitrary point in the past.
5347 */
5348 abstract metrics(): Promise<Metrics>;
5349 /**
5350 * The page's URL.
5351 *
5352 * @remarks
5353 *
5354 * Shortcut for {@link Frame.url | page.mainFrame().url()}.
5355 */
5356 url(): string;
5357 /**
5358 * The full HTML contents of the page, including the DOCTYPE.
5359 */
5360 content(): Promise<string>;
5361 /**
5362 * Set the content of the page.
5363 *
5364 * @param html - HTML markup to assign to the page.
5365 * @param options - Parameters that has some properties.
5366 */
5367 setContent(html: string, options?: WaitForOptions): Promise<void>;
5368 /**
5369 * {@inheritDoc Frame.goto}
5370 */
5371 goto(url: string, options?: GoToOptions): Promise<HTTPResponse | null>;
5372 /**
5373 * Reloads the page.
5374 *
5375 * @param options - Options to configure waiting behavior.
5376 * @returns A promise which resolves to the main resource response. In case of
5377 * multiple redirects, the navigation will resolve with the response of the
5378 * last redirect.
5379 */
5380 abstract reload(options?: WaitForOptions): Promise<HTTPResponse | null>;
5381 /**
5382 * Waits for the page to navigate to a new URL or to reload. It is useful when
5383 * you run code that will indirectly cause the page to navigate.
5384 *
5385 * @example
5386 *
5387 * ```ts
5388 * const [response] = await Promise.all([
5389 * page.waitForNavigation(), // The promise resolves after navigation has finished
5390 * page.click('a.my-link'), // Clicking the link will indirectly cause a navigation
5391 * ]);
5392 * ```
5393 *
5394 * @remarks
5395 *
5396 * Usage of the
5397 * {@link https://developer.mozilla.org/en-US/docs/Web/API/History_API | History API}
5398 * to change the URL is considered a navigation.
5399 *
5400 * @param options - Navigation parameters which might have the following
5401 * properties:
5402 * @returns A `Promise` which resolves to the main resource response.
5403 *
5404 * - In case of multiple redirects, the navigation will resolve with the
5405 * response of the last redirect.
5406 * - In case of navigation to a different anchor or navigation due to History
5407 * API usage, the navigation will resolve with `null`.
5408 */
5409 waitForNavigation(options?: WaitForOptions): Promise<HTTPResponse | null>;
5410 /**
5411 * @param urlOrPredicate - A URL or predicate to wait for
5412 * @param options - Optional waiting parameters
5413 * @returns Promise which resolves to the matched request
5414 * @example
5415 *
5416 * ```ts
5417 * const firstRequest = await page.waitForRequest(
5418 * 'https://example.com/resource',
5419 * );
5420 * const finalRequest = await page.waitForRequest(
5421 * request => request.url() === 'https://example.com',
5422 * );
5423 * return finalRequest.response()?.ok();
5424 * ```
5425 *
5426 * @remarks
5427 * Optional Waiting Parameters have:
5428 *
5429 * - `timeout`: Maximum wait time in milliseconds, defaults to `30` seconds, pass
5430 * `0` to disable the timeout. The default value can be changed by using the
5431 * {@link Page.setDefaultTimeout} method.
5432 */
5433 waitForRequest(urlOrPredicate: string | AwaitablePredicate<HTTPRequest>, options?: WaitTimeoutOptions): Promise<HTTPRequest>;
5434 /**
5435 * @param urlOrPredicate - A URL or predicate to wait for.
5436 * @param options - Optional waiting parameters
5437 * @returns Promise which resolves to the matched response.
5438 * @example
5439 *
5440 * ```ts
5441 * const firstResponse = await page.waitForResponse(
5442 * 'https://example.com/resource',
5443 * );
5444 * const finalResponse = await page.waitForResponse(
5445 * response =>
5446 * response.url() === 'https://example.com' && response.status() === 200,
5447 * );
5448 * const finalResponse = await page.waitForResponse(async response => {
5449 * return (await response.text()).includes('<html>');
5450 * });
5451 * return finalResponse.ok();
5452 * ```
5453 *
5454 * @remarks
5455 * Optional Parameter have:
5456 *
5457 * - `timeout`: Maximum wait time in milliseconds, defaults to `30` seconds,
5458 * pass `0` to disable the timeout. The default value can be changed by using
5459 * the {@link Page.setDefaultTimeout} method.
5460 */
5461 waitForResponse(urlOrPredicate: string | AwaitablePredicate<HTTPResponse>, options?: WaitTimeoutOptions): Promise<HTTPResponse>;
5462 /**
5463 * Waits for the network to be idle.
5464 *
5465 * @param options - Options to configure waiting behavior.
5466 * @returns A promise which resolves once the network is idle.
5467 */
5468 waitForNetworkIdle(options?: WaitForNetworkIdleOptions): Promise<void>;
5469
5470 /**
5471 * Waits for a frame matching the given conditions to appear.
5472 *
5473 * @example
5474 *
5475 * ```ts
5476 * const frame = await page.waitForFrame(async frame => {
5477 * return frame.name() === 'Test';
5478 * });
5479 * ```
5480 */
5481 waitForFrame(urlOrPredicate: string | ((frame: Frame) => Awaitable<boolean>), options?: WaitTimeoutOptions): Promise<Frame>;
5482 /**
5483 * This method navigate to the previous page in history.
5484 * @param options - Navigation parameters
5485 * @returns Promise which resolves to the main resource response. In case of
5486 * multiple redirects, the navigation will resolve with the response of the
5487 * last redirect. If can not go back, resolves to `null`.
5488 */
5489 abstract goBack(options?: WaitForOptions): Promise<HTTPResponse | null>;
5490 /**
5491 * This method navigate to the next page in history.
5492 * @param options - Navigation Parameter
5493 * @returns Promise which resolves to the main resource response. In case of
5494 * multiple redirects, the navigation will resolve with the response of the
5495 * last redirect. If can not go forward, resolves to `null`.
5496 */
5497 abstract goForward(options?: WaitForOptions): Promise<HTTPResponse | null>;
5498 /**
5499 * Brings page to front (activates tab).
5500 */
5501 abstract bringToFront(): Promise<void>;
5502 /**
5503 * Emulates a given device's metrics and user agent.
5504 *
5505 * To aid emulation, Puppeteer provides a list of known devices that can be
5506 * via {@link KnownDevices}.
5507 *
5508 * @remarks
5509 * This method is a shortcut for calling two methods:
5510 * {@link Page.setUserAgent} and {@link Page.setViewport}.
5511 *
5512 * This method will resize the page. A lot of websites don't expect phones to
5513 * change size, so you should emulate before navigating to the page.
5514 *
5515 * @example
5516 *
5517 * ```ts
5518 * import {KnownDevices} from 'puppeteer';
5519 * const iPhone = KnownDevices['iPhone 15 Pro'];
5520 *
5521 * (async () => {
5522 * const browser = await puppeteer.launch();
5523 * const page = await browser.newPage();
5524 * await page.emulate(iPhone);
5525 * await page.goto('https://www.google.com');
5526 * // other actions...
5527 * await browser.close();
5528 * })();
5529 * ```
5530 */
5531 emulate(device: Device): Promise<void>;
5532 /**
5533 * @param enabled - Whether or not to enable JavaScript on the page.
5534 * @remarks
5535 * NOTE: changing this value won't affect scripts that have already been run.
5536 * It will take full effect on the next navigation.
5537 */
5538 abstract setJavaScriptEnabled(enabled: boolean): Promise<void>;
5539 /**
5540 * Toggles bypassing page's Content-Security-Policy.
5541 * @param enabled - sets bypassing of page's Content-Security-Policy.
5542 * @remarks
5543 * NOTE: CSP bypassing happens at the moment of CSP initialization rather than
5544 * evaluation. Usually, this means that `page.setBypassCSP` should be called
5545 * before navigating to the domain.
5546 */
5547 abstract setBypassCSP(enabled: boolean): Promise<void>;
5548 /**
5549 * @param type - Changes the CSS media type of the page. The only allowed
5550 * values are `screen`, `print` and `null`. Passing `null` disables CSS media
5551 * emulation.
5552 * @example
5553 *
5554 * ```ts
5555 * await page.evaluate(() => matchMedia('screen').matches);
5556 * // → true
5557 * await page.evaluate(() => matchMedia('print').matches);
5558 * // → false
5559 *
5560 * await page.emulateMediaType('print');
5561 * await page.evaluate(() => matchMedia('screen').matches);
5562 * // → false
5563 * await page.evaluate(() => matchMedia('print').matches);
5564 * // → true
5565 *
5566 * await page.emulateMediaType(null);
5567 * await page.evaluate(() => matchMedia('screen').matches);
5568 * // → true
5569 * await page.evaluate(() => matchMedia('print').matches);
5570 * // → false
5571 * ```
5572 */
5573 abstract emulateMediaType(type?: string): Promise<void>;
5574 /**
5575 * Enables CPU throttling to emulate slow CPUs.
5576 * @param factor - slowdown factor (1 is no throttle, 2 is 2x slowdown, etc).
5577 */
5578 abstract emulateCPUThrottling(factor: number | null): Promise<void>;
5579 /**
5580 * @param features - `<?Array<Object>>` Given an array of media feature
5581 * objects, emulates CSS media features on the page. Each media feature object
5582 * must have the following properties:
5583 * @example
5584 *
5585 * ```ts
5586 * await page.emulateMediaFeatures([
5587 * {name: 'prefers-color-scheme', value: 'dark'},
5588 * ]);
5589 * await page.evaluate(
5590 * () => matchMedia('(prefers-color-scheme: dark)').matches,
5591 * );
5592 * // → true
5593 * await page.evaluate(
5594 * () => matchMedia('(prefers-color-scheme: light)').matches,
5595 * );
5596 * // → false
5597 *
5598 * await page.emulateMediaFeatures([
5599 * {name: 'prefers-reduced-motion', value: 'reduce'},
5600 * ]);
5601 * await page.evaluate(
5602 * () => matchMedia('(prefers-reduced-motion: reduce)').matches,
5603 * );
5604 * // → true
5605 * await page.evaluate(
5606 * () => matchMedia('(prefers-reduced-motion: no-preference)').matches,
5607 * );
5608 * // → false
5609 *
5610 * await page.emulateMediaFeatures([
5611 * {name: 'prefers-color-scheme', value: 'dark'},
5612 * {name: 'prefers-reduced-motion', value: 'reduce'},
5613 * ]);
5614 * await page.evaluate(
5615 * () => matchMedia('(prefers-color-scheme: dark)').matches,
5616 * );
5617 * // → true
5618 * await page.evaluate(
5619 * () => matchMedia('(prefers-color-scheme: light)').matches,
5620 * );
5621 * // → false
5622 * await page.evaluate(
5623 * () => matchMedia('(prefers-reduced-motion: reduce)').matches,
5624 * );
5625 * // → true
5626 * await page.evaluate(
5627 * () => matchMedia('(prefers-reduced-motion: no-preference)').matches,
5628 * );
5629 * // → false
5630 *
5631 * await page.emulateMediaFeatures([{name: 'color-gamut', value: 'p3'}]);
5632 * await page.evaluate(() => matchMedia('(color-gamut: srgb)').matches);
5633 * // → true
5634 * await page.evaluate(() => matchMedia('(color-gamut: p3)').matches);
5635 * // → true
5636 * await page.evaluate(() => matchMedia('(color-gamut: rec2020)').matches);
5637 * // → false
5638 * ```
5639 */
5640 abstract emulateMediaFeatures(features?: MediaFeature[]): Promise<void>;
5641 /**
5642 * @param timezoneId - Changes the timezone of the page. See
5643 * {@link https://source.chromium.org/chromium/chromium/deps/icu.git/+/faee8bc70570192d82d2978a71e2a615788597d1:source/data/misc/metaZones.txt | ICU’s metaZones.txt}
5644 * for a list of supported timezone IDs. Passing
5645 * `null` disables timezone emulation.
5646 */
5647 abstract emulateTimezone(timezoneId?: string): Promise<void>;
5648 /**
5649 * Emulates the idle state.
5650 * If no arguments set, clears idle state emulation.
5651 *
5652 * @example
5653 *
5654 * ```ts
5655 * // set idle emulation
5656 * await page.emulateIdleState({isUserActive: true, isScreenUnlocked: false});
5657 *
5658 * // do some checks here
5659 * ...
5660 *
5661 * // clear idle emulation
5662 * await page.emulateIdleState();
5663 * ```
5664 *
5665 * @param overrides - Mock idle state. If not set, clears idle overrides
5666 */
5667 abstract emulateIdleState(overrides?: {
5668 isUserActive: boolean;
5669 isScreenUnlocked: boolean;
5670 }): Promise<void>;
5671 /**
5672 * Simulates the given vision deficiency on the page.
5673 *
5674 * @example
5675 *
5676 * ```ts
5677 * import puppeteer from 'puppeteer';
5678 *
5679 * (async () => {
5680 * const browser = await puppeteer.launch();
5681 * const page = await browser.newPage();
5682 * await page.goto('https://v8.dev/blog/10-years');
5683 *
5684 * await page.emulateVisionDeficiency('achromatopsia');
5685 * await page.screenshot({path: 'achromatopsia.png'});
5686 *
5687 * await page.emulateVisionDeficiency('deuteranopia');
5688 * await page.screenshot({path: 'deuteranopia.png'});
5689 *
5690 * await page.emulateVisionDeficiency('blurredVision');
5691 * await page.screenshot({path: 'blurred-vision.png'});
5692 *
5693 * await page.emulateVisionDeficiency('reducedContrast');
5694 * await page.screenshot({path: 'reduced-contrast.png'});
5695 *
5696 * await browser.close();
5697 * })();
5698 * ```
5699 *
5700 * @param type - the type of deficiency to simulate, or `'none'` to reset.
5701 */
5702 abstract emulateVisionDeficiency(type?: Protocol.Emulation.SetEmulatedVisionDeficiencyRequest['type']): Promise<void>;
5703 /**
5704 * `page.setViewport` will resize the page. A lot of websites don't expect
5705 * phones to change size, so you should set the viewport before navigating to
5706 * the page.
5707 *
5708 * In the case of multiple pages in a single browser, each page can have its
5709 * own viewport size. Setting the viewport to `null` resets the viewport to
5710 * its default value.
5711 *
5712 * @example
5713 *
5714 * ```ts
5715 * const page = await browser.newPage();
5716 * await page.setViewport({
5717 * width: 640,
5718 * height: 480,
5719 * deviceScaleFactor: 1,
5720 * });
5721 * await page.goto('https://example.com');
5722 * ```
5723 *
5724 * @param viewport -
5725 * @remarks
5726 * NOTE: in certain cases, setting viewport will reload the page in order to
5727 * set the isMobile or hasTouch properties.
5728 */
5729 abstract setViewport(viewport: Viewport | null): Promise<void>;
5730 /**
5731 * Returns the current page viewport settings without checking the actual page
5732 * viewport.
5733 *
5734 * This is either the viewport set with the previous {@link Page.setViewport}
5735 * call or the default viewport set via
5736 * {@link ConnectOptions.defaultViewport |
5737 * ConnectOptions.defaultViewport}.
5738 */
5739 abstract viewport(): Viewport | null;
5740 /**
5741 * Evaluates a function in the page's context and returns the result.
5742 *
5743 * If the function passed to `page.evaluate` returns a Promise, the
5744 * function will wait for the promise to resolve and return its value.
5745 *
5746 * @example
5747 *
5748 * ```ts
5749 * const result = await frame.evaluate(() => {
5750 * return Promise.resolve(8 * 7);
5751 * });
5752 * console.log(result); // prints "56"
5753 * ```
5754 *
5755 * You can pass a string instead of a function (although functions are
5756 * recommended as they are easier to debug and use with TypeScript):
5757 *
5758 * @example
5759 *
5760 * ```ts
5761 * const aHandle = await page.evaluate('1 + 2');
5762 * ```
5763 *
5764 * To get the best TypeScript experience, you should pass in as the
5765 * generic the type of `pageFunction`:
5766 *
5767 * ```ts
5768 * const aHandle = await page.evaluate(() => 2);
5769 * ```
5770 *
5771 * @example
5772 *
5773 * {@link ElementHandle} instances (including {@link JSHandle}s) can be passed
5774 * as arguments to the `pageFunction`:
5775 *
5776 * ```ts
5777 * const bodyHandle = await page.$('body');
5778 * const html = await page.evaluate(body => body.innerHTML, bodyHandle);
5779 * await bodyHandle.dispose();
5780 * ```
5781 *
5782 * @param pageFunction - a function that is run within the page
5783 * @param args - arguments to be passed to the pageFunction
5784 *
5785 * @returns the return value of `pageFunction`.
5786 */
5787 evaluate<Params extends unknown[], Func extends EvaluateFunc<Params> = EvaluateFunc<Params>>(pageFunction: Func | string, ...args: Params): Promise<Awaited<ReturnType<Func>>>;
5788 /**
5789 * Adds a function which would be invoked in one of the following scenarios:
5790 *
5791 * - whenever the page is navigated
5792 *
5793 * - whenever the child frame is attached or navigated. In this case, the
5794 * function is invoked in the context of the newly attached frame.
5795 *
5796 * The function is invoked after the document was created but before any of
5797 * its scripts were run. This is useful to amend the JavaScript environment,
5798 * e.g. to seed `Math.random`.
5799 * @param pageFunction - Function to be evaluated in browser context
5800 * @param args - Arguments to pass to `pageFunction`
5801 * @example
5802 * An example of overriding the navigator.languages property before the page loads:
5803 *
5804 * ```ts
5805 * // preload.js
5806 *
5807 * // overwrite the `languages` property to use a custom getter
5808 * Object.defineProperty(navigator, 'languages', {
5809 * get: function () {
5810 * return ['en-US', 'en', 'bn'];
5811 * },
5812 * });
5813 *
5814 * // In your puppeteer script, assuming the preload.js file is
5815 * // in same folder of our script.
5816 * const preloadFile = fs.readFileSync('./preload.js', 'utf8');
5817 * await page.evaluateOnNewDocument(preloadFile);
5818 * ```
5819 */
5820 abstract evaluateOnNewDocument<Params extends unknown[], Func extends (...args: Params) => unknown = (...args: Params) => unknown>(pageFunction: Func | string, ...args: Params): Promise<NewDocumentScriptEvaluation>;
5821 /**
5822 * Removes script that injected into page by Page.evaluateOnNewDocument.
5823 *
5824 * @param identifier - script identifier
5825 */
5826 abstract removeScriptToEvaluateOnNewDocument(identifier: string): Promise<void>;
5827 /**
5828 * Toggles ignoring cache for each request based on the enabled state. By
5829 * default, caching is enabled.
5830 * @param enabled - sets the `enabled` state of cache
5831 * @defaultValue `true`
5832 */
5833 abstract setCacheEnabled(enabled?: boolean): Promise<void>;
5834
5835 /**
5836 * Captures a screencast of this {@link Page | page}.
5837 *
5838 * @example
5839 * Recording a {@link Page | page}:
5840 *
5841 * ```
5842 * import puppeteer from 'puppeteer';
5843 *
5844 * // Launch a browser
5845 * const browser = await puppeteer.launch();
5846 *
5847 * // Create a new page
5848 * const page = await browser.newPage();
5849 *
5850 * // Go to your site.
5851 * await page.goto("https://www.example.com");
5852 *
5853 * // Start recording.
5854 * const recorder = await page.screencast({path: 'recording.webm'});
5855 *
5856 * // Do something.
5857 *
5858 * // Stop recording.
5859 * await recorder.stop();
5860 *
5861 * browser.close();
5862 * ```
5863 *
5864 * @param options - Configures screencast behavior.
5865 *
5866 * @experimental
5867 *
5868 * @remarks
5869 *
5870 * All recordings will be {@link https://www.webmproject.org/ | WebM} format using
5871 * the {@link https://www.webmproject.org/vp9/ | VP9} video codec. The FPS is 30.
5872 *
5873 * You must have {@link https://ffmpeg.org/ | ffmpeg} installed on your system.
5874 */
5875 screencast(options?: Readonly<ScreencastOptions>): Promise<ScreenRecorder>;
5876
5877
5878 /**
5879 * Captures a screenshot of this {@link Page | page}.
5880 *
5881 * @param options - Configures screenshot behavior.
5882 *
5883 * @remarks
5884 *
5885 * While a screenshot is being taken in a {@link BrowserContext}, the
5886 * following methods will automatically wait for the screenshot to
5887 * finish to prevent interference with the screenshot process:
5888 * {@link BrowserContext.newPage}, {@link Browser.newPage},
5889 * {@link Page.close}.
5890 *
5891 * Calling {@link Page.bringToFront} will not wait for existing
5892 * screenshot operations.
5893 *
5894 */
5895 screenshot(options: Readonly<ScreenshotOptions> & {
5896 encoding: 'base64';
5897 }): Promise<string>;
5898 screenshot(options?: Readonly<ScreenshotOptions>): Promise<Uint8Array>;
5899
5900 /**
5901 * Generates a PDF of the page with the `print` CSS media type.
5902 *
5903 * @param options - options for generating the PDF.
5904 *
5905 * @remarks
5906 *
5907 * To generate a PDF with the `screen` media type, call
5908 * {@link Page.emulateMediaType | `page.emulateMediaType('screen')`} before
5909 * calling `page.pdf()`.
5910 *
5911 * By default, `page.pdf()` generates a pdf with modified colors for printing.
5912 * Use the
5913 * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/-webkit-print-color-adjust | `-webkit-print-color-adjust`}
5914 * property to force rendering of exact colors.
5915 */
5916 abstract createPDFStream(options?: PDFOptions): Promise<ReadableStream<Uint8Array>>;
5917 /**
5918 * {@inheritDoc Page.createPDFStream}
5919 */
5920 abstract pdf(options?: PDFOptions): Promise<Uint8Array>;
5921 /**
5922 * The page's title
5923 *
5924 * @remarks
5925 *
5926 * Shortcut for {@link Frame.title | page.mainFrame().title()}.
5927 */
5928 title(): Promise<string>;
5929 abstract close(options?: {
5930 runBeforeUnload?: boolean;
5931 }): Promise<void>;
5932 /**
5933 * Indicates that the page has been closed.
5934 * @returns
5935 */
5936 abstract isClosed(): boolean;
5937 /**
5938 * {@inheritDoc Mouse}
5939 */
5940 abstract get mouse(): Mouse;
5941 /**
5942 * This method fetches an element with `selector`, scrolls it into view if
5943 * needed, and then uses {@link Page.mouse} to click in the center of the
5944 * element. If there's no element matching `selector`, the method throws an
5945 * error.
5946 *
5947 * @remarks
5948 *
5949 * Bear in mind that if `click()` triggers a navigation event and
5950 * there's a separate `page.waitForNavigation()` promise to be resolved, you
5951 * may end up with a race condition that yields unexpected results. The
5952 * correct pattern for click and wait for navigation is the following:
5953 *
5954 * ```ts
5955 * const [response] = await Promise.all([
5956 * page.waitForNavigation(waitOptions),
5957 * page.click(selector, clickOptions),
5958 * ]);
5959 * ```
5960 *
5961 * Shortcut for {@link Frame.click | page.mainFrame().click(selector[, options]) }.
5962 * @param selector -
5963 * {@link https://pptr.dev/guides/page-interactions#selectors | selector}
5964 * to query the page for.
5965 * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors | CSS selectors}
5966 * can be passed as-is and a
5967 * {@link https://pptr.dev/guides/page-interactions#non-css-selectors | Puppeteer-specific selector syntax}
5968 * allows quering by
5969 * {@link https://pptr.dev/guides/page-interactions#text-selectors--p-text | text},
5970 * {@link https://pptr.dev/guides/page-interactions#aria-selectors--p-aria | a11y role and name},
5971 * and
5972 * {@link https://pptr.dev/guides/page-interactions#xpath-selectors--p-xpath | xpath}
5973 * and
5974 * {@link https://pptr.dev/guides/page-interactions#querying-elements-in-shadow-dom | combining these queries across shadow roots}.
5975 * Alternatively, you can specify the selector type using a
5976 * {@link https://pptr.dev/guides/page-interactions#prefixed-selector-syntax | prefix}. If there are
5977 * multiple elements satisfying the `selector`, the first will be clicked
5978 * @param options - `Object`
5979 * @returns Promise which resolves when the element matching `selector` is
5980 * successfully clicked. The Promise will be rejected if there is no element
5981 * matching `selector`.
5982 */
5983 click(selector: string, options?: Readonly<ClickOptions>): Promise<void>;
5984 /**
5985 * This method fetches an element with `selector` and focuses it. If
5986 * there's no element matching `selector`, the method throws an error.
5987 * @param selector -
5988 * {@link https://pptr.dev/guides/page-interactions#selectors | selector}
5989 * to query the page for.
5990 * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors | CSS selectors}
5991 * can be passed as-is and a
5992 * {@link https://pptr.dev/guides/page-interactions#non-css-selectors | Puppeteer-specific selector syntax}
5993 * allows quering by
5994 * {@link https://pptr.dev/guides/page-interactions#text-selectors--p-text | text},
5995 * {@link https://pptr.dev/guides/page-interactions#aria-selectors--p-aria | a11y role and name},
5996 * and
5997 * {@link https://pptr.dev/guides/page-interactions#xpath-selectors--p-xpath | xpath}
5998 * and
5999 * {@link https://pptr.dev/guides/page-interactions#querying-elements-in-shadow-dom | combining these queries across shadow roots}.
6000 * Alternatively, you can specify the selector type using a
6001 * {@link https://pptr.dev/guides/page-interactions#prefixed-selector-syntax | prefix}.
6002 * If there are multiple elements satisfying the selector, the first
6003 * will be focused.
6004 * @returns Promise which resolves when the element matching selector
6005 * is successfully focused. The promise will be rejected if there is
6006 * no element matching selector.
6007 *
6008 * @remarks
6009 *
6010 * Shortcut for
6011 * {@link Frame.focus | page.mainFrame().focus(selector)}.
6012 */
6013 focus(selector: string): Promise<void>;
6014 /**
6015 * This method fetches an element with `selector`, scrolls it into view if
6016 * needed, and then uses {@link Page.mouse}
6017 * to hover over the center of the element.
6018 * If there's no element matching `selector`, the method throws an error.
6019 * @param selector -
6020 * {@link https://pptr.dev/guides/page-interactions#selectors | selector}
6021 * to query the page for.
6022 * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors | CSS selectors}
6023 * can be passed as-is and a
6024 * {@link https://pptr.dev/guides/page-interactions#non-css-selectors | Puppeteer-specific selector syntax}
6025 * allows quering by
6026 * {@link https://pptr.dev/guides/page-interactions#text-selectors--p-text | text},
6027 * {@link https://pptr.dev/guides/page-interactions#aria-selectors--p-aria | a11y role and name},
6028 * and
6029 * {@link https://pptr.dev/guides/page-interactions#xpath-selectors--p-xpath | xpath}
6030 * and
6031 * {@link https://pptr.dev/guides/page-interactions#querying-elements-in-shadow-dom | combining these queries across shadow roots}.
6032 * Alternatively, you can specify the selector type using a
6033 * {@link https://pptr.dev/guides/page-interactions#prefixed-selector-syntax | prefix}. If there are
6034 * multiple elements satisfying the `selector`, the first will be hovered.
6035 * @returns Promise which resolves when the element matching `selector` is
6036 * successfully hovered. Promise gets rejected if there's no element matching
6037 * `selector`.
6038 *
6039 * @remarks
6040 *
6041 * Shortcut for {@link Page.hover | page.mainFrame().hover(selector)}.
6042 */
6043 hover(selector: string): Promise<void>;
6044 /**
6045 * Triggers a `change` and `input` event once all the provided options have been
6046 * selected. If there's no `<select>` element matching `selector`, the method
6047 * throws an error.
6048 *
6049 * @example
6050 *
6051 * ```ts
6052 * page.select('select#colors', 'blue'); // single selection
6053 * page.select('select#colors', 'red', 'green', 'blue'); // multiple selections
6054 * ```
6055 *
6056 * @param selector -
6057 * {@link https://pptr.dev/guides/page-interactions#selectors | selector}
6058 * to query the page for.
6059 * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors | CSS selectors}
6060 * can be passed as-is and a
6061 * {@link https://pptr.dev/guides/page-interactions#non-css-selectors | Puppeteer-specific selector syntax}
6062 * allows quering by
6063 * {@link https://pptr.dev/guides/page-interactions#text-selectors--p-text | text},
6064 * {@link https://pptr.dev/guides/page-interactions#aria-selectors--p-aria | a11y role and name},
6065 * and
6066 * {@link https://pptr.dev/guides/page-interactions#xpath-selectors--p-xpath | xpath}
6067 * and
6068 * {@link https://pptr.dev/guides/page-interactions#querying-elements-in-shadow-dom | combining these queries across shadow roots}.
6069 * Alternatively, you can specify the selector type using a
6070 * {@link https://pptr.dev/guides/page-interactions#prefixed-selector-syntax | prefix}.
6071 * @param values - Values of options to select. If the `<select>` has the
6072 * `multiple` attribute, all values are considered, otherwise only the first one
6073 * is taken into account.
6074 * @returns
6075 *
6076 * @remarks
6077 *
6078 * Shortcut for {@link Frame.select | page.mainFrame().select()}
6079 */
6080 select(selector: string, ...values: string[]): Promise<string[]>;
6081 /**
6082 * This method fetches an element with `selector`, scrolls it into view if
6083 * needed, and then uses {@link Page.touchscreen}
6084 * to tap in the center of the element.
6085 * If there's no element matching `selector`, the method throws an error.
6086 * @param selector -
6087 * {@link https://pptr.dev/guides/page-interactions#selectors | selector}
6088 * to query the page for.
6089 * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors | CSS selectors}
6090 * can be passed as-is and a
6091 * {@link https://pptr.dev/guides/page-interactions#non-css-selectors | Puppeteer-specific selector syntax}
6092 * allows quering by
6093 * {@link https://pptr.dev/guides/page-interactions#text-selectors--p-text | text},
6094 * {@link https://pptr.dev/guides/page-interactions#aria-selectors--p-aria | a11y role and name},
6095 * and
6096 * {@link https://pptr.dev/guides/page-interactions#xpath-selectors--p-xpath | xpath}
6097 * and
6098 * {@link https://pptr.dev/guides/page-interactions#querying-elements-in-shadow-dom | combining these queries across shadow roots}.
6099 * Alternatively, you can specify the selector type using a
6100 * {@link https://pptr.dev/guides/page-interactions#prefixed-selector-syntax | prefix}. If there are multiple elements satisfying the
6101 * selector, the first will be tapped.
6102 *
6103 * @remarks
6104 *
6105 * Shortcut for {@link Frame.tap | page.mainFrame().tap(selector)}.
6106 */
6107 tap(selector: string): Promise<void>;
6108 /**
6109 * Sends a `keydown`, `keypress/input`, and `keyup` event for each character
6110 * in the text.
6111 *
6112 * To press a special key, like `Control` or `ArrowDown`, use {@link Keyboard.press}.
6113 * @example
6114 *
6115 * ```ts
6116 * await page.type('#mytextarea', 'Hello');
6117 * // Types instantly
6118 * await page.type('#mytextarea', 'World', {delay: 100});
6119 * // Types slower, like a user
6120 * ```
6121 *
6122 * @param selector -
6123 * {@link https://pptr.dev/guides/page-interactions#selectors | selector}
6124 * to query the page for.
6125 * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors | CSS selectors}
6126 * can be passed as-is and a
6127 * {@link https://pptr.dev/guides/page-interactions#non-css-selectors | Puppeteer-specific selector syntax}
6128 * allows quering by
6129 * {@link https://pptr.dev/guides/page-interactions#text-selectors--p-text | text},
6130 * {@link https://pptr.dev/guides/page-interactions#aria-selectors--p-aria | a11y role and name},
6131 * and
6132 * {@link https://pptr.dev/guides/page-interactions#xpath-selectors--p-xpath | xpath}
6133 * and
6134 * {@link https://pptr.dev/guides/page-interactions#querying-elements-in-shadow-dom | combining these queries across shadow roots}.
6135 * Alternatively, you can specify the selector type using a
6136 * {@link https://pptr.dev/guides/page-interactions#prefixed-selector-syntax | prefix}.
6137 * @param text - A text to type into a focused element.
6138 * @param options - have property `delay` which is the Time to wait between
6139 * key presses in milliseconds. Defaults to `0`.
6140 * @returns
6141 */
6142 type(selector: string, text: string, options?: Readonly<KeyboardTypeOptions>): Promise<void>;
6143 /**
6144 * Wait for the `selector` to appear in page. If at the moment of calling the
6145 * method the `selector` already exists, the method will return immediately. If
6146 * the `selector` doesn't appear after the `timeout` milliseconds of waiting, the
6147 * function will throw.
6148 *
6149 * @example
6150 * This method works across navigations:
6151 *
6152 * ```ts
6153 * import puppeteer from 'puppeteer';
6154 * (async () => {
6155 * const browser = await puppeteer.launch();
6156 * const page = await browser.newPage();
6157 * let currentURL;
6158 * page
6159 * .waitForSelector('img')
6160 * .then(() => console.log('First URL with image: ' + currentURL));
6161 * for (currentURL of [
6162 * 'https://example.com',
6163 * 'https://google.com',
6164 * 'https://bbc.com',
6165 * ]) {
6166 * await page.goto(currentURL);
6167 * }
6168 * await browser.close();
6169 * })();
6170 * ```
6171 *
6172 * @param selector -
6173 * {@link https://pptr.dev/guides/page-interactions#selectors | selector}
6174 * to query the page for.
6175 * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors | CSS selectors}
6176 * can be passed as-is and a
6177 * {@link https://pptr.dev/guides/page-interactions#non-css-selectors | Puppeteer-specific selector syntax}
6178 * allows quering by
6179 * {@link https://pptr.dev/guides/page-interactions#text-selectors--p-text | text},
6180 * {@link https://pptr.dev/guides/page-interactions#aria-selectors--p-aria | a11y role and name},
6181 * and
6182 * {@link https://pptr.dev/guides/page-interactions#xpath-selectors--p-xpath | xpath}
6183 * and
6184 * {@link https://pptr.dev/guides/page-interactions#querying-elements-in-shadow-dom | combining these queries across shadow roots}.
6185 * Alternatively, you can specify the selector type using a
6186 * {@link https://pptr.dev/guides/page-interactions#prefixed-selector-syntax | prefix}.
6187 * @param options - Optional waiting parameters
6188 * @returns Promise which resolves when element specified by selector string
6189 * is added to DOM. Resolves to `null` if waiting for hidden: `true` and
6190 * selector is not found in DOM.
6191 *
6192 * @remarks
6193 * The optional Parameter in Arguments `options` are:
6194 *
6195 * - `visible`: A boolean wait for element to be present in DOM and to be
6196 * visible, i.e. to not have `display: none` or `visibility: hidden` CSS
6197 * properties. Defaults to `false`.
6198 *
6199 * - `hidden`: Wait for element to not be found in the DOM or to be hidden,
6200 * i.e. have `display: none` or `visibility: hidden` CSS properties. Defaults to
6201 * `false`.
6202 *
6203 * - `timeout`: maximum time to wait for in milliseconds. Defaults to `30000`
6204 * (30 seconds). Pass `0` to disable timeout. The default value can be changed
6205 * by using the {@link Page.setDefaultTimeout} method.
6206 */
6207 waitForSelector<Selector extends string>(selector: Selector, options?: WaitForSelectorOptions): Promise<ElementHandle<NodeFor<Selector>> | null>;
6208 /**
6209 * Waits for the provided function, `pageFunction`, to return a truthy value when
6210 * evaluated in the page's context.
6211 *
6212 * @example
6213 * {@link Page.waitForFunction} can be used to observe a viewport size change:
6214 *
6215 * ```ts
6216 * import puppeteer from 'puppeteer';
6217 * (async () => {
6218 * const browser = await puppeteer.launch();
6219 * const page = await browser.newPage();
6220 * const watchDog = page.waitForFunction('window.innerWidth < 100');
6221 * await page.setViewport({width: 50, height: 50});
6222 * await watchDog;
6223 * await browser.close();
6224 * })();
6225 * ```
6226 *
6227 * @example
6228 * Arguments can be passed from Node.js to `pageFunction`:
6229 *
6230 * ```ts
6231 * const selector = '.foo';
6232 * await page.waitForFunction(
6233 * selector => !!document.querySelector(selector),
6234 * {},
6235 * selector,
6236 * );
6237 * ```
6238 *
6239 * @example
6240 * The provided `pageFunction` can be asynchronous:
6241 *
6242 * ```ts
6243 * const username = 'github-username';
6244 * await page.waitForFunction(
6245 * async username => {
6246 * const githubResponse = await fetch(
6247 * `https://api.github.com/users/${username}`,
6248 * );
6249 * const githubUser = await githubResponse.json();
6250 * // show the avatar
6251 * const img = document.createElement('img');
6252 * img.src = githubUser.avatar_url;
6253 * // wait 3 seconds
6254 * await new Promise((resolve, reject) => setTimeout(resolve, 3000));
6255 * img.remove();
6256 * },
6257 * {},
6258 * username,
6259 * );
6260 * ```
6261 *
6262 * @param pageFunction - Function to be evaluated in browser context until it returns a
6263 * truthy value.
6264 * @param options - Options for configuring waiting behavior.
6265 */
6266 waitForFunction<Params extends unknown[], Func extends EvaluateFunc<Params> = EvaluateFunc<Params>>(pageFunction: Func | string, options?: FrameWaitForFunctionOptions, ...args: Params): Promise<HandleFor<Awaited<ReturnType<Func>>>>;
6267 /**
6268 * This method is typically coupled with an action that triggers a device
6269 * request from an api such as WebBluetooth.
6270 *
6271 * :::caution
6272 *
6273 * This must be called before the device request is made. It will not return a
6274 * currently active device prompt.
6275 *
6276 * :::
6277 *
6278 * @example
6279 *
6280 * ```ts
6281 * const [devicePrompt] = Promise.all([
6282 * page.waitForDevicePrompt(),
6283 * page.click('#connect-bluetooth'),
6284 * ]);
6285 * await devicePrompt.select(
6286 * await devicePrompt.waitForDevice(({name}) => name.includes('My Device')),
6287 * );
6288 * ```
6289 */
6290 abstract waitForDevicePrompt(options?: WaitTimeoutOptions): Promise<DeviceRequestPrompt>;
6291
6292
6293}
6294
6295/**
6296 * All the events that a page instance may emit.
6297 *
6298 * @public
6299 */
6300export declare const enum PageEvent {
6301 /**
6302 * Emitted when the page closes.
6303 */
6304 Close = "close",
6305 /**
6306 * Emitted when JavaScript within the page calls one of console API methods,
6307 * e.g. `console.log` or `console.dir`. Also emitted if the page throws an
6308 * error or a warning.
6309 *
6310 * @remarks
6311 * A `console` event provides a {@link ConsoleMessage} representing the
6312 * console message that was logged.
6313 *
6314 * @example
6315 * An example of handling `console` event:
6316 *
6317 * ```ts
6318 * page.on('console', msg => {
6319 * for (let i = 0; i < msg.args().length; ++i)
6320 * console.log(`${i}: ${msg.args()[i]}`);
6321 * });
6322 * page.evaluate(() => console.log('hello', 5, {foo: 'bar'}));
6323 * ```
6324 */
6325 Console = "console",
6326 /**
6327 * Emitted when a JavaScript dialog appears, such as `alert`, `prompt`,
6328 * `confirm` or `beforeunload`. Puppeteer can respond to the dialog via
6329 * {@link Dialog.accept} or {@link Dialog.dismiss}.
6330 */
6331 Dialog = "dialog",
6332 /**
6333 * Emitted when the JavaScript
6334 * {@link https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded | DOMContentLoaded }
6335 * event is dispatched.
6336 */
6337 DOMContentLoaded = "domcontentloaded",
6338 /**
6339 * Emitted when the page crashes. Will contain an `Error`.
6340 */
6341 Error = "error",
6342 /** Emitted when a frame is attached. Will contain a {@link Frame}. */
6343 FrameAttached = "frameattached",
6344 /** Emitted when a frame is detached. Will contain a {@link Frame}. */
6345 FrameDetached = "framedetached",
6346 /**
6347 * Emitted when a frame is navigated to a new URL. Will contain a
6348 * {@link Frame}.
6349 */
6350 FrameNavigated = "framenavigated",
6351 /**
6352 * Emitted when the JavaScript
6353 * {@link https://developer.mozilla.org/en-US/docs/Web/Events/load | load}
6354 * event is dispatched.
6355 */
6356 Load = "load",
6357 /**
6358 * Emitted when the JavaScript code makes a call to `console.timeStamp`. For
6359 * the list of metrics see {@link Page.metrics | page.metrics}.
6360 *
6361 * @remarks
6362 * Contains an object with two properties:
6363 *
6364 * - `title`: the title passed to `console.timeStamp`
6365 * - `metrics`: object containing metrics as key/value pairs. The values will
6366 * be `number`s.
6367 */
6368 Metrics = "metrics",
6369 /**
6370 * Emitted when an uncaught exception happens within the page. Contains an
6371 * `Error`.
6372 */
6373 PageError = "pageerror",
6374 /**
6375 * Emitted when the page opens a new tab or window.
6376 *
6377 * Contains a {@link Page} corresponding to the popup window.
6378 *
6379 * @example
6380 *
6381 * ```ts
6382 * const [popup] = await Promise.all([
6383 * new Promise(resolve => page.once('popup', resolve)),
6384 * page.click('a[target=_blank]'),
6385 * ]);
6386 * ```
6387 *
6388 * ```ts
6389 * const [popup] = await Promise.all([
6390 * new Promise(resolve => page.once('popup', resolve)),
6391 * page.evaluate(() => window.open('https://example.com')),
6392 * ]);
6393 * ```
6394 */
6395 Popup = "popup",
6396 /**
6397 * Emitted when a page issues a request and contains a {@link HTTPRequest}.
6398 *
6399 * @remarks
6400 * The object is readonly. See {@link Page.setRequestInterception} for
6401 * intercepting and mutating requests.
6402 */
6403 Request = "request",
6404 /**
6405 * Emitted when a request ended up loading from cache. Contains a
6406 * {@link HTTPRequest}.
6407 *
6408 * @remarks
6409 * For certain requests, might contain undefined.
6410 * {@link https://crbug.com/750469}
6411 */
6412 RequestServedFromCache = "requestservedfromcache",
6413 /**
6414 * Emitted when a request fails, for example by timing out.
6415 *
6416 * Contains a {@link HTTPRequest}.
6417 *
6418 * @remarks
6419 * HTTP Error responses, such as 404 or 503, are still successful responses
6420 * from HTTP standpoint, so request will complete with `requestfinished` event
6421 * and not with `requestfailed`.
6422 */
6423 RequestFailed = "requestfailed",
6424 /**
6425 * Emitted when a request finishes successfully. Contains a
6426 * {@link HTTPRequest}.
6427 */
6428 RequestFinished = "requestfinished",
6429 /**
6430 * Emitted when a response is received. Contains a {@link HTTPResponse}.
6431 */
6432 Response = "response",
6433 /**
6434 * Emitted when a dedicated
6435 * {@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API | WebWorker}
6436 * is spawned by the page.
6437 */
6438 WorkerCreated = "workercreated",
6439 /**
6440 * Emitted when a dedicated
6441 * {@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API | WebWorker}
6442 * is destroyed by the page.
6443 */
6444 WorkerDestroyed = "workerdestroyed"
6445}
6446
6447/**
6448 * Denotes the objects received by callback functions for page events.
6449 *
6450 * See {@link PageEvent} for more detail on the events and when they are
6451 * emitted.
6452 *
6453 * @public
6454 */
6455export declare interface PageEvents extends Record<EventType, unknown> {
6456 [PageEvent.Close]: undefined;
6457 [PageEvent.Console]: ConsoleMessage;
6458 [PageEvent.Dialog]: Dialog;
6459 [PageEvent.DOMContentLoaded]: undefined;
6460 [PageEvent.Error]: Error;
6461 [PageEvent.FrameAttached]: Frame;
6462 [PageEvent.FrameDetached]: Frame;
6463 [PageEvent.FrameNavigated]: Frame;
6464 [PageEvent.Load]: undefined;
6465 [PageEvent.Metrics]: {
6466 title: string;
6467 metrics: Metrics;
6468 };
6469 [PageEvent.PageError]: Error;
6470 [PageEvent.Popup]: Page | null;
6471 [PageEvent.Request]: HTTPRequest;
6472 [PageEvent.Response]: HTTPResponse;
6473 [PageEvent.RequestFailed]: HTTPRequest;
6474 [PageEvent.RequestFinished]: HTTPRequest;
6475 [PageEvent.RequestServedFromCache]: HTTPRequest;
6476 [PageEvent.WorkerCreated]: WebWorker;
6477 [PageEvent.WorkerDestroyed]: WebWorker;
6478}
6479
6480/**
6481 * All the valid paper format types when printing a PDF.
6482 *
6483 * @remarks
6484 *
6485 * The sizes of each format are as follows:
6486 *
6487 * - `Letter`: 8.5in x 11in / 21.59cm x 27.94cm
6488 *
6489 * - `Legal`: 8.5in x 14in / 21.59cm x 35.56cm
6490 *
6491 * - `Tabloid`: 11in x 17in / 27.94cm x 43.18cm
6492 *
6493 * - `Ledger`: 17in x 11in / 43.18cm x 27.94cm
6494 *
6495 * - `A0`: 33.1102in x 46.811in / 84.1cm x 118.9cm
6496 *
6497 * - `A1`: 23.3858in x 33.1102in / 59.4cm x 84.1cm
6498 *
6499 * - `A2`: 16.5354in x 23.3858in / 42cm x 59.4cm
6500 *
6501 * - `A3`: 11.6929in x 16.5354in / 29.7cm x 42cm
6502 *
6503 * - `A4`: 8.2677in x 11.6929in / 21cm x 29.7cm
6504 *
6505 * - `A5`: 5.8268in x 8.2677in / 14.8cm x 21cm
6506 *
6507 * - `A6`: 4.1339in x 5.8268in / 10.5cm x 14.8cm
6508 *
6509 * @public
6510 */
6511export declare type PaperFormat = Uppercase<LowerCasePaperFormat> | Capitalize<LowerCasePaperFormat> | LowerCasePaperFormat;
6512
6513/**
6514 * @license
6515 * Copyright 2020 Google Inc.
6516 * SPDX-License-Identifier: Apache-2.0
6517 */
6518/**
6519 * @public
6520 */
6521export declare interface PDFMargin {
6522 top?: string | number;
6523 bottom?: string | number;
6524 left?: string | number;
6525 right?: string | number;
6526}
6527
6528/**
6529 * Valid options to configure PDF generation via {@link Page.pdf}.
6530 * @public
6531 */
6532export declare interface PDFOptions {
6533 /**
6534 * Scales the rendering of the web page. Amount must be between `0.1` and `2`.
6535 * @defaultValue `1`
6536 */
6537 scale?: number;
6538 /**
6539 * Whether to show the header and footer.
6540 * @defaultValue `false`
6541 */
6542 displayHeaderFooter?: boolean;
6543 /**
6544 * HTML template for the print header. Should be valid HTML with the following
6545 * classes used to inject values into them:
6546 *
6547 * - `date` formatted print date
6548 *
6549 * - `title` document title
6550 *
6551 * - `url` document location
6552 *
6553 * - `pageNumber` current page number
6554 *
6555 * - `totalPages` total pages in the document
6556 */
6557 headerTemplate?: string;
6558 /**
6559 * HTML template for the print footer. Has the same constraints and support
6560 * for special classes as {@link PDFOptions.headerTemplate}.
6561 */
6562 footerTemplate?: string;
6563 /**
6564 * Set to `true` to print background graphics.
6565 * @defaultValue `false`
6566 */
6567 printBackground?: boolean;
6568 /**
6569 * Whether to print in landscape orientation.
6570 * @defaultValue `false`
6571 */
6572 landscape?: boolean;
6573 /**
6574 * Paper ranges to print, e.g. `1-5, 8, 11-13`.
6575 * @defaultValue The empty string, which means all pages are printed.
6576 */
6577 pageRanges?: string;
6578 /**
6579 * @remarks
6580 * If set, this takes priority over the `width` and `height` options.
6581 * @defaultValue `letter`.
6582 */
6583 format?: PaperFormat;
6584 /**
6585 * Sets the width of paper. You can pass in a number or a string with a unit.
6586 */
6587 width?: string | number;
6588 /**
6589 * Sets the height of paper. You can pass in a number or a string with a unit.
6590 */
6591 height?: string | number;
6592 /**
6593 * Give any CSS `@page` size declared in the page priority over what is
6594 * declared in the `width` or `height` or `format` option.
6595 * @defaultValue `false`, which will scale the content to fit the paper size.
6596 */
6597 preferCSSPageSize?: boolean;
6598 /**
6599 * Set the PDF margins.
6600 * @defaultValue `undefined` no margins are set.
6601 */
6602 margin?: PDFMargin;
6603 /**
6604 * The path to save the file to.
6605 *
6606 * @remarks
6607 *
6608 * If the path is relative, it's resolved relative to the current working directory.
6609 *
6610 * @defaultValue `undefined`, which means the PDF will not be written to disk.
6611 */
6612 path?: string;
6613 /**
6614 * Hides default white background and allows generating pdfs with transparency.
6615 * @defaultValue `false`
6616 */
6617 omitBackground?: boolean;
6618 /**
6619 * Generate tagged (accessible) PDF.
6620 *
6621 * @defaultValue `true`
6622 * @experimental
6623 */
6624 tagged?: boolean;
6625 /**
6626 * Generate document outline.
6627 *
6628 * @defaultValue `false`
6629 * @experimental
6630 */
6631 outline?: boolean;
6632 /**
6633 * Timeout in milliseconds. Pass `0` to disable timeout.
6634 *
6635 * The default value can be changed by using {@link Page.setDefaultTimeout}
6636 *
6637 * @defaultValue `30_000`
6638 */
6639 timeout?: number;
6640 /**
6641 * If true, waits for `document.fonts.ready` to resolve. This might require
6642 * activating the page using {@link Page.bringToFront} if the page is in the
6643 * background.
6644 *
6645 * @defaultValue `true`
6646 */
6647 waitForFonts?: boolean;
6648}
6649
6650/**
6651 * @public
6652 */
6653export declare type Permission = 'geolocation' | 'midi' | 'notifications' | 'camera' | 'microphone' | 'background-sync' | 'ambient-light-sensor' | 'accelerometer' | 'gyroscope' | 'magnetometer' | 'accessibility-events' | 'clipboard-read' | 'clipboard-write' | 'clipboard-sanitized-write' | 'payment-handler' | 'persistent-storage' | 'idle-detection' | 'midi-sysex';
6654
6655/**
6656 * @public
6657 */
6658export declare interface Point {
6659 x: number;
6660 y: number;
6661}
6662
6663declare namespace PQuerySelector {
6664 export {
6665
6666 }
6667}
6668
6669/**
6670 * A list of pre-defined network conditions to be used with
6671 * {@link Page.emulateNetworkConditions}.
6672 *
6673 * @example
6674 *
6675 * ```ts
6676 * import {PredefinedNetworkConditions} from 'puppeteer';
6677 * (async () => {
6678 * const browser = await puppeteer.launch();
6679 * const page = await browser.newPage();
6680 * await page.emulateNetworkConditions(
6681 * PredefinedNetworkConditions['Slow 3G'],
6682 * );
6683 * await page.goto('https://www.google.com');
6684 * await page.emulateNetworkConditions(
6685 * PredefinedNetworkConditions['Fast 3G'],
6686 * );
6687 * await page.goto('https://www.google.com');
6688 * await page.emulateNetworkConditions(
6689 * PredefinedNetworkConditions['Slow 4G'],
6690 * ); // alias to Fast 3G.
6691 * await page.goto('https://www.google.com');
6692 * await page.emulateNetworkConditions(
6693 * PredefinedNetworkConditions['Fast 4G'],
6694 * );
6695 * await page.goto('https://www.google.com');
6696 * // other actions...
6697 * await browser.close();
6698 * })();
6699 * ```
6700 *
6701 * @public
6702 */
6703export declare const PredefinedNetworkConditions: Readonly<{
6704 'Slow 3G': NetworkConditions;
6705 'Fast 3G': NetworkConditions;
6706 'Slow 4G': NetworkConditions;
6707 'Fast 4G': NetworkConditions;
6708}>;
6709
6710/**
6711 * @public
6712 */
6713export declare type Predicate<From, To extends From = From> = ((value: From) => value is To) | ((value: From) => Awaitable<boolean>);
6714
6715export { Protocol }
6716
6717/**
6718 * ProtocolError is emitted whenever there is an error from the protocol.
6719 *
6720 * @public
6721 */
6722export declare class ProtocolError extends PuppeteerError {
6723 #private;
6724 set code(code: number | undefined);
6725 /**
6726 * @readonly
6727 * @public
6728 */
6729 get code(): number | undefined;
6730 set originalMessage(originalMessage: string);
6731 /**
6732 * @readonly
6733 * @public
6734 */
6735 get originalMessage(): string;
6736}
6737
6738/**
6739 * @public
6740 */
6741export declare type ProtocolLifeCycleEvent = 'load' | 'DOMContentLoaded' | 'networkIdle' | 'networkAlmostIdle';
6742
6743/**
6744 * @public
6745 */
6746export declare type ProtocolType = 'cdp' | 'webDriverBiDi';
6747
6748/**
6749 * The main Puppeteer class.
6750 *
6751 * IMPORTANT: if you are using Puppeteer in a Node environment, you will get an
6752 * instance of {@link PuppeteerNode} when you import or require `puppeteer`.
6753 * That class extends `Puppeteer`, so has all the methods documented below as
6754 * well as all that are defined on {@link PuppeteerNode}.
6755 *
6756 * @public
6757 */
6758export declare class Puppeteer {
6759
6760 /**
6761 * Registers a {@link CustomQueryHandler | custom query handler}.
6762 *
6763 * @remarks
6764 * After registration, the handler can be used everywhere where a selector is
6765 * expected by prepending the selection string with `<name>/`. The name is only
6766 * allowed to consist of lower- and upper case latin letters.
6767 *
6768 * @example
6769 *
6770 * ```
6771 * import {Puppeteer}, puppeteer from 'puppeteer';
6772 *
6773 * Puppeteer.registerCustomQueryHandler('text', { … });
6774 * const aHandle = await page.$('text/…');
6775 * ```
6776 *
6777 * @param name - The name that the custom query handler will be registered
6778 * under.
6779 * @param queryHandler - The {@link CustomQueryHandler | custom query handler}
6780 * to register.
6781 *
6782 * @public
6783 */
6784 static registerCustomQueryHandler(name: string, queryHandler: CustomQueryHandler): void;
6785 /**
6786 * Unregisters a custom query handler for a given name.
6787 */
6788 static unregisterCustomQueryHandler(name: string): void;
6789 /**
6790 * Gets the names of all custom query handlers.
6791 */
6792 static customQueryHandlerNames(): string[];
6793 /**
6794 * Unregisters all custom query handlers.
6795 */
6796 static clearCustomQueryHandlers(): void;
6797
6798
6799
6800 /**
6801 * This method attaches Puppeteer to an existing browser instance.
6802 *
6803 * @remarks
6804 *
6805 * @param options - Set of configurable options to set on the browser.
6806 * @returns Promise which resolves to browser instance.
6807 */
6808 connect(options: ConnectOptions): Promise<Browser>;
6809}
6810
6811/**
6812 * @public
6813 */
6814declare const puppeteer: Puppeteer_2.PuppeteerNode;
6815export default puppeteer;
6816
6817declare namespace Puppeteer_2 {
6818 export {
6819 Protocol,
6820 Session,
6821 BrowserContextOptions,
6822 TargetFilterCallback,
6823 Permission,
6824 WaitForTargetOptions,
6825 BrowserEvent,
6826 BrowserEvents,
6827 DebugInfo,
6828 Browser,
6829 BrowserContextEvent,
6830 BrowserContextEvents,
6831 BrowserContext,
6832 CDPEvents,
6833 CDPSessionEvent,
6834 CDPSessionEvents,
6835 CommandOptions,
6836 CDPSession,
6837 Dialog,
6838 Quad,
6839 BoxModel,
6840 BoundingBox,
6841 Offset,
6842 ClickOptions,
6843 Point,
6844 ElementScreenshotOptions,
6845 ElementHandle,
6846 AutofillData,
6847 WaitForOptions,
6848 GoToOptions,
6849 FrameWaitForFunctionOptions,
6850 FrameAddScriptTagOptions,
6851 FrameAddStyleTagOptions,
6852 FrameEvents,
6853 Frame,
6854 ContinueRequestOverrides,
6855 InterceptResolutionState,
6856 ResponseForRequest,
6857 ResourceType,
6858 DEFAULT_INTERCEPT_RESOLUTION_PRIORITY,
6859 HTTPRequest,
6860 InterceptResolutionAction,
6861 ErrorCode,
6862 ActionResult,
6863 RemoteAddress,
6864 HTTPResponse,
6865 KeyDownOptions,
6866 KeyboardTypeOptions,
6867 KeyPressOptions,
6868 Keyboard,
6869 MouseOptions,
6870 MouseClickOptions,
6871 MouseWheelOptions,
6872 MouseMoveOptions,
6873 MouseButton,
6874 Mouse,
6875 TouchHandle,
6876 Touchscreen,
6877 JSHandle,
6878 Metrics,
6879 Credentials,
6880 WaitForNetworkIdleOptions,
6881 WaitTimeoutOptions,
6882 WaitForSelectorOptions,
6883 GeolocationOptions,
6884 MediaFeature,
6885 ScreenshotClip,
6886 ScreenshotOptions,
6887 ScreencastOptions,
6888 QueryOptions,
6889 PageEvent,
6890 PageEvents,
6891 NewDocumentScriptEvaluation,
6892 Page,
6893 TargetType,
6894 Target,
6895 WebWorker,
6896 VisibilityOption,
6897 ActionOptions,
6898 LocatorClickOptions,
6899 LocatorScrollOptions,
6900 LocatorEvent,
6901 LocatorEvents,
6902 Locator,
6903 Predicate,
6904 Mapper,
6905 AwaitedLocator,
6906 SerializedAXNode,
6907 SnapshotOptions,
6908 Accessibility,
6909 Connection,
6910 CoverageEntry,
6911 JSCoverageEntry,
6912 JSCoverageOptions,
6913 CSSCoverageOptions,
6914 Coverage,
6915 JSCoverage,
6916 CSSCoverage,
6917 DeviceRequestPromptDevice,
6918 DeviceRequestPrompt,
6919 ExtensionTransport,
6920 PuppeteerLifeCycleEvent,
6921 ProtocolLifeCycleEvent,
6922 NetworkConditions,
6923 InternalNetworkConditions,
6924 convertCookiesPartitionKeyFromPuppeteerToCdp,
6925 PredefinedNetworkConditions,
6926 TracingOptions,
6927 Tracing,
6928 ExperimentsConfiguration,
6929 Configuration,
6930 ChromeSettings,
6931 ChromeHeadlessShellSettings,
6932 FirefoxSettings,
6933 ConnectionTransport,
6934 ProtocolType,
6935 SupportedWebDriverCapability,
6936 SupportedWebDriverCapabilities,
6937 ConnectOptions,
6938 ConsoleMessageLocation,
6939 ConsoleMessageType,
6940 ConsoleMessage,
6941 CookieSameSite,
6942 CookiePriority,
6943 CookieSourceScheme,
6944 CookiePartitionKey,
6945 Cookie,
6946 CookieParam,
6947 CookieData,
6948 DeleteCookiesRequest,
6949 CustomQueryHandler,
6950 Device,
6951 KnownDevices,
6952 PuppeteerError,
6953 TimeoutError,
6954 TouchError,
6955 ProtocolError,
6956 UnsupportedOperation,
6957 EventType,
6958 Handler,
6959 CommonEventEmitter,
6960 EventsWithWildcard,
6961 EventEmitter,
6962 FileChooser,
6963 PDFMargin,
6964 LowerCasePaperFormat,
6965 PaperFormat,
6966 PDFOptions,
6967 SupportedBrowser,
6968 Puppeteer,
6969 SecurityDetails,
6970 AwaitablePredicate,
6971 Moveable,
6972 AwaitableIterable,
6973 Awaitable,
6974 HandleFor,
6975 HandleOr,
6976 FlattenHandle,
6977 InnerParams,
6978 ElementFor,
6979 EvaluateFunc,
6980 EvaluateFuncWith,
6981 NodeFor,
6982 KeyInput,
6983 Viewport,
6984 DownloadPolicy,
6985 DownloadBehavior,
6986 ChromeReleaseChannel,
6987 LaunchOptions,
6988 BrowserLauncher,
6989 PuppeteerNode,
6990 ScreenRecorder
6991 }
6992}
6993
6994/**
6995 * @license
6996 * Copyright 2018 Google Inc.
6997 * SPDX-License-Identifier: Apache-2.0
6998 */
6999/**
7000 * The base class for all Puppeteer-specific errors
7001 *
7002 * @public
7003 */
7004export declare class PuppeteerError extends Error {
7005
7006
7007}
7008
7009/**
7010 * @public
7011 */
7012export declare type PuppeteerLifeCycleEvent =
7013/**
7014* Waits for the 'load' event.
7015*/
7016'load'
7017/**
7018* Waits for the 'DOMContentLoaded' event.
7019*/
7020| 'domcontentloaded'
7021/**
7022* Waits till there are no more than 0 network connections for at least `500`
7023* ms.
7024*/
7025| 'networkidle0'
7026/**
7027* Waits till there are no more than 2 network connections for at least `500`
7028* ms.
7029*/
7030| 'networkidle2';
7031
7032/**
7033 * Extends the main {@link Puppeteer} class with Node specific behaviour for
7034 * fetching and downloading browsers.
7035 *
7036 * If you're using Puppeteer in a Node environment, this is the class you'll get
7037 * when you run `require('puppeteer')` (or the equivalent ES `import`).
7038 *
7039 * @remarks
7040 * The most common method to use is {@link PuppeteerNode.launch | launch}, which
7041 * is used to launch and connect to a new browser instance.
7042 *
7043 * See {@link Puppeteer | the main Puppeteer class} for methods common to all
7044 * environments, such as {@link Puppeteer.connect}.
7045 *
7046 * @example
7047 * The following is a typical example of using Puppeteer to drive automation:
7048 *
7049 * ```ts
7050 * import puppeteer from 'puppeteer';
7051 *
7052 * (async () => {
7053 * const browser = await puppeteer.launch();
7054 * const page = await browser.newPage();
7055 * await page.goto('https://www.google.com');
7056 * // other actions...
7057 * await browser.close();
7058 * })();
7059 * ```
7060 *
7061 * Once you have created a `page` you have access to a large API to interact
7062 * with the page, navigate, or find certain elements in that page.
7063 * The {@link Page | `page` documentation} lists all the available methods.
7064 *
7065 * @public
7066 */
7067export declare class PuppeteerNode extends Puppeteer {
7068 #private;
7069
7070
7071
7072 /**
7073 * This method attaches Puppeteer to an existing browser instance.
7074 *
7075 * @param options - Set of configurable options to set on the browser.
7076 * @returns Promise which resolves to browser instance.
7077 */
7078 connect(options: ConnectOptions): Promise<Browser>;
7079 /**
7080 * Launches a browser instance with given arguments and options when
7081 * specified.
7082 *
7083 * When using with `puppeteer-core`,
7084 * {@link LaunchOptions.executablePath | options.executablePath} or
7085 * {@link LaunchOptions.channel | options.channel} must be provided.
7086 *
7087 * @example
7088 * You can use {@link LaunchOptions.ignoreDefaultArgs | options.ignoreDefaultArgs}
7089 * to filter out `--mute-audio` from default arguments:
7090 *
7091 * ```ts
7092 * const browser = await puppeteer.launch({
7093 * ignoreDefaultArgs: ['--mute-audio'],
7094 * });
7095 * ```
7096 *
7097 * @remarks
7098 * Puppeteer can also be used to control the Chrome browser, but it works best
7099 * with the version of Chrome for Testing downloaded by default.
7100 * There is no guarantee it will work with any other version. If Google Chrome
7101 * (rather than Chrome for Testing) is preferred, a
7102 * {@link https://www.google.com/chrome/browser/canary.html | Chrome Canary}
7103 * or
7104 * {@link https://www.chromium.org/getting-involved/dev-channel | Dev Channel}
7105 * build is suggested. See
7106 * {@link https://www.howtogeek.com/202825/what%E2%80%99s-the-difference-between-chromium-and-chrome/ | this article}
7107 * for a description of the differences between Chromium and Chrome.
7108 * {@link https://chromium.googlesource.com/chromium/src/+/lkgr/docs/chromium_browser_vs_google_chrome.md | This article}
7109 * describes some differences for Linux users. See
7110 * {@link https://developer.chrome.com/blog/chrome-for-testing/ | this doc} for the description
7111 * of Chrome for Testing.
7112 *
7113 * @param options - Options to configure launching behavior.
7114 */
7115 launch(options?: LaunchOptions): Promise<Browser>;
7116 /**
7117 * The default executable path for a given ChromeReleaseChannel.
7118 */
7119 executablePath(channel: ChromeReleaseChannel): string;
7120 /**
7121 * The default executable path given LaunchOptions.
7122 */
7123 executablePath(options: LaunchOptions): string;
7124 /**
7125 * The default executable path.
7126 */
7127 executablePath(): string;
7128
7129
7130 /**
7131 * The name of the browser that was last launched.
7132 */
7133 get lastLaunchedBrowser(): SupportedBrowser;
7134 /**
7135 * The name of the browser that will be launched by default. For
7136 * `puppeteer`, this is influenced by your configuration. Otherwise, it's
7137 * `chrome`.
7138 */
7139 get defaultBrowser(): SupportedBrowser;
7140 /**
7141 * @deprecated Do not use as this field as it does not take into account
7142 * multiple browsers of different types. Use
7143 * {@link PuppeteerNode.defaultBrowser | defaultBrowser} or
7144 * {@link PuppeteerNode.lastLaunchedBrowser | lastLaunchedBrowser}.
7145 *
7146 * @returns The name of the browser that is under automation.
7147 */
7148 get product(): string;
7149 /**
7150 * @param options - Set of configurable options to set on the browser.
7151 *
7152 * @returns The default arguments that the browser will be launched with.
7153 */
7154 defaultArgs(options?: LaunchOptions): string[];
7155 /**
7156 * Removes all non-current Firefox and Chrome binaries in the cache directory
7157 * identified by the provided Puppeteer configuration. The current browser
7158 * version is determined by resolving PUPPETEER_REVISIONS from Puppeteer
7159 * unless `configuration.browserRevision` is provided.
7160 *
7161 * @remarks
7162 *
7163 * Note that the method does not check if any other Puppeteer versions
7164 * installed on the host that use the same cache directory require the
7165 * non-current binaries.
7166 *
7167 * @public
7168 */
7169 trimCache(): Promise<void>;
7170}
7171
7172/**
7173 * @public
7174 */
7175export declare type Quad = [Point, Point, Point, Point];
7176
7177/**
7178 * @public
7179 */
7180export declare interface QueryOptions {
7181 /**
7182 * Whether to run the query in isolation. When returning many elements
7183 * from {@link Page.$$} or similar methods, it might be useful to turn
7184 * off the isolation to improve performance. By default, the querying
7185 * code will be executed in a separate sandbox realm.
7186 *
7187 * @defaultValue `true`
7188 */
7189 isolate: boolean;
7190}
7191
7192/**
7193 * @public
7194 */
7195export declare interface RemoteAddress {
7196 ip?: string;
7197 port?: number;
7198}
7199
7200/**
7201 * Resource types for HTTPRequests as perceived by the rendering engine.
7202 *
7203 * @public
7204 */
7205export declare type ResourceType = Lowercase<Protocol.Network.ResourceType>;
7206
7207/**
7208 * Required response data to fulfill a request with.
7209 *
7210 * @public
7211 */
7212export declare interface ResponseForRequest {
7213 status: number;
7214 /**
7215 * Optional response headers.
7216 *
7217 * The record values will be converted to string following:
7218 * Arrays' values will be mapped to String
7219 * (Used when you need multiple headers with the same name).
7220 * Non-arrays will be converted to String.
7221 */
7222 headers: Record<string, string | string[] | unknown>;
7223 contentType: string;
7224 body: string | Uint8Array;
7225}
7226
7227/**
7228 * @public
7229 * @experimental
7230 */
7231export declare interface ScreencastOptions {
7232 /**
7233 * File path to save the screencast to.
7234 */
7235 path?: `${string}.webm`;
7236 /**
7237 * Specifies the region of the viewport to crop.
7238 */
7239 crop?: BoundingBox;
7240 /**
7241 * Scales the output video.
7242 *
7243 * For example, `0.5` will shrink the width and height of the output video by
7244 * half. `2` will double the width and height of the output video.
7245 *
7246 * @defaultValue `1`
7247 */
7248 scale?: number;
7249 /**
7250 * Specifies the speed to record at.
7251 *
7252 * For example, `0.5` will slowdown the output video by 50%. `2` will double the
7253 * speed of the output video.
7254 *
7255 * @defaultValue `1`
7256 */
7257 speed?: number;
7258 /**
7259 * Path to the {@link https://ffmpeg.org/ | ffmpeg}.
7260 *
7261 * Required if `ffmpeg` is not in your PATH.
7262 */
7263 ffmpegPath?: string;
7264}
7265
7266/**
7267 * @public
7268 */
7269export declare class ScreenRecorder extends PassThrough {
7270 #private;
7271
7272 /**
7273 * Stops the recorder.
7274 *
7275 * @public
7276 */
7277 stop(): Promise<void>;
7278
7279}
7280
7281/**
7282 * @public
7283 */
7284export declare interface ScreenshotClip extends BoundingBox {
7285 /**
7286 * @defaultValue `1`
7287 */
7288 scale?: number;
7289}
7290
7291/**
7292 * @public
7293 */
7294export declare interface ScreenshotOptions {
7295 /**
7296 * @defaultValue `false`
7297 */
7298 optimizeForSpeed?: boolean;
7299 /**
7300 * @defaultValue `'png'`
7301 */
7302 type?: 'png' | 'jpeg' | 'webp';
7303 /**
7304 * Quality of the image, between 0-100. Not applicable to `png` images.
7305 */
7306 quality?: number;
7307 /**
7308 * Capture the screenshot from the surface, rather than the view.
7309 *
7310 * @defaultValue `true`
7311 */
7312 fromSurface?: boolean;
7313 /**
7314 * When `true`, takes a screenshot of the full page.
7315 *
7316 * @defaultValue `false`
7317 */
7318 fullPage?: boolean;
7319 /**
7320 * Hides default white background and allows capturing screenshots with transparency.
7321 *
7322 * @defaultValue `false`
7323 */
7324 omitBackground?: boolean;
7325 /**
7326 * The file path to save the image to. The screenshot type will be inferred
7327 * from file extension. If path is a relative path, then it is resolved
7328 * relative to current working directory. If no path is provided, the image
7329 * won't be saved to the disk.
7330 */
7331 path?: string;
7332 /**
7333 * Specifies the region of the page/element to clip.
7334 */
7335 clip?: ScreenshotClip;
7336 /**
7337 * Encoding of the image.
7338 *
7339 * @defaultValue `'binary'`
7340 */
7341 encoding?: 'base64' | 'binary';
7342 /**
7343 * Capture the screenshot beyond the viewport.
7344 *
7345 * @defaultValue `false` if there is no `clip`. `true` otherwise.
7346 */
7347 captureBeyondViewport?: boolean;
7348}
7349
7350/**
7351 * The SecurityDetails class represents the security details of a
7352 * response that was received over a secure connection.
7353 *
7354 * @public
7355 */
7356export declare class SecurityDetails {
7357 #private;
7358
7359 /**
7360 * The name of the issuer of the certificate.
7361 */
7362 issuer(): string;
7363 /**
7364 * {@link https://en.wikipedia.org/wiki/Unix_time | Unix timestamp}
7365 * marking the start of the certificate's validity.
7366 */
7367 validFrom(): number;
7368 /**
7369 * {@link https://en.wikipedia.org/wiki/Unix_time | Unix timestamp}
7370 * marking the end of the certificate's validity.
7371 */
7372 validTo(): number;
7373 /**
7374 * The security protocol being used, e.g. "TLS 1.2".
7375 */
7376 protocol(): string;
7377 /**
7378 * The name of the subject to which the certificate was issued.
7379 */
7380 subjectName(): string;
7381 /**
7382 * The list of {@link https://en.wikipedia.org/wiki/Subject_Alternative_Name | subject alternative names (SANs)} of the certificate.
7383 */
7384 subjectAlternativeNames(): string[];
7385}
7386
7387/**
7388 * Represents a Node and the properties of it that are relevant to Accessibility.
7389 * @public
7390 */
7391export declare interface SerializedAXNode {
7392 /**
7393 * The {@link https://www.w3.org/TR/wai-aria/#usage_intro | role} of the node.
7394 */
7395 role: string;
7396 /**
7397 * A human readable name for the node.
7398 */
7399 name?: string;
7400 /**
7401 * The current value of the node.
7402 */
7403 value?: string | number;
7404 /**
7405 * An additional human readable description of the node.
7406 */
7407 description?: string;
7408 /**
7409 * Any keyboard shortcuts associated with this node.
7410 */
7411 keyshortcuts?: string;
7412 /**
7413 * A human readable alternative to the role.
7414 */
7415 roledescription?: string;
7416 /**
7417 * A description of the current value.
7418 */
7419 valuetext?: string;
7420 disabled?: boolean;
7421 expanded?: boolean;
7422 focused?: boolean;
7423 modal?: boolean;
7424 multiline?: boolean;
7425 /**
7426 * Whether more than one child can be selected.
7427 */
7428 multiselectable?: boolean;
7429 readonly?: boolean;
7430 required?: boolean;
7431 selected?: boolean;
7432 /**
7433 * Whether the checkbox is checked, or in a
7434 * {@link https://www.w3.org/TR/wai-aria-practices/examples/checkbox/checkbox-2/checkbox-2.html | mixed state}.
7435 */
7436 checked?: boolean | 'mixed';
7437 /**
7438 * Whether the node is checked or in a mixed state.
7439 */
7440 pressed?: boolean | 'mixed';
7441 /**
7442 * The level of a heading.
7443 */
7444 level?: number;
7445 valuemin?: number;
7446 valuemax?: number;
7447 autocomplete?: string;
7448 haspopup?: string;
7449 /**
7450 * Whether and in what way this node's value is invalid.
7451 */
7452 invalid?: string;
7453 orientation?: string;
7454 /**
7455 * Children of this node, if there are any.
7456 */
7457 children?: SerializedAXNode[];
7458 /**
7459 * Get an ElementHandle for this AXNode if available.
7460 *
7461 * If the underlying DOM element has been disposed, the method might return an
7462 * error.
7463 */
7464 elementHandle(): Promise<ElementHandle | null>;
7465}
7466
7467export { Session }
7468
7469/**
7470 * @public
7471 */
7472export declare interface SnapshotOptions {
7473 /**
7474 * Prune uninteresting nodes from the tree.
7475 * @defaultValue `true`
7476 */
7477 interestingOnly?: boolean;
7478 /**
7479 * If true, gets accessibility trees for each of the iframes in the frame
7480 * subtree.
7481 *
7482 * @defaultValue `false`
7483 */
7484 includeIframes?: boolean;
7485 /**
7486 * Root node to get the accessibility tree for
7487 * @defaultValue The root node of the entire page.
7488 */
7489 root?: ElementHandle<Node>;
7490}
7491
7492/**
7493 * @license
7494 * Copyright 2020 Google Inc.
7495 * SPDX-License-Identifier: Apache-2.0
7496 */
7497/**
7498 * Browsers supported by Puppeteer.
7499 *
7500 * @public
7501 */
7502export declare type SupportedBrowser = 'chrome' | 'firefox';
7503
7504/**
7505 * WebDriver BiDi capabilities that are not set by Puppeteer itself.
7506 *
7507 * @public
7508 */
7509export declare interface SupportedWebDriverCapabilities {
7510 firstMatch?: SupportedWebDriverCapability[];
7511 alwaysMatch?: SupportedWebDriverCapability;
7512}
7513
7514/**
7515 * @public
7516 */
7517export declare type SupportedWebDriverCapability = Exclude<Session.CapabilityRequest, 'unhandledPromptBehavior' | 'acceptInsecureCerts'>;
7518
7519/**
7520 * Target represents a
7521 * {@link https://chromedevtools.github.io/devtools-protocol/tot/Target/ | CDP target}.
7522 * In CDP a target is something that can be debugged such a frame, a page or a
7523 * worker.
7524 * @public
7525 */
7526export declare abstract class Target {
7527
7528 /**
7529 * If the target is not of type `"service_worker"` or `"shared_worker"`, returns `null`.
7530 */
7531 worker(): Promise<WebWorker | null>;
7532 /**
7533 * If the target is not of type `"page"`, `"webview"` or `"background_page"`,
7534 * returns `null`.
7535 */
7536 page(): Promise<Page | null>;
7537 /**
7538 * Forcefully creates a page for a target of any type. It is useful if you
7539 * want to handle a CDP target of type `other` as a page. If you deal with a
7540 * regular page target, use {@link Target.page}.
7541 */
7542 abstract asPage(): Promise<Page>;
7543 abstract url(): string;
7544 /**
7545 * Creates a Chrome Devtools Protocol session attached to the target.
7546 */
7547 abstract createCDPSession(): Promise<CDPSession>;
7548 /**
7549 * Identifies what kind of target this is.
7550 *
7551 * @remarks
7552 *
7553 * See {@link https://developer.chrome.com/extensions/background_pages | docs} for more info about background pages.
7554 */
7555 abstract type(): TargetType;
7556 /**
7557 * Get the browser the target belongs to.
7558 */
7559 abstract browser(): Browser;
7560 /**
7561 * Get the browser context the target belongs to.
7562 */
7563 abstract browserContext(): BrowserContext;
7564 /**
7565 * Get the target that opened this target. Top-level targets return `null`.
7566 */
7567 abstract opener(): Target | undefined;
7568}
7569
7570/**
7571 * @public
7572 */
7573export declare type TargetFilterCallback = (target: Target) => boolean;
7574
7575/**
7576 * @public
7577 */
7578export declare enum TargetType {
7579 PAGE = "page",
7580 BACKGROUND_PAGE = "background_page",
7581 SERVICE_WORKER = "service_worker",
7582 SHARED_WORKER = "shared_worker",
7583 BROWSER = "browser",
7584 WEBVIEW = "webview",
7585 OTHER = "other",
7586
7587}
7588
7589/**
7590 * TimeoutError is emitted whenever certain operations are terminated due to
7591 * timeout.
7592 *
7593 * @remarks
7594 * Example operations are {@link Page.waitForSelector | page.waitForSelector} or
7595 * {@link PuppeteerNode.launch | puppeteer.launch}.
7596 *
7597 * @public
7598 */
7599export declare class TimeoutError extends PuppeteerError {
7600}
7601
7602/**
7603 * TouchError is thrown when an attempt is made to move or end a touch that does
7604 * not exist.
7605 * @public
7606 */
7607export declare class TouchError extends PuppeteerError {
7608}
7609
7610/**
7611 * The TouchHandle interface exposes methods to manipulate touches that have been started
7612 * @public
7613 */
7614export declare interface TouchHandle {
7615 /**
7616 * Dispatches a `touchMove` event for this touch.
7617 * @param x - Horizontal position of the move.
7618 * @param y - Vertical position of the move.
7619 */
7620 move(x: number, y: number): Promise<void>;
7621 /**
7622 * Dispatches a `touchend` event for this touch.
7623 */
7624 end(): Promise<void>;
7625}
7626
7627/**
7628 * The Touchscreen class exposes touchscreen events.
7629 * @public
7630 */
7631export declare abstract class Touchscreen {
7632
7633
7634
7635
7636 /**
7637 * Dispatches a `touchstart` and `touchend` event.
7638 * @param x - Horizontal position of the tap.
7639 * @param y - Vertical position of the tap.
7640 */
7641 tap(x: number, y: number): Promise<void>;
7642 /**
7643 * Dispatches a `touchstart` event.
7644 * @param x - Horizontal position of the tap.
7645 * @param y - Vertical position of the tap.
7646 * @returns A handle for the touch that was started.
7647 */
7648 abstract touchStart(x: number, y: number): Promise<TouchHandle>;
7649 /**
7650 * Dispatches a `touchMove` event on the first touch that is active.
7651 * @param x - Horizontal position of the move.
7652 * @param y - Vertical position of the move.
7653 *
7654 * @remarks
7655 *
7656 * Not every `touchMove` call results in a `touchmove` event being emitted,
7657 * depending on the browser's optimizations. For example, Chrome
7658 * {@link https://developer.chrome.com/blog/a-more-compatible-smoother-touch/#chromes-new-model-the-throttled-async-touchmove-model | throttles}
7659 * touch move events.
7660 */
7661 touchMove(x: number, y: number): Promise<void>;
7662 /**
7663 * Dispatches a `touchend` event on the first touch that is active.
7664 */
7665 touchEnd(): Promise<void>;
7666}
7667
7668/**
7669 * The Tracing class exposes the tracing audit interface.
7670 * @remarks
7671 * You can use `tracing.start` and `tracing.stop` to create a trace file
7672 * which can be opened in Chrome DevTools or {@link https://chromedevtools.github.io/timeline-viewer/ | timeline viewer}.
7673 *
7674 * @example
7675 *
7676 * ```ts
7677 * await page.tracing.start({path: 'trace.json'});
7678 * await page.goto('https://www.google.com');
7679 * await page.tracing.stop();
7680 * ```
7681 *
7682 * @public
7683 */
7684export declare class Tracing {
7685 #private;
7686
7687
7688 /**
7689 * Starts a trace for the current page.
7690 * @remarks
7691 * Only one trace can be active at a time per browser.
7692 *
7693 * @param options - Optional `TracingOptions`.
7694 */
7695 start(options?: TracingOptions): Promise<void>;
7696 /**
7697 * Stops a trace started with the `start` method.
7698 * @returns Promise which resolves to buffer with trace data.
7699 */
7700 stop(): Promise<Uint8Array | undefined>;
7701}
7702
7703/**
7704 * @public
7705 */
7706export declare interface TracingOptions {
7707 path?: string;
7708 screenshots?: boolean;
7709 categories?: string[];
7710}
7711
7712/**
7713 * Puppeteer will throw this error if a method is not
7714 * supported by the currently used protocol
7715 *
7716 * @public
7717 */
7718export declare class UnsupportedOperation extends PuppeteerError {
7719}
7720
7721/**
7722 * @license
7723 * Copyright 2020 Google Inc.
7724 * SPDX-License-Identifier: Apache-2.0
7725 */
7726/**
7727 * @public
7728 */
7729export declare interface Viewport {
7730 /**
7731 * The page width in CSS pixels.
7732 *
7733 * @remarks
7734 * Setting this value to `0` will reset this value to the system default.
7735 */
7736 width: number;
7737 /**
7738 * The page height in CSS pixels.
7739 *
7740 * @remarks
7741 * Setting this value to `0` will reset this value to the system default.
7742 */
7743 height: number;
7744 /**
7745 * Specify device scale factor.
7746 * See {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio | devicePixelRatio} for more info.
7747 *
7748 * @remarks
7749 * Setting this value to `0` will reset this value to the system default.
7750 *
7751 * @defaultValue `1`
7752 */
7753 deviceScaleFactor?: number;
7754 /**
7755 * Whether the `meta viewport` tag is taken into account.
7756 * @defaultValue `false`
7757 */
7758 isMobile?: boolean;
7759 /**
7760 * Specifies if the viewport is in landscape mode.
7761 * @defaultValue `false`
7762 */
7763 isLandscape?: boolean;
7764 /**
7765 * Specify if the viewport supports touch events.
7766 * @defaultValue `false`
7767 */
7768 hasTouch?: boolean;
7769}
7770
7771/**
7772 * Whether to wait for the element to be
7773 * {@link ElementHandle.isVisible | visible} or
7774 * {@link ElementHandle.isHidden | hidden}.
7775 * `null` to disable visibility checks.
7776 *
7777 * @public
7778 */
7779export declare type VisibilityOption = 'hidden' | 'visible' | null;
7780
7781/**
7782 * @public
7783 */
7784export declare interface WaitForNetworkIdleOptions extends WaitTimeoutOptions {
7785 /**
7786 * Time (in milliseconds) the network should be idle.
7787 *
7788 * @defaultValue `500`
7789 */
7790 idleTime?: number;
7791 /**
7792 * Maximum number concurrent of network connections to be considered inactive.
7793 *
7794 * @defaultValue `0`
7795 */
7796 concurrency?: number;
7797}
7798
7799/**
7800 * @public
7801 */
7802export declare interface WaitForOptions {
7803 /**
7804 * Maximum wait time in milliseconds. Pass 0 to disable the timeout.
7805 *
7806 * The default value can be changed by using the
7807 * {@link Page.setDefaultTimeout} or {@link Page.setDefaultNavigationTimeout}
7808 * methods.
7809 *
7810 * @defaultValue `30000`
7811 */
7812 timeout?: number;
7813 /**
7814 * When to consider waiting succeeds. Given an array of event strings, waiting
7815 * is considered to be successful after all events have been fired.
7816 *
7817 * @defaultValue `'load'`
7818 */
7819 waitUntil?: PuppeteerLifeCycleEvent | PuppeteerLifeCycleEvent[];
7820
7821 /**
7822 * A signal object that allows you to cancel the call.
7823 */
7824 signal?: AbortSignal;
7825}
7826
7827/**
7828 * @public
7829 */
7830export declare interface WaitForSelectorOptions {
7831 /**
7832 * Wait for the selected element to be present in DOM and to be visible. See
7833 * {@link ElementHandle.isVisible} for the definition of element visibility.
7834 *
7835 * @defaultValue `false`
7836 */
7837 visible?: boolean;
7838 /**
7839 * Wait for the selected element to not be found in the DOM or to be hidden.
7840 * See {@link ElementHandle.isHidden} for the definition of element
7841 * invisibility.
7842 *
7843 * @defaultValue `false`
7844 */
7845 hidden?: boolean;
7846 /**
7847 * Maximum time to wait in milliseconds. Pass `0` to disable timeout.
7848 *
7849 * The default value can be changed by using {@link Page.setDefaultTimeout}
7850 *
7851 * @defaultValue `30_000` (30 seconds)
7852 */
7853 timeout?: number;
7854 /**
7855 * A signal object that allows you to cancel a waitForSelector call.
7856 */
7857 signal?: AbortSignal;
7858}
7859
7860/**
7861 * @public
7862 */
7863export declare interface WaitForTargetOptions {
7864 /**
7865 * Maximum wait time in milliseconds. Pass `0` to disable the timeout.
7866 *
7867 * @defaultValue `30_000`
7868 */
7869 timeout?: number;
7870 /**
7871 * A signal object that allows you to cancel a waitFor call.
7872 */
7873 signal?: AbortSignal;
7874}
7875
7876/**
7877 * @public
7878 */
7879export declare interface WaitTimeoutOptions {
7880 /**
7881 * Maximum wait time in milliseconds. Pass 0 to disable the timeout.
7882 *
7883 * The default value can be changed by using the
7884 * {@link Page.setDefaultTimeout} method.
7885 *
7886 * @defaultValue `30_000`
7887 */
7888 timeout?: number;
7889 /**
7890 * A signal object that allows you to cancel a waitFor call.
7891 */
7892 signal?: AbortSignal;
7893}
7894
7895/**
7896 * This class represents a
7897 * {@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API | WebWorker}.
7898 *
7899 * @remarks
7900 * The events `workercreated` and `workerdestroyed` are emitted on the page
7901 * object to signal the worker lifecycle.
7902 *
7903 * @example
7904 *
7905 * ```ts
7906 * page.on('workercreated', worker =>
7907 * console.log('Worker created: ' + worker.url()),
7908 * );
7909 * page.on('workerdestroyed', worker =>
7910 * console.log('Worker destroyed: ' + worker.url()),
7911 * );
7912 *
7913 * console.log('Current workers:');
7914 * for (const worker of page.workers()) {
7915 * console.log(' ' + worker.url());
7916 * }
7917 * ```
7918 *
7919 * @public
7920 */
7921export declare abstract class WebWorker extends EventEmitter<Record<EventType, unknown>> {
7922 #private;
7923
7924
7925
7926 /**
7927 * The URL of this web worker.
7928 */
7929 url(): string;
7930 /**
7931 * The CDP session client the WebWorker belongs to.
7932 */
7933 abstract get client(): CDPSession;
7934 /**
7935 * Evaluates a given function in the {@link WebWorker | worker}.
7936 *
7937 * @remarks If the given function returns a promise,
7938 * {@link WebWorker.evaluate | evaluate} will wait for the promise to resolve.
7939 *
7940 * As a rule of thumb, if the return value of the given function is more
7941 * complicated than a JSON object (e.g. most classes), then
7942 * {@link WebWorker.evaluate | evaluate} will _likely_ return some truncated
7943 * value (or `{}`). This is because we are not returning the actual return
7944 * value, but a deserialized version as a result of transferring the return
7945 * value through a protocol to Puppeteer.
7946 *
7947 * In general, you should use
7948 * {@link WebWorker.evaluateHandle | evaluateHandle} if
7949 * {@link WebWorker.evaluate | evaluate} cannot serialize the return value
7950 * properly or you need a mutable {@link JSHandle | handle} to the return
7951 * object.
7952 *
7953 * @param func - Function to be evaluated.
7954 * @param args - Arguments to pass into `func`.
7955 * @returns The result of `func`.
7956 */
7957 evaluate<Params extends unknown[], Func extends EvaluateFunc<Params> = EvaluateFunc<Params>>(func: Func | string, ...args: Params): Promise<Awaited<ReturnType<Func>>>;
7958 /**
7959 * Evaluates a given function in the {@link WebWorker | worker}.
7960 *
7961 * @remarks If the given function returns a promise,
7962 * {@link WebWorker.evaluate | evaluate} will wait for the promise to resolve.
7963 *
7964 * In general, you should use
7965 * {@link WebWorker.evaluateHandle | evaluateHandle} if
7966 * {@link WebWorker.evaluate | evaluate} cannot serialize the return value
7967 * properly or you need a mutable {@link JSHandle | handle} to the return
7968 * object.
7969 *
7970 * @param func - Function to be evaluated.
7971 * @param args - Arguments to pass into `func`.
7972 * @returns A {@link JSHandle | handle} to the return value of `func`.
7973 */
7974 evaluateHandle<Params extends unknown[], Func extends EvaluateFunc<Params> = EvaluateFunc<Params>>(func: Func | string, ...args: Params): Promise<HandleFor<Awaited<ReturnType<Func>>>>;
7975 close(): Promise<void>;
7976}
7977
7978export { }
7979
\No newline at end of file