diff --git a/types/puppeteer/index.d.ts b/types/puppeteer/index.d.ts index bd65a70455..66c73e1f96 100644 --- a/types/puppeteer/index.d.ts +++ b/types/puppeteer/index.d.ts @@ -18,6 +18,19 @@ export type WrapElementHandle = X extends Element ? ElementHandle : X; /** Unwraps a DOM element out of an ElementHandle instance */ export type UnwrapElementHandle = X extends ElementHandle ? E : X; +export type Serializable = + | number + | string + | boolean + | null + | JSONArray + | JSONObject; +export interface JSONArray extends Array { } +export interface JSONObject { + [key: string]: Serializable; +} +export type SerializableOrJSHandle = Serializable | JSHandle; + /** Defines `$eval` and `$$eval` for Page, Frame and ElementHandle. */ export interface Evalable { /** @@ -106,7 +119,7 @@ export interface Evalable { $eval( selector: string, pageFunction: (element: Element, ...args: any[]) => R | Promise, - ...args: any[], + ...args: SerializableOrJSHandle[], ): Promise>; /** @@ -195,7 +208,7 @@ export interface Evalable { $$eval( selector: string, pageFunction: (elements: Element[], ...args: any[]) => R | Promise, - ...args: any[] + ...args: SerializableOrJSHandle[] ): Promise>; } @@ -718,7 +731,7 @@ export interface Worker { */ evaluate( pageFunction: (...args: any[]) => T | Promise, - ...args: any[], + ...args: SerializableOrJSHandle[], ): Promise; /** @@ -727,7 +740,7 @@ export interface Worker { */ evaluateHandle( pageFunction: (...args: any[]) => T | Promise, - ...args: any[], + ...args: SerializableOrJSHandle[], ): Promise; executionContext(): Promise; @@ -830,11 +843,11 @@ export interface ElementHandle extends JSHandle, Ev export interface ExecutionContext { evaluate( fn: EvaluateFn, - ...args: any[] + ...args: SerializableOrJSHandle[] ): Promise; evaluateHandle( fn: EvaluateFn, - ...args: any[] + ...args: SerializableOrJSHandle[] ): Promise; queryObjects(prototypeHandle: JSHandle): JSHandle; } @@ -1141,7 +1154,7 @@ export interface FrameBase extends Evalable { */ evaluate( fn: EvaluateFn, - ...args: any[] + ...args: SerializableOrJSHandle[] ): Promise; /** @@ -1154,7 +1167,7 @@ export interface FrameBase extends Evalable { */ evaluateHandle( fn: EvaluateFn, - ...args: any[] + ...args: SerializableOrJSHandle[] ): Promise; /** This method fetches an element with selector and focuses it. */ @@ -1219,7 +1232,11 @@ export interface FrameBase extends Evalable { /** * Shortcut for waitForFunction. */ - waitFor(selector: ((...args: any[]) => any) | string, options?: WaitForSelectorOptions, ...args: any[]): Promise; + waitFor( + selector: ((...args: any[]) => any) | string, + options?: WaitForSelectorOptions, + ...args: SerializableOrJSHandle[] + ): Promise; /** * Allows waiting for various conditions. @@ -1227,7 +1244,7 @@ export interface FrameBase extends Evalable { waitForFunction( fn: string | ((...args: any[]) => any), options?: PageFnOptions, - ...args: any[] + ...args: SerializableOrJSHandle[] ): Promise; /** @@ -1539,7 +1556,7 @@ export interface Page extends EventEmitter, FrameBase { */ evaluateHandle( fn: EvaluateFn, - ...args: any[] + ...args: SerializableOrJSHandle[] ): Promise; /** @@ -1550,7 +1567,7 @@ export interface Page extends EventEmitter, FrameBase { */ evaluateOnNewDocument( fn: EvaluateFn, - ...args: any[] + ...args: SerializableOrJSHandle[] ): Promise; /**