1/** 2 * Copyright 2017 Google Inc. All rights reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16/// <reference types="node" /> 17import { EventEmitter } from './EventEmitter.js'; 18import { CDPSession } from './Connection.js'; 19import { Frame } from './FrameManager.js'; 20import { Keyboard, Mouse, Touchscreen, MouseButton } from './Input.js'; 21import { Tracing } from './Tracing.js'; 22import { Coverage } from './Coverage.js'; 23import { WebWorker } from './WebWorker.js'; 24import { Browser, BrowserContext } from './Browser.js'; 25import { Target } from './Target.js'; 26import { JSHandle, ElementHandle } from './JSHandle.js'; 27import { Viewport } from './PuppeteerViewport.js'; 28import { Credentials } from './NetworkManager.js'; 29import { HTTPRequest } from './HTTPRequest.js'; 30import { HTTPResponse } from './HTTPResponse.js'; 31import { Accessibility } from './Accessibility.js'; 32import { FileChooser } from './FileChooser.js'; 33import { PuppeteerLifeCycleEvent } from './LifecycleWatcher.js'; 34import { Protocol } from 'devtools-protocol'; 35import { SerializableOrJSHandle, EvaluateHandleFn, WrapElementHandle, EvaluateFn, EvaluateFnReturnType, UnwrapPromiseLike } from './EvalTypes.js'; 36import { PDFOptions } from './PDFOptions.js'; 37/** 38 * @public 39 */ 40export interface Metrics { 41 Timestamp?: number; 42 Documents?: number; 43 Frames?: number; 44 JSEventListeners?: number; 45 Nodes?: number; 46 LayoutCount?: number; 47 RecalcStyleCount?: number; 48 LayoutDuration?: number; 49 RecalcStyleDuration?: number; 50 ScriptDuration?: number; 51 TaskDuration?: number; 52 JSHeapUsedSize?: number; 53 JSHeapTotalSize?: number; 54} 55/** 56 * @public 57 */ 58export interface WaitTimeoutOptions { 59 /** 60 * Maximum wait time in milliseconds, defaults to 30 seconds, pass `0` to 61 * disable the timeout. 62 * 63 * @remarks 64 * The default value can be changed by using the 65 * {@link Page.setDefaultTimeout} method. 66 */ 67 timeout?: number; 68} 69/** 70 * @public 71 */ 72export interface WaitForOptions { 73 /** 74 * Maximum wait time in milliseconds, defaults to 30 seconds, pass `0` to 75 * disable the timeout. 76 * 77 * @remarks 78 * The default value can be changed by using the 79 * {@link Page.setDefaultTimeout} or {@link Page.setDefaultNavigationTimeout} 80 * methods. 81 */ 82 timeout?: number; 83 waitUntil?: PuppeteerLifeCycleEvent | PuppeteerLifeCycleEvent[]; 84} 85/** 86 * @public 87 */ 88export interface GeolocationOptions { 89 /** 90 * Latitude between -90 and 90. 91 */ 92 longitude: number; 93 /** 94 * Longitude between -180 and 180. 95 */ 96 latitude: number; 97 /** 98 * Optional non-negative accuracy value. 99 */ 100 accuracy?: number; 101} 102interface MediaFeature { 103 name: string; 104 value: string; 105} 106interface ScreenshotClip { 107 x: number; 108 y: number; 109 width: number; 110 height: number; 111} 112interface ScreenshotOptions { 113 type?: 'png' | 'jpeg'; 114 path?: string; 115 fullPage?: boolean; 116 clip?: ScreenshotClip; 117 quality?: number; 118 omitBackground?: boolean; 119 encoding?: string; 120} 121/** 122 * All the events that a page instance may emit. 123 * 124 * @public 125 */ 126export declare const enum PageEmittedEvents { 127 /** Emitted when the page closes. */ 128 Close = "close", 129 /** 130 * Emitted when JavaScript within the page calls one of console API methods, 131 * e.g. `console.log` or `console.dir`. Also emitted if the page throws an 132 * error or a warning. 133 * 134 * @remarks 135 * 136 * A `console` event provides a {@link ConsoleMessage} representing the 137 * console message that was logged. 138 * 139 * @example 140 * An example of handling `console` event: 141 * ```js 142 * page.on('console', msg => { 143 * for (let i = 0; i < msg.args().length; ++i) 144 * console.log(`${i}: ${msg.args()[i]}`); 145 * }); 146 * page.evaluate(() => console.log('hello', 5, {foo: 'bar'})); 147 * ``` 148 */ 149 Console = "console", 150 /** 151 * Emitted when a JavaScript dialog appears, such as `alert`, `prompt`, 152 * `confirm` or `beforeunload`. Puppeteer can respond to the dialog via 153 * {@link Dialog.accept} or {@link Dialog.dismiss}. 154 */ 155 Dialog = "dialog", 156 /** 157 * Emitted when the JavaScript 158 * {@link https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded | DOMContentLoaded } event is dispatched. 159 */ 160 DOMContentLoaded = "domcontentloaded", 161 /** 162 * Emitted when the page crashes. Will contain an `Error`. 163 */ 164 Error = "error", 165 /** Emitted when a frame is attached. Will contain a {@link Frame}. */ 166 FrameAttached = "frameattached", 167 /** Emitted when a frame is detached. Will contain a {@link Frame}. */ 168 FrameDetached = "framedetached", 169 /** Emitted when a frame is navigated to a new URL. Will contain a {@link Frame}. */ 170 FrameNavigated = "framenavigated", 171 /** 172 * Emitted when the JavaScript 173 * {@link https://developer.mozilla.org/en-US/docs/Web/Events/load | load} 174 * event is dispatched. 175 */ 176 Load = "load", 177 /** 178 * Emitted when the JavaScript code makes a call to `console.timeStamp`. For 179 * the list of metrics see {@link Page.metrics | page.metrics}. 180 * 181 * @remarks 182 * Contains an object with two properties: 183 * - `title`: the title passed to `console.timeStamp` 184 * - `metrics`: objec containing metrics as key/value pairs. The values will 185 * be `number`s. 186 */ 187 Metrics = "metrics", 188 /** 189 * Emitted when an uncaught exception happens within the page. 190 * Contains an `Error`. 191 */ 192 PageError = "pageerror", 193 /** 194 * Emitted when the page opens a new tab or window. 195 * 196 * Contains a {@link Page} corresponding to the popup window. 197 * 198 * @example 199 * 200 * ```js 201 * const [popup] = await Promise.all([ 202 * new Promise(resolve => page.once('popup', resolve)), 203 * page.click('a[target=_blank]'), 204 * ]); 205 * ``` 206 * 207 * ```js 208 * const [popup] = await Promise.all([ 209 * new Promise(resolve => page.once('popup', resolve)), 210 * page.evaluate(() => window.open('https://example.com')), 211 * ]); 212 * ``` 213 */ 214 Popup = "popup", 215 /** 216 * Emitted when a page issues a request and contains a {@link HTTPRequest}. 217 * 218 * @remarks 219 * The object is readonly. See {@Page.setRequestInterception} for intercepting 220 * and mutating requests. 221 */ 222 Request = "request", 223 /** 224 * Emitted when a request fails, for example by timing out. 225 * 226 * Contains a {@link HTTPRequest}. 227 * 228 * @remarks 229 * 230 * NOTE: HTTP Error responses, such as 404 or 503, are still successful 231 * responses from HTTP standpoint, so request will complete with 232 * `requestfinished` event and not with `requestfailed`. 233 */ 234 RequestFailed = "requestfailed", 235 /** 236 * Emitted when a request finishes successfully. Contains a {@link HTTPRequest}. 237 */ 238 RequestFinished = "requestfinished", 239 /** 240 * Emitted when a response is received. Contains a {@link HTTPResponse}. 241 */ 242 Response = "response", 243 /** 244 * Emitted when a dedicated 245 * {@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API | WebWorker} 246 * is spawned by the page. 247 */ 248 WorkerCreated = "workercreated", 249 /** 250 * Emitted when a dedicated 251 * {@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API | WebWorker} 252 * is destroyed by the page. 253 */ 254 WorkerDestroyed = "workerdestroyed" 255} 256/** 257 * Page provides methods to interact with a single tab or 258 * {@link https://developer.chrome.com/extensions/background_pages | extension background page} in Chromium. 259 * 260 * @remarks 261 * 262 * One Browser instance might have multiple Page instances. 263 * 264 * @example 265 * This example creates a page, navigates it to a URL, and then * saves a screenshot: 266 * ```js 267 * const puppeteer = require('puppeteer'); 268 * 269 * (async () => { 270 * const browser = await puppeteer.launch(); 271 * const page = await browser.newPage(); 272 * await page.goto('https://example.com'); 273 * await page.screenshot({path: 'screenshot.png'}); 274 * await browser.close(); 275 * })(); 276 * ``` 277 * 278 * The Page class extends from Puppeteer's {@link EventEmitter} class and will 279 * emit various events which are documented in the {@link PageEmittedEvents} enum. 280 * 281 * @example 282 * This example logs a message for a single page `load` event: 283 * ```js 284 * page.once('load', () => console.log('Page loaded!')); 285 * ``` 286 * 287 * To unsubscribe from events use the `off` method: 288 * 289 * ```js 290 * function logRequest(interceptedRequest) { 291 * console.log('A request was made:', interceptedRequest.url()); 292 * } 293 * page.on('request', logRequest); 294 * // Sometime later... 295 * page.off('request', logRequest); 296 * ``` 297 * @public 298 */ 299export declare class Page extends EventEmitter { 300 /** 301 * @internal 302 */ 303 static create(client: CDPSession, target: Target, ignoreHTTPSErrors: boolean, defaultViewport: Viewport | null): Promise<Page>; 304 private _closed; 305 private _client; 306 private _target; 307 private _keyboard; 308 private _mouse; 309 private _timeoutSettings; 310 private _touchscreen; 311 private _accessibility; 312 private _frameManager; 313 private _emulationManager; 314 private _tracing; 315 private _pageBindings; 316 private _coverage; 317 private _javascriptEnabled; 318 private _viewport; 319 private _screenshotTaskQueue; 320 private _workers; 321 private _fileChooserInterceptors; 322 private _disconnectPromise?; 323 /** 324 * @internal 325 */ 326 constructor(client: CDPSession, target: Target, ignoreHTTPSErrors: boolean); 327 private _initialize; 328 private _onFileChooser; 329 /** 330 * @returns `true` if the page has JavaScript enabled, `false` otherwise. 331 */ 332 isJavaScriptEnabled(): boolean; 333 /** 334 * @param options - Optional waiting parameters 335 * @returns Resolves after a page requests a file picker. 336 */ 337 waitForFileChooser(options?: WaitTimeoutOptions): Promise<FileChooser>; 338 /** 339 * Sets the page's geolocation. 340 * 341 * @remarks 342 * Consider using {@link BrowserContext.overridePermissions} to grant 343 * permissions for the page to read its geolocation. 344 * 345 * @example 346 * ```js 347 * await page.setGeolocation({latitude: 59.95, longitude: 30.31667}); 348 * ``` 349 */ 350 setGeolocation(options: GeolocationOptions): Promise<void>; 351 /** 352 * @returns A target this page was created from. 353 */ 354 target(): Target; 355 /** 356 * @returns The browser this page belongs to. 357 */ 358 browser(): Browser; 359 /** 360 * @returns The browser context that the page belongs to 361 */ 362 browserContext(): BrowserContext; 363 private _onTargetCrashed; 364 private _onLogEntryAdded; 365 /** 366 * @returns The page's main frame. 367 */ 368 mainFrame(): Frame; 369 get keyboard(): Keyboard; 370 get touchscreen(): Touchscreen; 371 get coverage(): Coverage; 372 get tracing(): Tracing; 373 get accessibility(): Accessibility; 374 /** 375 * @returns An array of all frames attached to the page. 376 */ 377 frames(): Frame[]; 378 /** 379 * @returns all of the dedicated 380 * {@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API | WebWorkers} 381 * associated with the page. 382 */ 383 workers(): WebWorker[]; 384 /** 385 * @param value - Whether to enable request interception. 386 * 387 * @remarks 388 * Activating request interception enables {@link HTTPRequest.abort}, 389 * {@link HTTPRequest.continue} and {@link HTTPRequest.respond} methods. This 390 * provides the capability to modify network requests that are made by a page. 391 * 392 * Once request interception is enabled, every request will stall unless it's 393 * continued, responded or aborted. 394 * 395 * **NOTE** Enabling request interception disables page caching. 396 * 397 * @example 398 * An example of a naïve request interceptor that aborts all image requests: 399 * ```js 400 * const puppeteer = require('puppeteer'); 401 * (async () => { 402 * const browser = await puppeteer.launch(); 403 * const page = await browser.newPage(); 404 * await page.setRequestInterception(true); 405 * page.on('request', interceptedRequest => { 406 * if (interceptedRequest.url().endsWith('.png') || 407 * interceptedRequest.url().endsWith('.jpg')) 408 * interceptedRequest.abort(); 409 * else 410 * interceptedRequest.continue(); 411 * }); 412 * await page.goto('https://example.com'); 413 * await browser.close(); 414 * })(); 415 * ``` 416 */ 417 setRequestInterception(value: boolean): Promise<void>; 418 /** 419 * @param enabled - When `true`, enables offline mode for the page. 420 */ 421 setOfflineMode(enabled: boolean): Promise<void>; 422 /** 423 * @param timeout - Maximum navigation time in milliseconds. 424 */ 425 setDefaultNavigationTimeout(timeout: number): void; 426 /** 427 * @param timeout - Maximum time in milliseconds. 428 */ 429 setDefaultTimeout(timeout: number): void; 430 /** 431 * Runs `document.querySelector` within the page. If no element matches the 432 * selector, the return value resolves to `null`. 433 * 434 * @remarks 435 * Shortcut for {@link Frame.$ | Page.mainFrame().$(selector) }. 436 * 437 * @param selector - A 438 * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors | selector} 439 * to query page for. 440 */ 441 $(selector: string): Promise<ElementHandle | null>; 442 /** 443 * @remarks 444 * 445 * The only difference between {@link Page.evaluate | page.evaluate} and 446 * `page.evaluateHandle` is that `evaluateHandle` will return the value 447 * wrapped in an in-page object. 448 * 449 * If the function passed to `page.evaluteHandle` returns a Promise, the 450 * function will wait for the promise to resolve and return its value. 451 * 452 * You can pass a string instead of a function (although functions are 453 * recommended as they are easier to debug and use with TypeScript): 454 * 455 * @example 456 * ``` 457 * const aHandle = await page.evaluateHandle('document') 458 * ``` 459 * 460 * @example 461 * {@link JSHandle} instances can be passed as arguments to the `pageFunction`: 462 * ``` 463 * const aHandle = await page.evaluateHandle(() => document.body); 464 * const resultHandle = await page.evaluateHandle(body => body.innerHTML, aHandle); 465 * console.log(await resultHandle.jsonValue()); 466 * await resultHandle.dispose(); 467 * ``` 468 * 469 * Most of the time this function returns a {@link JSHandle}, 470 * but if `pageFunction` returns a reference to an element, 471 * you instead get an {@link ElementHandle} back: 472 * 473 * @example 474 * ``` 475 * const button = await page.evaluateHandle(() => document.querySelector('button')); 476 * // can call `click` because `button` is an `ElementHandle` 477 * await button.click(); 478 * ``` 479 * 480 * The TypeScript definitions assume that `evaluateHandle` returns 481 * a `JSHandle`, but if you know it's going to return an 482 * `ElementHandle`, pass it as the generic argument: 483 * 484 * ``` 485 * const button = await page.evaluateHandle<ElementHandle>(...); 486 * ``` 487 * 488 * @param pageFunction - a function that is run within the page 489 * @param args - arguments to be passed to the pageFunction 490 */ 491 evaluateHandle<HandlerType extends JSHandle = JSHandle>(pageFunction: EvaluateHandleFn, ...args: SerializableOrJSHandle[]): Promise<HandlerType>; 492 /** 493 * This method iterates the JavaScript heap and finds all objects with the 494 * given prototype. 495 * 496 * @remarks 497 * 498 * @example 499 * 500 * ```js 501 * // Create a Map object 502 * await page.evaluate(() => window.map = new Map()); 503 * // Get a handle to the Map object prototype 504 * const mapPrototype = await page.evaluateHandle(() => Map.prototype); 505 * // Query all map instances into an array 506 * const mapInstances = await page.queryObjects(mapPrototype); 507 * // Count amount of map objects in heap 508 * const count = await page.evaluate(maps => maps.length, mapInstances); 509 * await mapInstances.dispose(); 510 * await mapPrototype.dispose(); 511 * ``` 512 * @param prototypeHandle - a handle to the object prototype. 513 */ 514 queryObjects(prototypeHandle: JSHandle): Promise<JSHandle>; 515 /** 516 * This method runs `document.querySelector` within the page and passes the 517 * result as the first argument to the `pageFunction`. 518 * 519 * @remarks 520 * 521 * If no element is found matching `selector`, the method will throw an error. 522 * 523 * If `pageFunction` returns a promise `$eval` will wait for the promise to 524 * resolve and then return its value. 525 * 526 * @example 527 * 528 * ``` 529 * const searchValue = await page.$eval('#search', el => el.value); 530 * const preloadHref = await page.$eval('link[rel=preload]', el => el.href); 531 * const html = await page.$eval('.main-container', el => el.outerHTML); 532 * ``` 533 * 534 * If you are using TypeScript, you may have to provide an explicit type to the 535 * first argument of the `pageFunction`. 536 * By default it is typed as `Element`, but you may need to provide a more 537 * specific sub-type: 538 * 539 * @example 540 * 541 * ``` 542 * // if you don't provide HTMLInputElement here, TS will error 543 * // as `value` is not on `Element` 544 * const searchValue = await page.$eval('#search', (el: HTMLInputElement) => el.value); 545 * ``` 546 * 547 * The compiler should be able to infer the return type 548 * from the `pageFunction` you provide. If it is unable to, you can use the generic 549 * type to tell the compiler what return type you expect from `$eval`: 550 * 551 * @example 552 * 553 * ``` 554 * // The compiler can infer the return type in this case, but if it can't 555 * // or if you want to be more explicit, provide it as the generic type. 556 * const searchValue = await page.$eval<string>( 557 * '#search', (el: HTMLInputElement) => el.value 558 * ); 559 * ``` 560 * 561 * @param selector - the 562 * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors | selector} 563 * to query for 564 * @param pageFunction - the function to be evaluated in the page context. 565 * Will be passed the result of `document.querySelector(selector)` as its 566 * first argument. 567 * @param args - any additional arguments to pass through to `pageFunction`. 568 * 569 * @returns The result of calling `pageFunction`. If it returns an element it 570 * is wrapped in an {@link ElementHandle}, else the raw value itself is 571 * returned. 572 */ 573 $eval<ReturnType>(selector: string, pageFunction: (element: Element, ...args: unknown[]) => ReturnType | Promise<ReturnType>, ...args: SerializableOrJSHandle[]): Promise<WrapElementHandle<ReturnType>>; 574 /** 575 * This method runs `Array.from(document.querySelectorAll(selector))` within 576 * the page and passes the result as the first argument to the `pageFunction`. 577 * 578 * @remarks 579 * 580 * If `pageFunction` returns a promise `$$eval` will wait for the promise to 581 * resolve and then return its value. 582 * 583 * @example 584 * 585 * ``` 586 * // get the amount of divs on the page 587 * const divCount = await page.$$eval('div', divs => divs.length); 588 * 589 * // get the text content of all the `.options` elements: 590 * const options = await page.$$eval('div > span.options', options => { 591 * return options.map(option => option.textContent) 592 * }); 593 * ``` 594 * 595 * If you are using TypeScript, you may have to provide an explicit type to the 596 * first argument of the `pageFunction`. 597 * By default it is typed as `Element[]`, but you may need to provide a more 598 * specific sub-type: 599 * 600 * @example 601 * 602 * ``` 603 * // if you don't provide HTMLInputElement here, TS will error 604 * // as `value` is not on `Element` 605 * await page.$$eval('input', (elements: HTMLInputElement[]) => { 606 * return elements.map(e => e.value); 607 * }); 608 * ``` 609 * 610 * The compiler should be able to infer the return type 611 * from the `pageFunction` you provide. If it is unable to, you can use the generic 612 * type to tell the compiler what return type you expect from `$$eval`: 613 * 614 * @example 615 * 616 * ``` 617 * // The compiler can infer the return type in this case, but if it can't 618 * // or if you want to be more explicit, provide it as the generic type. 619 * const allInputValues = await page.$$eval<string[]>( 620 * 'input', (elements: HTMLInputElement[]) => elements.map(e => e.textContent) 621 * ); 622 * ``` 623 * 624 * @param selector the 625 * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors | selector} 626 * to query for 627 * @param pageFunction the function to be evaluated in the page context. Will 628 * be passed the result of `Array.from(document.querySelectorAll(selector))` 629 * as its first argument. 630 * @param args any additional arguments to pass through to `pageFunction`. 631 * 632 * @returns The result of calling `pageFunction`. If it returns an element it 633 * is wrapped in an {@link ElementHandle}, else the raw value itself is 634 * returned. 635 */ 636 $$eval<ReturnType>(selector: string, pageFunction: (elements: Element[], ...args: unknown[]) => ReturnType | Promise<ReturnType>, ...args: SerializableOrJSHandle[]): Promise<WrapElementHandle<ReturnType>>; 637 $$(selector: string): Promise<ElementHandle[]>; 638 $x(expression: string): Promise<ElementHandle[]>; 639 /** 640 * If no URLs are specified, this method returns cookies for the current page 641 * URL. If URLs are specified, only cookies for those URLs are returned. 642 */ 643 cookies(...urls: string[]): Promise<Protocol.Network.Cookie[]>; 644 deleteCookie(...cookies: Protocol.Network.DeleteCookiesRequest[]): Promise<void>; 645 setCookie(...cookies: Protocol.Network.CookieParam[]): Promise<void>; 646 addScriptTag(options: { 647 url?: string; 648 path?: string; 649 content?: string; 650 type?: string; 651 }): Promise<ElementHandle>; 652 addStyleTag(options: { 653 url?: string; 654 path?: string; 655 content?: string; 656 }): Promise<ElementHandle>; 657 exposeFunction(name: string, puppeteerFunction: Function): Promise<void>; 658 authenticate(credentials: Credentials): Promise<void>; 659 setExtraHTTPHeaders(headers: Record<string, string>): Promise<void>; 660 setUserAgent(userAgent: string): Promise<void>; 661 metrics(): Promise<Metrics>; 662 private _emitMetrics; 663 private _buildMetricsObject; 664 private _handleException; 665 private _onConsoleAPI; 666 private _onBindingCalled; 667 private _addConsoleMessage; 668 private _onDialog; 669 url(): string; 670 content(): Promise<string>; 671 setContent(html: string, options?: WaitForOptions): Promise<void>; 672 goto(url: string, options?: WaitForOptions & { 673 referer?: string; 674 }): Promise<HTTPResponse>; 675 reload(options?: WaitForOptions): Promise<HTTPResponse | null>; 676 waitForNavigation(options?: WaitForOptions): Promise<HTTPResponse | null>; 677 private _sessionClosePromise; 678 waitForRequest(urlOrPredicate: string | Function, options?: { 679 timeout?: number; 680 }): Promise<HTTPRequest>; 681 waitForResponse(urlOrPredicate: string | Function, options?: { 682 timeout?: number; 683 }): Promise<HTTPResponse>; 684 goBack(options?: WaitForOptions): Promise<HTTPResponse | null>; 685 goForward(options?: WaitForOptions): Promise<HTTPResponse | null>; 686 private _go; 687 bringToFront(): Promise<void>; 688 emulate(options: { 689 viewport: Viewport; 690 userAgent: string; 691 }): Promise<void>; 692 setJavaScriptEnabled(enabled: boolean): Promise<void>; 693 setBypassCSP(enabled: boolean): Promise<void>; 694 emulateMediaType(type?: string): Promise<void>; 695 emulateMediaFeatures(features?: MediaFeature[]): Promise<void>; 696 emulateTimezone(timezoneId?: string): Promise<void>; 697 /** 698 * Emulates the idle state. 699 * If no arguments set, clears idle state emulation. 700 * 701 * @example 702 * ```js 703 * // set idle emulation 704 * await page.emulateIdleState({isUserActive: true, isScreenUnlocked: false}); 705 * 706 * // do some checks here 707 * ... 708 * 709 * // clear idle emulation 710 * await page.emulateIdleState(); 711 * ``` 712 * 713 * @param overrides Mock idle state. If not set, clears idle overrides 714 * @param isUserActive Mock isUserActive 715 * @param isScreenUnlocked Mock isScreenUnlocked 716 */ 717 emulateIdleState(overrides?: { 718 isUserActive: boolean; 719 isScreenUnlocked: boolean; 720 }): Promise<void>; 721 /** 722 * Simulates the given vision deficiency on the page. 723 * 724 * @example 725 * ```js 726 * const puppeteer = require('puppeteer'); 727 * 728 * (async () => { 729 * const browser = await puppeteer.launch(); 730 * const page = await browser.newPage(); 731 * await page.goto('https://v8.dev/blog/10-years'); 732 * 733 * await page.emulateVisionDeficiency('achromatopsia'); 734 * await page.screenshot({ path: 'achromatopsia.png' }); 735 * 736 * await page.emulateVisionDeficiency('deuteranopia'); 737 * await page.screenshot({ path: 'deuteranopia.png' }); 738 * 739 * await page.emulateVisionDeficiency('blurredVision'); 740 * await page.screenshot({ path: 'blurred-vision.png' }); 741 * 742 * await browser.close(); 743 * })(); 744 * ``` 745 * 746 * @param type - the type of deficiency to simulate, or `'none'` to reset. 747 */ 748 emulateVisionDeficiency(type?: Protocol.Emulation.SetEmulatedVisionDeficiencyRequest['type']): Promise<void>; 749 setViewport(viewport: Viewport): Promise<void>; 750 viewport(): Viewport | null; 751 /** 752 * @remarks 753 * 754 * Evaluates a function in the page's context and returns the result. 755 * 756 * If the function passed to `page.evaluteHandle` returns a Promise, the 757 * function will wait for the promise to resolve and return its value. 758 * 759 * @example 760 * 761 * ```js 762 * const result = await frame.evaluate(() => { 763 * return Promise.resolve(8 * 7); 764 * }); 765 * console.log(result); // prints "56" 766 * ``` 767 * 768 * You can pass a string instead of a function (although functions are 769 * recommended as they are easier to debug and use with TypeScript): 770 * 771 * @example 772 * ``` 773 * const aHandle = await page.evaluate('1 + 2'); 774 * ``` 775 * 776 * To get the best TypeScript experience, you should pass in as the 777 * generic the type of `pageFunction`: 778 * 779 * ``` 780 * const aHandle = await page.evaluate<() => number>(() => 2); 781 * ``` 782 * 783 * @example 784 * 785 * {@link ElementHandle} instances (including {@link JSHandle}s) can be passed 786 * as arguments to the `pageFunction`: 787 * 788 * ``` 789 * const bodyHandle = await page.$('body'); 790 * const html = await page.evaluate(body => body.innerHTML, bodyHandle); 791 * await bodyHandle.dispose(); 792 * ``` 793 * 794 * @param pageFunction - a function that is run within the page 795 * @param args - arguments to be passed to the pageFunction 796 * 797 * @returns the return value of `pageFunction`. 798 */ 799 evaluate<T extends EvaluateFn>(pageFunction: T, ...args: SerializableOrJSHandle[]): Promise<UnwrapPromiseLike<EvaluateFnReturnType<T>>>; 800 evaluateOnNewDocument(pageFunction: Function | string, ...args: unknown[]): Promise<void>; 801 setCacheEnabled(enabled?: boolean): Promise<void>; 802 screenshot(options?: ScreenshotOptions): Promise<Buffer | string | void>; 803 private _screenshotTask; 804 /** 805 * Generatees a PDF of the page with the `print` CSS media type. 806 * @remarks 807 * 808 * IMPORTANT: PDF generation is only supported in Chrome headless mode. 809 * 810 * To generate a PDF with the `screen` media type, call 811 * {@link Page.emulateMediaType | `page.emulateMediaType('screen')`} before 812 * calling `page.pdf()`. 813 * 814 * By default, `page.pdf()` generates a pdf with modified colors for printing. 815 * Use the 816 * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/-webkit-print-color-adjust | `-webkit-print-color-adjust`} 817 * property to force rendering of exact colors. 818 * 819 * 820 * @param options - options for generating the PDF. 821 */ 822 pdf(options?: PDFOptions): Promise<Buffer>; 823 title(): Promise<string>; 824 close(options?: { 825 runBeforeUnload?: boolean; 826 }): Promise<void>; 827 isClosed(): boolean; 828 get mouse(): Mouse; 829 click(selector: string, options?: { 830 delay?: number; 831 button?: MouseButton; 832 clickCount?: number; 833 }): Promise<void>; 834 focus(selector: string): Promise<void>; 835 hover(selector: string): Promise<void>; 836 select(selector: string, ...values: string[]): Promise<string[]>; 837 tap(selector: string): Promise<void>; 838 type(selector: string, text: string, options?: { 839 delay: number; 840 }): Promise<void>; 841 /** 842 * @remarks 843 * 844 * This method behaves differently depending on the first parameter. If it's a 845 * `string`, it will be treated as a `selector` or `xpath` (if the string 846 * starts with `//`). This method then is a shortcut for 847 * {@link Page.waitForSelector} or {@link Page.waitForXPath}. 848 * 849 * If the first argument is a function this method is a shortcut for 850 * {@link Page.waitForFunction}. 851 * 852 * If the first argument is a `number`, it's treated as a timeout in 853 * milliseconds and the method returns a promise which resolves after the 854 * timeout. 855 * 856 * @param selectorOrFunctionOrTimeout - a selector, predicate or timeout to 857 * wait for. 858 * @param options - optional waiting parameters. 859 * @param args - arguments to pass to `pageFunction`. 860 * 861 * @deprecated Don't use this method directly. Instead use the more explicit 862 * methods available: {@link Page.waitForSelector}, 863 * {@link Page.waitForXPath}, {@link Page.waitForFunction} or 864 * {@link Page.waitForTimeout}. 865 */ 866 waitFor(selectorOrFunctionOrTimeout: string | number | Function, options?: { 867 visible?: boolean; 868 hidden?: boolean; 869 timeout?: number; 870 polling?: string | number; 871 }, ...args: SerializableOrJSHandle[]): Promise<JSHandle>; 872 /** 873 * Causes your script to wait for the given number of milliseconds. 874 * 875 * @remarks 876 * 877 * It's generally recommended to not wait for a number of seconds, but instead 878 * use {@link Page.waitForSelector}, {@link Page.waitForXPath} or 879 * {@link Page.waitForFunction} to wait for exactly the conditions you want. 880 * 881 * @example 882 * 883 * Wait for 1 second: 884 * 885 * ``` 886 * await page.waitForTimeout(1000); 887 * ``` 888 * 889 * @param milliseconds - the number of milliseconds to wait. 890 */ 891 waitForTimeout(milliseconds: number): Promise<void>; 892 waitForSelector(selector: string, options?: { 893 visible?: boolean; 894 hidden?: boolean; 895 timeout?: number; 896 }): Promise<ElementHandle | null>; 897 waitForXPath(xpath: string, options?: { 898 visible?: boolean; 899 hidden?: boolean; 900 timeout?: number; 901 }): Promise<ElementHandle | null>; 902 waitForFunction(pageFunction: Function | string, options?: { 903 timeout?: number; 904 polling?: string | number; 905 }, ...args: SerializableOrJSHandle[]): Promise<JSHandle>; 906} 907export {}; 908//# sourceMappingURL=Page.d.ts.map