From f08ddbb734c8223d089d4b7571b40569fe8592f0 Mon Sep 17 00:00:00 2001 From: jwbay Date: Tue, 23 Jan 2018 13:53:59 -0500 Subject: [PATCH] puppeteer 1.0 (#23014) --- types/puppeteer/index.d.ts | 155 +++- types/puppeteer/puppeteer-tests.ts | 37 +- types/puppeteer/v0/index.d.ts | 1197 +++++++++++++++++++++++++ types/puppeteer/v0/puppeteer-tests.ts | 283 ++++++ types/puppeteer/v0/tsconfig.json | 34 + types/puppeteer/v0/tslint.json | 1 + 6 files changed, 1679 insertions(+), 28 deletions(-) create mode 100644 types/puppeteer/v0/index.d.ts create mode 100644 types/puppeteer/v0/puppeteer-tests.ts create mode 100644 types/puppeteer/v0/tsconfig.json create mode 100644 types/puppeteer/v0/tslint.json diff --git a/types/puppeteer/index.d.ts b/types/puppeteer/index.d.ts index d0958706e9..a325a871be 100644 --- a/types/puppeteer/index.d.ts +++ b/types/puppeteer/index.d.ts @@ -1,13 +1,15 @@ -// Type definitions for puppeteer 0.13 +// Type definitions for puppeteer 1.0 // Project: https://github.com/GoogleChrome/puppeteer#readme // Definitions by: Marvin Hagemeister // Christopher Deutsch +// jwbay // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 /// import { EventEmitter } from "events"; +import { ChildProcess } from "child_process"; /** Keyboard provides an api for managing a virtual keyboard. */ export interface Keyboard { @@ -91,10 +93,16 @@ export interface Touchscreen { * You can use `tracing.start` and `tracing.stop` to create a trace file which can be opened in Chrome DevTools or timeline viewer. */ export interface Tracing { - start(options: { path: string; screenshots?: boolean }): Promise; + start(options: TracingStartOptions): Promise; stop(): Promise; } +export interface TracingStartOptions { + path: string; + screenshots?: boolean; + categories?: string[]; +} + /** Dialog objects are dispatched by page via the 'dialog' event. */ export interface Dialog { /** @@ -113,16 +121,16 @@ export interface Dialog { message(): string; /** The dialog type. Dialog's type, can be one of `alert`, `beforeunload`, `confirm` or `prompt`. */ - type: "alert" | "beforeunload" | "confirm" | "prompt"; + type(): "alert" | "beforeunload" | "confirm" | "prompt"; } /** ConsoleMessage objects are dispatched by page via the 'console' event. */ export interface ConsoleMessage { /** The message arguments. */ - args: JSHandle[]; + args(): JSHandle[]; /** The message text. */ - text: string; - type: 'log' | 'debug' | 'info' | 'error' | 'warning' | 'dir' | 'dirxml' | 'table' | + text(): string; + type(): 'log' | 'debug' | 'info' | 'error' | 'warning' | 'dir' | 'dirxml' | 'table' | 'trace' | 'clear' | 'startGroup' | 'startGroupCollapsed' | 'endGroup' | 'assert' | 'profile' | 'profileEnd' | 'count' | 'timeEnd'; } @@ -302,6 +310,24 @@ export interface PDFOptions { * @default false */ displayHeaderFooter?: boolean; + /** + * HTML template for the print header. Should be valid HTML markup with following classes used to inject printing values into them: + * - `date` formatted print date + * - `title` document title + * - `url` document location + * - `pageNumber` current page number + * - `totalPages` total pages in the document + */ + headerTemplate?: string; + /** + * HTML template for the print footer. Should be valid HTML markup with following classes used to inject printing values into them: + * - `date` formatted print date + * - `title` document title + * - `url` document location + * - `pageNumber` current page number + * - `totalPages` total pages in the document + */ + footerTemplate?: string; /** * Print background graphics. * @default false @@ -418,6 +444,10 @@ export interface ElementHandle extends JSHandle { * @since 0.13.0 */ $$(selector: string): Promise; + /** + * @param selector XPath expression to evaluate. + */ + $x(expression: string): Promise; /** * This method returns the value resolve to the bounding box of the element (relative to the main frame), or null if the element is not visible. */ @@ -590,20 +620,25 @@ export interface Request { */ continue(overrides?: Overrides): Promise; + /** + * @returns The `Frame` object that initiated the request, or `null` if navigating to error pages + */ + frame(): Promise; + /** * An object with HTTP headers associated with the request. * All header names are lower-case. */ - headers: Headers; + headers(): Headers; /** Returns the request's method (GET, POST, etc.) */ - method: HttpMethod; + method(): HttpMethod; /** Contains the request's post body, if any. */ - postData: string | undefined; + postData(): string | undefined; /** Contains the request's resource type as it was perceived by the rendering engine. */ - resourceType: ResourceType; + resourceType(): ResourceType; /** * Fulfills request with given response. @@ -617,7 +652,7 @@ export interface Request { response(): Response | null; /** Contains the URL of the request. */ - url: string; + url(): string; } /** Options for `Request.respond` method */ export interface RespondOptions { @@ -639,22 +674,22 @@ export interface Response { /** Promise which resolves to a buffer with response body. */ buffer(): Promise; /** An object with HTTP headers associated with the response. All header names are lower-case. */ - headers: Headers; + headers(): Headers; /** * Promise which resolves to a JSON representation of response body. * @throws This method will throw if the response body is not parsable via `JSON.parse`. */ json(): Promise; /** Contains a boolean stating whether the response was successful (status in the range 200-299) or not. */ - ok: boolean; + ok(): boolean; /** A matching Request object. */ request(): Request; /** Contains the status code of the response (e.g., 200 for a success). */ - status: number; + status(): number; /** Promise which resolves to a text representation of response body. */ text(): Promise; /** Contains the URL of the response. */ - url: string; + url(): string; } export interface FrameBase { @@ -667,6 +702,10 @@ export interface FrameBase { * The method runs document.querySelectorAll within the page. If no elements match the selector, the return value resolve to []. */ $$(selector: string): Promise; + /** + * @param expression XPath expression to evaluate. + */ + $x(expression: string): Promise; /** * This method runs document.querySelector within the page and passes it as the first argument to `fn`. @@ -699,6 +738,9 @@ export interface FrameBase { /** Adds a `` tag into the page with the desired url or a `