UNPKG

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