devtools-protocol icon indicating copy to clipboard operation
devtools-protocol copied to clipboard

Add `Promise` version of events

Open kazarmy opened this issue 4 years ago • 0 comments

This pr extends the generator script to add Promise versions of events, e.g.:

domContentEventFired(): Promise<Protocol.Page.DomContentEventFiredEvent>;

as a complement for

on(event: 'domContentEventFired', listener: (params: Protocol.Page.DomContentEventFiredEvent) => void): void;

The motivation for this pr is to provide typings support for the following syntax:

const {Page} = client;
await Page.domContentEventFired();

Currently, typings support is provided for the following syntax via DefinitelyTyped's chrome-remote-interface typings:

await client['Page.domContentEventFired']();

but it is less elegant and the client part shouldn't really be necessary. Unfortunately, it doesn't seem possible to provide typings for the former syntax via protocol-mapping.d.ts since it is not possible to split something like 'Page.domContentEventFired' into its component parts with the current version of TypeScript (4.3).


In the code, there are two forEach loops for emitApiEvent() so that all the on() overloads are kept together.

Fixes #246.

kazarmy avatar Aug 10 '21 07:08 kazarmy