forked from cyrus-and/chrome-remote-interface
/
index.d.ts
412 lines (378 loc) · 13 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
import type ProtocolMappingApi from 'devtools-protocol/types/protocol-mapping';
import type ProtocolProxyApi from 'devtools-protocol/types/protocol-proxy-api';
declare namespace CDP {
interface BaseOptions {
host?: string | undefined;
port?: number | undefined;
secure?: boolean | undefined;
useHostName?: boolean | undefined;
alterPath?: ((path: string) => string) | undefined;
}
interface Options extends BaseOptions {
target?:
| ((targets: Target[]) => Target | number)
| Target
| string
| undefined;
protocol?: Protocol | undefined;
local?: boolean | undefined;
}
interface ActivateOptions extends BaseOptions {
id: string;
}
interface CloseOptions extends BaseOptions {
id: string;
}
interface NewOptions extends BaseOptions {
url?: string | undefined;
}
interface ProtocolOptions extends BaseOptions {
local?: boolean | undefined;
}
interface EventMessage {
method: string;
params: object;
sessionId?: string | undefined;
}
interface SendError {
code: number;
message: string;
data?: string | undefined;
}
interface SendCallback<T extends keyof ProtocolMappingApi.Commands> {
(error: true, response: SendError): void;
(
error: false,
response: ProtocolMappingApi.Commands[T]['returnType'],
): void;
(error: Error, response: undefined): void;
}
interface Target {
description: string;
devtoolsFrontendUrl: string;
id: string;
title: string;
type: string;
url: string;
webSocketDebuggerUrl: string;
}
interface VersionResult {
Browser: string;
'Protocol-Version': string;
'User-Agent': string;
'V8-Version': string;
'Webkit-Version': string;
webSocketDebuggerUrl: string;
}
/////////////////////////////////////////////////
// Generated with https://app.quicktype.io/, Name: Protocol, Language: TypeScript, Interfaces only.
// Manually done: TypeEnum simplified, add " | undefined" for optional properties.
// Source: https://github.com/ChromeDevTools/devtools-protocol/blob/master/json/ (merge JSON objects)
/////////////////////////////////////////////////
interface Protocol {
version: Version;
domains: Domain[];
}
interface Domain {
domain: string;
experimental?: boolean | undefined;
dependencies?: string[] | undefined;
types?: TypeElement[] | undefined;
commands: Command[];
events?: Event[] | undefined;
description?: string | undefined;
deprecated?: boolean | undefined;
}
interface Command {
name: string;
description?: string | undefined;
experimental?: boolean | undefined;
parameters?: Parameter[] | undefined;
returns?: Parameter[] | undefined;
redirect?: string | undefined;
deprecated?: boolean | undefined;
}
interface Parameter {
name: string;
description?: string | undefined;
optional?: boolean | undefined;
$ref?: string | undefined;
type?: TypeEnum | undefined;
items?: Items | undefined;
enum?: string[] | undefined;
experimental?: boolean | undefined;
deprecated?: boolean | undefined;
}
interface Items {
type?: TypeEnum | undefined;
$ref?: string | undefined;
}
type TypeEnum =
| 'any'
| 'array'
| 'boolean'
| 'integer'
| 'number'
| 'object'
| 'string';
interface Event {
name: string;
description?: string | undefined;
parameters?: Parameter[] | undefined;
experimental?: boolean | undefined;
deprecated?: boolean | undefined;
}
interface TypeElement {
id: string;
description?: string | undefined;
type: TypeEnum;
enum?: string[] | undefined;
properties?: Parameter[] | undefined;
experimental?: boolean | undefined;
items?: Items | undefined;
deprecated?: boolean | undefined;
}
interface Version {
major: string;
minor: string;
}
/////////////////////////////////////////////////
// Generated content end.
/////////////////////////////////////////////////
type GetEventFromString<
D extends string,
S extends string,
> = S extends `${D}.${infer E}` ? E : never;
type GetEvent<D extends string> = GetEventFromString<
D,
keyof ProtocolMappingApi.Events
>;
type GetReturnType<
D extends string,
E extends string,
> = `${D}.${E}` extends keyof ProtocolMappingApi.Events
? ProtocolMappingApi.Events[`${D}.${E}`][0]
: never;
type DoEventPromises<D extends string> = {
[event in GetEvent<D>]: // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
() => Promise<
GetReturnType<D, event> extends undefined ? void : GetReturnType<D, event>
>;
};
type DoEventListeners<D extends string> = {
[event in GetEvent<D>]: (
listener: (params: GetReturnType<D, event>, sessionId?: string) => void,
) => () => Client;
};
type DoEventObj<D> = D extends string
? DoEventPromises<D> & DoEventListeners<D>
: {};
type IsNullableObj<T> = Record<keyof T, undefined> extends T ? true : false;
/**
* Checks whether the only parameter of `T[key]` is nullable i.e. all of
* its properties are optional, and makes it optional if so.
*/
type OptIfParamNullable<T> = {
[key in keyof T]: T[key] extends (params: any) => any
? IsNullableObj<Parameters<T[key]>[0]> extends true
? (params?: Parameters<T[key]>[0]) => ReturnType<T[key]>
: T[key]
: T[key];
};
type AddOptParams<T> = {
[key in keyof T]: key extends 'on'
? T[key]
: T[key] extends (...args: infer P) => infer R
? (...args: [...curArgs: P, sessionId?: string]) => R
: T[key];
};
type ImproveAPI<T> = {
[key in keyof T]: DoEventObj<key> &
AddOptParams<OptIfParamNullable<T[key]>>;
};
interface StableDomains {
Browser: ProtocolProxyApi.BrowserApi;
Debugger: ProtocolProxyApi.DebuggerApi;
DOM: ProtocolProxyApi.DOMApi;
DOMDebugger: ProtocolProxyApi.DOMDebuggerApi;
Emulation: ProtocolProxyApi.EmulationApi;
Input: ProtocolProxyApi.InputApi;
IO: ProtocolProxyApi.IOApi;
Log: ProtocolProxyApi.LogApi;
Network: ProtocolProxyApi.NetworkApi;
Page: ProtocolProxyApi.PageApi;
Performance: ProtocolProxyApi.PerformanceApi;
Profiler: ProtocolProxyApi.ProfilerApi;
Runtime: ProtocolProxyApi.RuntimeApi;
Security: ProtocolProxyApi.SecurityApi;
Target: ProtocolProxyApi.TargetApi;
}
interface DeprecatedDomains {
/** @deprecated This domain is deprecated - use Runtime or Log instead. */
Console: ProtocolProxyApi.ConsoleApi;
/** @deprecated This domain is deprecated. */
Schema: ProtocolProxyApi.SchemaApi;
}
interface ExperimentalDomains {
/** @deprecated this API is experimental. */
Accessibility: ProtocolProxyApi.AccessibilityApi;
/** @deprecated this API is experimental. */
Animation: ProtocolProxyApi.AnimationApi;
/** @deprecated this API is experimental. */
ApplicationCache: ProtocolProxyApi.ApplicationCacheApi;
/** @deprecated this API is experimental. */
Audits: ProtocolProxyApi.AuditsApi;
/** @deprecated this API is experimental. */
BackgroundService: ProtocolProxyApi.BackgroundServiceApi;
/** @deprecated this API is experimental. */
CacheStorage: ProtocolProxyApi.CacheStorageApi;
/** @deprecated this API is experimental. */
Cast: ProtocolProxyApi.CastApi;
/** @deprecated this API is experimental. */
CSS: ProtocolProxyApi.CSSApi;
/** @deprecated this API is experimental. */
Database: ProtocolProxyApi.DatabaseApi;
/** @deprecated this API is experimental. */
DeviceOrientation: ProtocolProxyApi.DeviceOrientationApi;
/** @deprecated this API is experimental. */
DOMSnapshot: ProtocolProxyApi.DOMSnapshotApi;
/** @deprecated this API is experimental. */
DOMStorage: ProtocolProxyApi.DOMStorageApi;
/** @deprecated this API is experimental. */
Fetch: ProtocolProxyApi.FetchApi;
/** @deprecated this API is experimental. */
HeadlessExperimental: ProtocolProxyApi.HeadlessExperimentalApi;
/** @deprecated this API is experimental. */
HeapProfiler: ProtocolProxyApi.HeapProfilerApi;
/** @deprecated this API is experimental. */
IndexedDB: ProtocolProxyApi.IndexedDBApi;
/** @deprecated this API is experimental. */
Inspector: ProtocolProxyApi.InspectorApi;
/** @deprecated this API is experimental. */
LayerTree: ProtocolProxyApi.LayerTreeApi;
/** @deprecated this API is experimental. */
Media: ProtocolProxyApi.MediaApi;
/** @deprecated this API is experimental. */
Memory: ProtocolProxyApi.MemoryApi;
/** @deprecated this API is experimental. */
Overlay: ProtocolProxyApi.OverlayApi;
/** @deprecated this API is experimental. */
ServiceWorker: ProtocolProxyApi.ServiceWorkerApi;
/** @deprecated this API is experimental. */
Storage: ProtocolProxyApi.StorageApi;
/** @deprecated this API is experimental. */
SystemInfo: ProtocolProxyApi.SystemInfoApi;
/** @deprecated this API is experimental. */
Tethering: ProtocolProxyApi.TetheringApi;
/** @deprecated this API is experimental. */
Tracing: ProtocolProxyApi.TracingApi;
/** @deprecated this API is experimental. */
WebAudio: ProtocolProxyApi.WebAudioApi;
/** @deprecated this API is experimental. */
WebAuthn: ProtocolProxyApi.WebAuthnApi;
}
type AllDomains = StableDomains & DeprecatedDomains & ExperimentalDomains;
type Client = {
close: () => Promise<void>;
on(event: 'event', callback: (message: EventMessage) => void): void;
on(event: 'ready' | 'disconnect', callback: () => void): void;
// '<domain>.<method>' i.e. Network.requestWillBeSent
on<T extends keyof ProtocolMappingApi.Events>(
event: T,
callback: (
params: ProtocolMappingApi.Events[T][0],
sessionId?: string,
) => void,
): void;
// '<domain>.<method>.<sessionId>' i.e. Network.requestWillBeSent.abc123
on(
event: string,
callback: (params: object, sessionId?: string) => void,
): void;
// client.send(method, [params], [sessionId], [callback])
send<T extends keyof ProtocolMappingApi.Commands>(
event: T,
callback: SendCallback<T>,
): void;
send<T extends keyof ProtocolMappingApi.Commands>(
event: T,
params: ProtocolMappingApi.Commands[T]['paramsType'][0],
callback: SendCallback<T>,
): void;
send<T extends keyof ProtocolMappingApi.Commands>(
event: T,
params: ProtocolMappingApi.Commands[T]['paramsType'][0],
sessionId: string,
callback: SendCallback<T>,
): void;
send<T extends keyof ProtocolMappingApi.Commands>(
event: T,
params?: ProtocolMappingApi.Commands[T]['paramsType'][0],
sessionId?: string,
): Promise<ProtocolMappingApi.Commands[T]['returnType']>;
} & EventPromises<ProtocolMappingApi.Events> &
EventCallbacks<ProtocolMappingApi.Events> &
ImproveAPI<AllDomains>;
// '<domain>.<event>' i.e. Page.loadEventFired
type EventPromises<T extends ProtocolMappingApi.Events> = {
[Property in keyof T]: () => T[Property] extends [any]
? Promise<T[Property][0]>
: Promise<void>;
};
type EventCallbacks<T extends ProtocolMappingApi.Events> = {
[Property in keyof T]: (
callback: (
params: T[Property] extends [any] ? T[Property][0] : undefined,
sessionId?: string,
) => void,
) => () => Client;
};
}
declare const CDP: {
(options: CDP.Options, callback: (client: CDP.Client) => void): void;
(callback: (client: CDP.Client) => void): void;
(options?: CDP.Options): Promise<CDP.Client>;
};
export default CDP;
export function Activate(
options: CDP.ActivateOptions,
callback: (err: Error | null) => void,
): void;
export function Activate(options: CDP.ActivateOptions): Promise<void>;
export function Close(
options: CDP.CloseOptions,
callback: (err: Error | null) => void,
): void;
export function Close(options: CDP.CloseOptions): Promise<void>;
export function List(
options: CDP.BaseOptions,
callback: (err: Error | null, targets: CDP.Target[]) => void,
): void;
export function List(
callback: (err: Error | null, targets: CDP.Target[]) => void,
): void;
export function List(options?: CDP.BaseOptions): Promise<CDP.Target[]>;
export function New(
options: CDP.NewOptions,
callback: (err: Error | null, target: CDP.Target) => void,
): void;
export function New(
callback: (err: Error | null, target: CDP.Target) => void,
): void;
export function New(options?: CDP.NewOptions): Promise<CDP.Target>;
export function Protocol(
options: CDP.ProtocolOptions,
callback: (err: Error | null, protocol: CDP.Protocol) => void,
): void;
export function Protocol(
callback: (err: Error | null, protocol: CDP.Protocol) => void,
): void;
export function Protocol(options?: CDP.ProtocolOptions): Promise<CDP.Protocol>;
export function Version(
options: CDP.BaseOptions,
callback: (err: Error | null, info: CDP.VersionResult) => void,
): void;
export function Version(
callback: (err: Error | null, info: CDP.VersionResult) => void,
): void;
export function Version(options?: CDP.BaseOptions): Promise<CDP.VersionResult>;