UNPKG

cdp-web

Version:

Provides a lightweight way to communicate with the Chrome DevTools Protocol (CDP).

45 lines (42 loc) 2.16 kB
type DeferredState = "pending" | "fulfilled" | "rejected"; declare class Deferred<T> extends Promise<T> { readonly state: DeferredState; readonly value?: T; readonly reason?: unknown; resolve: (value: T | PromiseLike<T>) => void; reject: (reason?: unknown) => void; constructor(executor?: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: unknown) => void) => void); } interface CdpConnectionOptions { url?: string | URL | undefined; target?: string | undefined; } interface CdpMessageEventInit<T = unknown> extends EventInit { method: string; params: T; } declare class CdpMessageEvent<T = unknown> extends Event { readonly method: string; readonly params: T; constructor(init: CdpMessageEventInit<T>); } interface CdpConnectionEventMap { message: CdpMessageEvent; } declare class CdpError extends Error { code: number; constructor(code: number, message: string, options?: ErrorOptions | undefined); } declare class CdpConnection extends EventTarget { #private; static create(options?: CdpConnectionOptions | undefined): Promise<CdpConnection>; private constructor(); send(method: string, params?: unknown): Deferred<unknown>; close(): void; addEventListener<T extends keyof CdpConnectionEventMap>(type: T, listener: (this: WebSocket, event: CdpConnectionEventMap[T]) => unknown, options?: boolean | AddEventListenerOptions): void; addEventListener(type: string, listener: (this: WebSocket, event: Event) => unknown, options?: boolean | AddEventListenerOptions): void; removeEventListener<T extends keyof CdpConnectionEventMap>(type: T, listener: (this: WebSocket, event: CdpConnectionEventMap[T]) => unknown, options?: boolean | EventListenerOptions): void; removeEventListener(type: string, listener: (this: WebSocket, event: Event) => unknown, options?: boolean | EventListenerOptions): void; } declare function createCdpConnection(options?: CdpConnectionOptions | undefined): Promise<CdpConnection>; export { CdpConnection, CdpConnectionEventMap, CdpConnectionOptions, CdpError, CdpMessageEvent, CdpMessageEventInit, createCdpConnection };