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