UNPKG

puppeteer

Version:

A high-level API to control headless Chrome over the DevTools Protocol

148 lines • 5.77 kB
/** * 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. */ /// <reference types="node" /> import { PuppeteerLifeCycleEvent } from './LifecycleWatcher'; import { JSHandle, ElementHandle } from './JSHandle'; import { ExecutionContext } from './ExecutionContext'; import { TimeoutSettings } from './TimeoutSettings'; import { MouseButton } from './Input'; import { FrameManager, Frame } from './FrameManager'; import { EvaluateFn, SerializableOrJSHandle, EvaluateHandleFn, WrapElementHandle } from './EvalTypes'; export interface WaitForSelectorOptions { visible?: boolean; hidden?: boolean; timeout?: number; } export declare class DOMWorld { _frameManager: FrameManager; _frame: Frame; _timeoutSettings: TimeoutSettings; _documentPromise?: Promise<ElementHandle>; _contextPromise?: Promise<ExecutionContext>; _contextResolveCallback?: (x?: ExecutionContext) => void; _detached: boolean; _waitTasks: Set<WaitTask>; constructor(frameManager: FrameManager, frame: Frame, timeoutSettings: TimeoutSettings); frame(): Frame; /** * @param {?ExecutionContext} context */ _setContext(context?: ExecutionContext): void; _hasContext(): boolean; _detach(): void; /** * @returns {!Promise<!ExecutionContext>} */ executionContext(): Promise<ExecutionContext>; evaluateHandle<HandlerType extends JSHandle = JSHandle>(pageFunction: EvaluateHandleFn, ...args: SerializableOrJSHandle[]): Promise<HandlerType>; /** * @param {Function|string} pageFunction * @param {!Array<*>} args * @returns {!Promise<*>} */ evaluate<ReturnType extends any>(pageFunction: Function | string, ...args: unknown[]): Promise<ReturnType>; /** * @param {string} selector * @returns {!Promise<?ElementHandle>} */ $(selector: string): Promise<ElementHandle | null>; _document(): Promise<ElementHandle>; $x(expression: string): Promise<ElementHandle[]>; $eval<ReturnType>(selector: string, pageFunction: (element: Element, ...args: unknown[]) => ReturnType | Promise<ReturnType>, ...args: SerializableOrJSHandle[]): Promise<WrapElementHandle<ReturnType>>; $$eval<ReturnType extends any>(selector: string, pageFunction: EvaluateFn | string, ...args: SerializableOrJSHandle[]): Promise<ReturnType>; /** * @param {string} selector * @returns {!Promise<!Array<!ElementHandle>>} */ $$(selector: string): Promise<ElementHandle[]>; content(): Promise<string>; setContent(html: string, options?: { timeout?: number; waitUntil?: PuppeteerLifeCycleEvent | PuppeteerLifeCycleEvent[]; }): Promise<void>; /** * Adds a script tag into the current context. * * @remarks * * You can pass a URL, filepath or string of contents. Note that when running Puppeteer * in a browser environment you cannot pass a filepath and should use either * `url` or `content`. * * @param options */ addScriptTag(options: { url?: string; path?: string; content?: string; type?: string; }): Promise<ElementHandle>; /** * Adds a style tag into the current context. * * @remarks * * You can pass a URL, filepath or string of contents. Note that when running Puppeteer * in a browser environment you cannot pass a filepath and should use either * `url` or `content`. * * @param options */ addStyleTag(options: { url?: string; path?: string; content?: string; }): Promise<ElementHandle>; click(selector: string, options: { delay?: number; button?: MouseButton; clickCount?: number; }): Promise<void>; focus(selector: string): Promise<void>; hover(selector: string): Promise<void>; select(selector: string, ...values: string[]): Promise<string[]>; tap(selector: string): Promise<void>; type(selector: string, text: string, options?: { delay: number; }): Promise<void>; waitForSelector(selector: string, options: WaitForSelectorOptions): Promise<ElementHandle | null>; waitForXPath(xpath: string, options: WaitForSelectorOptions): Promise<ElementHandle | null>; waitForFunction(pageFunction: Function | string, options?: { polling?: string | number; timeout?: number; }, ...args: SerializableOrJSHandle[]): Promise<JSHandle>; title(): Promise<string>; private _waitForSelectorOrXPath; } declare class WaitTask { _domWorld: DOMWorld; _polling: string | number; _timeout: number; _predicateBody: string; _args: SerializableOrJSHandle[]; _runCount: number; promise: Promise<JSHandle>; _resolve: (x: JSHandle) => void; _reject: (x: Error) => void; _timeoutTimer?: NodeJS.Timeout; _terminated: boolean; constructor(domWorld: DOMWorld, predicateBody: Function | string, predicateQueryHandlerBody: Function | string | undefined, title: string, polling: string | number, timeout: number, ...args: SerializableOrJSHandle[]); terminate(error: Error): void; rerun(): Promise<void>; _cleanup(): void; } export {}; //# sourceMappingURL=DOMWorld.d.ts.map