/** * Copyright 2019 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /// import { ExecutionContext } from './ExecutionContext.js'; import { Page, ScreenshotOptions } from './Page.js'; import { CDPSession } from './Connection.js'; import { KeyInput } from './USKeyboardLayout.js'; import { FrameManager, Frame } from './FrameManager.js'; import { Protocol } from 'devtools-protocol'; import { EvaluateFn, SerializableOrJSHandle, EvaluateFnReturnType, EvaluateHandleFn, WrapElementHandle, UnwrapPromiseLike } from './EvalTypes.js'; /** * @public */ export interface BoxModel { content: Array<{ x: number; y: number; }>; padding: Array<{ x: number; y: number; }>; border: Array<{ x: number; y: number; }>; margin: Array<{ x: number; y: number; }>; width: number; height: number; } /** * @public */ export interface BoundingBox { /** * the x coordinate of the element in pixels. */ x: number; /** * the y coordinate of the element in pixels. */ y: number; /** * the width of the element in pixels. */ width: number; /** * the height of the element in pixels. */ height: number; } /** * @internal */ export declare function createJSHandle(context: ExecutionContext, remoteObject: Protocol.Runtime.RemoteObject): JSHandle; /** * Represents an in-page JavaScript object. JSHandles can be created with the * {@link Page.evaluateHandle | page.evaluateHandle} method. * * @example * ```js * const windowHandle = await page.evaluateHandle(() => window); * ``` * * JSHandle prevents the referenced JavaScript object from being garbage-collected * unless the handle is {@link JSHandle.dispose | disposed}. JSHandles are auto- * disposed when their origin frame gets navigated or the parent context gets destroyed. * * JSHandle instances can be used as arguments for {@link Page.$eval}, * {@link Page.evaluate}, and {@link Page.evaluateHandle}. * * @public */ export declare class JSHandle { /** * @internal */ _context: ExecutionContext; /** * @internal */ _client: CDPSession; /** * @internal */ _remoteObject: Protocol.Runtime.RemoteObject; /** * @internal */ _disposed: boolean; /** * @internal */ constructor(context: ExecutionContext, client: CDPSession, remoteObject: Protocol.Runtime.RemoteObject); /** Returns the execution context the handle belongs to. */ executionContext(): ExecutionContext; /** * This method passes this handle as the first argument to `pageFunction`. * If `pageFunction` returns a Promise, then `handle.evaluate` would wait * for the promise to resolve and return its value. * * @example * ```js * const tweetHandle = await page.$('.tweet .retweets'); * expect(await tweetHandle.evaluate(node => node.innerText)).toBe('10'); * ``` */ evaluate>(pageFunction: T | string, ...args: SerializableOrJSHandle[]): Promise>>; /** * This method passes this handle as the first argument to `pageFunction`. * * @remarks * * The only difference between `jsHandle.evaluate` and * `jsHandle.evaluateHandle` is that `jsHandle.evaluateHandle` * returns an in-page object (JSHandle). * * If the function passed to `jsHandle.evaluateHandle` returns a Promise, * then `evaluateHandle.evaluateHandle` waits for the promise to resolve and * returns its value. * * See {@link Page.evaluateHandle} for more details. */ evaluateHandle(pageFunction: EvaluateHandleFn, ...args: SerializableOrJSHandle[]): Promise; /** Fetches a single property from the referenced object. */ getProperty(propertyName: string): Promise; /** * The method returns a map with property names as keys and JSHandle * instances for the property values. * * @example * ```js * const listHandle = await page.evaluateHandle(() => document.body.children); * const properties = await listHandle.getProperties(); * const children = []; * for (const property of properties.values()) { * const element = property.asElement(); * if (element) * children.push(element); * } * children; // holds elementHandles to all children of document.body * ``` */ getProperties(): Promise>; /** * @returns Returns a JSON representation of the object.If the object has a * `toJSON` function, it will not be called. * @remarks * * The JSON is generated by running {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify | JSON.stringify} * on the object in page and consequent {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse | JSON.parse} in puppeteer. * **NOTE** The method throws if the referenced object is not stringifiable. */ jsonValue(): Promise; /** * @returns Either `null` or the object handle itself, if the object * handle is an instance of {@link ElementHandle}. */ asElement(): ElementHandle | null; /** * Stops referencing the element handle, and resolves when the object handle is * successfully disposed of. */ dispose(): Promise; /** * Returns a string representation of the JSHandle. * * @remarks Useful during debugging. */ toString(): string; } /** * ElementHandle represents an in-page DOM element. * * @remarks * * ElementHandles can be created with the {@link Page.$} method. * * ```js * const puppeteer = require('puppeteer'); * * (async () => { * const browser = await puppeteer.launch(); * const page = await browser.newPage(); * await page.goto('https://example.com'); * const hrefElement = await page.$('a'); * await hrefElement.click(); * // ... * })(); * ``` * * ElementHandle prevents the DOM element from being garbage-collected unless the * handle is {@link JSHandle.dispose | disposed}. ElementHandles are auto-disposed * when their origin frame gets navigated. * * ElementHandle instances can be used as arguments in {@link Page.$eval} and * {@link Page.evaluate} methods. * * If you're using TypeScript, ElementHandle takes a generic argument that * denotes the type of element the handle is holding within. For example, if you * have a handle to a `` element matching `selector`, the method * throws an error. * * @example * ```js * handle.select('blue'); // single selection * handle.select('red', 'green', 'blue'); // multiple selections * ``` * @param values - Values of options to select. If the `