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