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