forked from chromedp/cdproto
/
types.go
516 lines (455 loc) · 19.9 KB
/
types.go
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
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
package runtime
// Code generated by cdproto-gen. DO NOT EDIT.
import (
"errors"
"fmt"
"strconv"
"time"
"github.com/mailru/easyjson"
"github.com/mailru/easyjson/jlexer"
"github.com/mailru/easyjson/jwriter"
)
// ScriptID unique script identifier.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#type-ScriptId
type ScriptID string
// String returns the ScriptID as string value.
func (t ScriptID) String() string {
return string(t)
}
// RemoteObjectID unique object identifier.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#type-RemoteObjectId
type RemoteObjectID string
// String returns the RemoteObjectID as string value.
func (t RemoteObjectID) String() string {
return string(t)
}
// UnserializableValue primitive value which cannot be JSON-stringified.
// Includes values -0, NaN, Infinity, -Infinity, and bigint literals.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#type-UnserializableValue
type UnserializableValue string
// String returns the UnserializableValue as string value.
func (t UnserializableValue) String() string {
return string(t)
}
// RemoteObject mirror object referencing original JavaScript object.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#type-RemoteObject
type RemoteObject struct {
Type Type `json:"type"` // Object type.
Subtype Subtype `json:"subtype,omitempty"` // Object subtype hint. Specified for object type values only.
ClassName string `json:"className,omitempty"` // Object class (constructor) name. Specified for object type values only.
Value easyjson.RawMessage `json:"value,omitempty"` // Remote object value in case of primitive values or JSON values (if it was requested).
UnserializableValue UnserializableValue `json:"unserializableValue,omitempty"` // Primitive value which can not be JSON-stringified does not have value, but gets this property.
Description string `json:"description,omitempty"` // String representation of the object.
ObjectID RemoteObjectID `json:"objectId,omitempty"` // Unique object identifier (for non-primitive values).
Preview *ObjectPreview `json:"preview,omitempty"` // Preview containing abbreviated property values. Specified for object type values only.
CustomPreview *CustomPreview `json:"customPreview,omitempty"`
}
// CustomPreview [no description].
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#type-CustomPreview
type CustomPreview struct {
Header string `json:"header"` // The JSON-stringified result of formatter.header(object, config) call. It contains json ML array that represents RemoteObject.
BodyGetterID RemoteObjectID `json:"bodyGetterId,omitempty"` // If formatter returns true as a result of formatter.hasBody call then bodyGetterId will contain RemoteObjectId for the function that returns result of formatter.body(object, config) call. The result value is json ML array.
}
// ObjectPreview object containing abbreviated remote object value.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#type-ObjectPreview
type ObjectPreview struct {
Type Type `json:"type"` // Object type.
Subtype Subtype `json:"subtype,omitempty"` // Object subtype hint. Specified for object type values only.
Description string `json:"description,omitempty"` // String representation of the object.
Overflow bool `json:"overflow"` // True iff some of the properties or entries of the original object did not fit.
Properties []*PropertyPreview `json:"properties"` // List of the properties.
Entries []*EntryPreview `json:"entries,omitempty"` // List of the entries. Specified for map and set subtype values only.
}
// PropertyPreview [no description].
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#type-PropertyPreview
type PropertyPreview struct {
Name string `json:"name"` // Property name.
Type Type `json:"type"` // Object type. Accessor means that the property itself is an accessor property.
Value string `json:"value,omitempty"` // User-friendly property value string.
ValuePreview *ObjectPreview `json:"valuePreview,omitempty"` // Nested value preview.
Subtype Subtype `json:"subtype,omitempty"` // Object subtype hint. Specified for object type values only.
}
// EntryPreview [no description].
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#type-EntryPreview
type EntryPreview struct {
Key *ObjectPreview `json:"key,omitempty"` // Preview of the key. Specified for map-like collection entries.
Value *ObjectPreview `json:"value"` // Preview of the value.
}
// PropertyDescriptor object property descriptor.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#type-PropertyDescriptor
type PropertyDescriptor struct {
Name string `json:"name"` // Property name or symbol description.
Value *RemoteObject `json:"value,omitempty"` // The value associated with the property.
Writable bool `json:"writable,omitempty"` // True if the value associated with the property may be changed (data descriptors only).
Get *RemoteObject `json:"get,omitempty"` // A function which serves as a getter for the property, or undefined if there is no getter (accessor descriptors only).
Set *RemoteObject `json:"set,omitempty"` // A function which serves as a setter for the property, or undefined if there is no setter (accessor descriptors only).
Configurable bool `json:"configurable"` // True if the type of this property descriptor may be changed and if the property may be deleted from the corresponding object.
Enumerable bool `json:"enumerable"` // True if this property shows up during enumeration of the properties on the corresponding object.
WasThrown bool `json:"wasThrown,omitempty"` // True if the result was thrown during the evaluation.
IsOwn bool `json:"isOwn,omitempty"` // True if the property is owned for the object.
Symbol *RemoteObject `json:"symbol,omitempty"` // Property symbol object, if the property is of the symbol type.
}
// InternalPropertyDescriptor object internal property descriptor. This
// property isn't normally visible in JavaScript code.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#type-InternalPropertyDescriptor
type InternalPropertyDescriptor struct {
Name string `json:"name"` // Conventional property name.
Value *RemoteObject `json:"value,omitempty"` // The value associated with the property.
}
// PrivatePropertyDescriptor object private field descriptor.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#type-PrivatePropertyDescriptor
type PrivatePropertyDescriptor struct {
Name string `json:"name"` // Private property name.
Value *RemoteObject `json:"value"` // The value associated with the private property.
}
// CallArgument represents function call argument. Either remote object id
// objectId, primitive value, unserializable primitive value or neither of (for
// undefined) them should be specified.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#type-CallArgument
type CallArgument struct {
Value easyjson.RawMessage `json:"value,omitempty"` // Primitive value or serializable javascript object.
UnserializableValue UnserializableValue `json:"unserializableValue,omitempty"` // Primitive value which can not be JSON-stringified.
ObjectID RemoteObjectID `json:"objectId,omitempty"` // Remote object handle.
}
// ExecutionContextID ID of an execution context.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#type-ExecutionContextId
type ExecutionContextID int64
// Int64 returns the ExecutionContextID as int64 value.
func (t ExecutionContextID) Int64() int64 {
return int64(t)
}
// ExecutionContextDescription description of an isolated world.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#type-ExecutionContextDescription
type ExecutionContextDescription struct {
ID ExecutionContextID `json:"id"` // Unique id of the execution context. It can be used to specify in which execution context script evaluation should be performed.
Origin string `json:"origin"` // Execution context origin.
Name string `json:"name"` // Human readable name describing given context.
AuxData easyjson.RawMessage `json:"auxData,omitempty"`
}
// ExceptionDetails detailed information about exception (or error) that was
// thrown during script compilation or execution.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#type-ExceptionDetails
type ExceptionDetails struct {
ExceptionID int64 `json:"exceptionId"` // Exception id.
Text string `json:"text"` // Exception text, which should be used together with exception object when available.
LineNumber int64 `json:"lineNumber"` // Line number of the exception location (0-based).
ColumnNumber int64 `json:"columnNumber"` // Column number of the exception location (0-based).
ScriptID ScriptID `json:"scriptId,omitempty"` // Script ID of the exception location.
URL string `json:"url,omitempty"` // URL of the exception location, to be used when the script was not reported.
StackTrace *StackTrace `json:"stackTrace,omitempty"` // JavaScript stack trace if available.
Exception *RemoteObject `json:"exception,omitempty"` // Exception object if available.
ExecutionContextID ExecutionContextID `json:"executionContextId,omitempty"` // Identifier of the context where exception happened.
}
// Error satisfies the error interface.
func (e *ExceptionDetails) Error() string {
// TODO: watch script parsed events and match the ExceptionDetails.ScriptID
// to the name/location of the actual code and display here
return fmt.Sprintf("encountered exception '%s' (%d:%d)", e.Text, e.LineNumber, e.ColumnNumber)
}
// Timestamp number of milliseconds since epoch.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#type-Timestamp
type Timestamp time.Time
// Time returns the Timestamp as time.Time value.
func (t Timestamp) Time() time.Time {
return time.Time(t)
}
// MarshalEasyJSON satisfies easyjson.Marshaler.
func (t Timestamp) MarshalEasyJSON(out *jwriter.Writer) {
v := float64(time.Time(t).UnixNano() / int64(time.Millisecond))
out.Buffer.EnsureSpace(20)
out.Buffer.Buf = strconv.AppendFloat(out.Buffer.Buf, v, 'f', -1, 64)
}
// MarshalJSON satisfies json.Marshaler.
func (t Timestamp) MarshalJSON() ([]byte, error) {
return easyjson.Marshal(t)
}
// UnmarshalEasyJSON satisfies easyjson.Unmarshaler.
func (t *Timestamp) UnmarshalEasyJSON(in *jlexer.Lexer) {
*t = Timestamp(time.Unix(0, int64(in.Float64()*float64(time.Millisecond))))
}
// UnmarshalJSON satisfies json.Unmarshaler.
func (t *Timestamp) UnmarshalJSON(buf []byte) error {
return easyjson.Unmarshal(buf, t)
}
// TimeDelta number of milliseconds.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#type-TimeDelta
type TimeDelta float64
// Float64 returns the TimeDelta as float64 value.
func (t TimeDelta) Float64() float64 {
return float64(t)
}
// CallFrame stack entry for runtime errors and assertions.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#type-CallFrame
type CallFrame struct {
FunctionName string `json:"functionName"` // JavaScript function name.
ScriptID ScriptID `json:"scriptId"` // JavaScript script id.
URL string `json:"url"` // JavaScript script name or url.
LineNumber int64 `json:"lineNumber"` // JavaScript script line number (0-based).
ColumnNumber int64 `json:"columnNumber"` // JavaScript script column number (0-based).
}
// StackTrace call frames for assertions or error messages.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#type-StackTrace
type StackTrace struct {
Description string `json:"description,omitempty"` // String label of this stack trace. For async traces this may be a name of the function that initiated the async call.
CallFrames []*CallFrame `json:"callFrames"` // JavaScript function name.
Parent *StackTrace `json:"parent,omitempty"` // Asynchronous JavaScript stack trace that preceded this stack, if available.
ParentID *StackTraceID `json:"parentId,omitempty"` // Asynchronous JavaScript stack trace that preceded this stack, if available.
}
// UniqueDebuggerID unique identifier of current debugger.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#type-UniqueDebuggerId
type UniqueDebuggerID string
// String returns the UniqueDebuggerID as string value.
func (t UniqueDebuggerID) String() string {
return string(t)
}
// StackTraceID if debuggerId is set stack trace comes from another debugger
// and can be resolved there. This allows to track cross-debugger calls. See
// Runtime.StackTrace and Debugger.paused for usages.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#type-StackTraceId
type StackTraceID struct {
ID string `json:"id"`
DebuggerID UniqueDebuggerID `json:"debuggerId,omitempty"`
}
// Type object type.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#type-type
type Type string
// String returns the Type as string value.
func (t Type) String() string {
return string(t)
}
// Type values.
const (
TypeObject Type = "object"
TypeFunction Type = "function"
TypeUndefined Type = "undefined"
TypeString Type = "string"
TypeNumber Type = "number"
TypeBoolean Type = "boolean"
TypeSymbol Type = "symbol"
TypeBigint Type = "bigint"
TypeAccessor Type = "accessor"
)
// MarshalEasyJSON satisfies easyjson.Marshaler.
func (t Type) MarshalEasyJSON(out *jwriter.Writer) {
out.String(string(t))
}
// MarshalJSON satisfies json.Marshaler.
func (t Type) MarshalJSON() ([]byte, error) {
return easyjson.Marshal(t)
}
// UnmarshalEasyJSON satisfies easyjson.Unmarshaler.
func (t *Type) UnmarshalEasyJSON(in *jlexer.Lexer) {
switch Type(in.String()) {
case TypeObject:
*t = TypeObject
case TypeFunction:
*t = TypeFunction
case TypeUndefined:
*t = TypeUndefined
case TypeString:
*t = TypeString
case TypeNumber:
*t = TypeNumber
case TypeBoolean:
*t = TypeBoolean
case TypeSymbol:
*t = TypeSymbol
case TypeBigint:
*t = TypeBigint
case TypeAccessor:
*t = TypeAccessor
default:
in.AddError(errors.New("unknown Type value"))
}
}
// UnmarshalJSON satisfies json.Unmarshaler.
func (t *Type) UnmarshalJSON(buf []byte) error {
return easyjson.Unmarshal(buf, t)
}
// Subtype object subtype hint. Specified for object type values only.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#type-subtype
type Subtype string
// String returns the Subtype as string value.
func (t Subtype) String() string {
return string(t)
}
// Subtype values.
const (
SubtypeArray Subtype = "array"
SubtypeNull Subtype = "null"
SubtypeNode Subtype = "node"
SubtypeRegexp Subtype = "regexp"
SubtypeDate Subtype = "date"
SubtypeMap Subtype = "map"
SubtypeSet Subtype = "set"
SubtypeWeakmap Subtype = "weakmap"
SubtypeWeakset Subtype = "weakset"
SubtypeIterator Subtype = "iterator"
SubtypeGenerator Subtype = "generator"
SubtypeError Subtype = "error"
SubtypeProxy Subtype = "proxy"
SubtypePromise Subtype = "promise"
SubtypeTypedarray Subtype = "typedarray"
SubtypeArraybuffer Subtype = "arraybuffer"
SubtypeDataview Subtype = "dataview"
)
// MarshalEasyJSON satisfies easyjson.Marshaler.
func (t Subtype) MarshalEasyJSON(out *jwriter.Writer) {
out.String(string(t))
}
// MarshalJSON satisfies json.Marshaler.
func (t Subtype) MarshalJSON() ([]byte, error) {
return easyjson.Marshal(t)
}
// UnmarshalEasyJSON satisfies easyjson.Unmarshaler.
func (t *Subtype) UnmarshalEasyJSON(in *jlexer.Lexer) {
switch Subtype(in.String()) {
case SubtypeArray:
*t = SubtypeArray
case SubtypeNull:
*t = SubtypeNull
case SubtypeNode:
*t = SubtypeNode
case SubtypeRegexp:
*t = SubtypeRegexp
case SubtypeDate:
*t = SubtypeDate
case SubtypeMap:
*t = SubtypeMap
case SubtypeSet:
*t = SubtypeSet
case SubtypeWeakmap:
*t = SubtypeWeakmap
case SubtypeWeakset:
*t = SubtypeWeakset
case SubtypeIterator:
*t = SubtypeIterator
case SubtypeGenerator:
*t = SubtypeGenerator
case SubtypeError:
*t = SubtypeError
case SubtypeProxy:
*t = SubtypeProxy
case SubtypePromise:
*t = SubtypePromise
case SubtypeTypedarray:
*t = SubtypeTypedarray
case SubtypeArraybuffer:
*t = SubtypeArraybuffer
case SubtypeDataview:
*t = SubtypeDataview
default:
in.AddError(errors.New("unknown Subtype value"))
}
}
// UnmarshalJSON satisfies json.Unmarshaler.
func (t *Subtype) UnmarshalJSON(buf []byte) error {
return easyjson.Unmarshal(buf, t)
}
// APIType type of the call.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#type-type
type APIType string
// String returns the APIType as string value.
func (t APIType) String() string {
return string(t)
}
// APIType values.
const (
APITypeLog APIType = "log"
APITypeDebug APIType = "debug"
APITypeInfo APIType = "info"
APITypeError APIType = "error"
APITypeWarning APIType = "warning"
APITypeDir APIType = "dir"
APITypeDirxml APIType = "dirxml"
APITypeTable APIType = "table"
APITypeTrace APIType = "trace"
APITypeClear APIType = "clear"
APITypeStartGroup APIType = "startGroup"
APITypeStartGroupCollapsed APIType = "startGroupCollapsed"
APITypeEndGroup APIType = "endGroup"
APITypeAssert APIType = "assert"
APITypeProfile APIType = "profile"
APITypeProfileEnd APIType = "profileEnd"
APITypeCount APIType = "count"
APITypeTimeEnd APIType = "timeEnd"
)
// MarshalEasyJSON satisfies easyjson.Marshaler.
func (t APIType) MarshalEasyJSON(out *jwriter.Writer) {
out.String(string(t))
}
// MarshalJSON satisfies json.Marshaler.
func (t APIType) MarshalJSON() ([]byte, error) {
return easyjson.Marshal(t)
}
// UnmarshalEasyJSON satisfies easyjson.Unmarshaler.
func (t *APIType) UnmarshalEasyJSON(in *jlexer.Lexer) {
switch APIType(in.String()) {
case APITypeLog:
*t = APITypeLog
case APITypeDebug:
*t = APITypeDebug
case APITypeInfo:
*t = APITypeInfo
case APITypeError:
*t = APITypeError
case APITypeWarning:
*t = APITypeWarning
case APITypeDir:
*t = APITypeDir
case APITypeDirxml:
*t = APITypeDirxml
case APITypeTable:
*t = APITypeTable
case APITypeTrace:
*t = APITypeTrace
case APITypeClear:
*t = APITypeClear
case APITypeStartGroup:
*t = APITypeStartGroup
case APITypeStartGroupCollapsed:
*t = APITypeStartGroupCollapsed
case APITypeEndGroup:
*t = APITypeEndGroup
case APITypeAssert:
*t = APITypeAssert
case APITypeProfile:
*t = APITypeProfile
case APITypeProfileEnd:
*t = APITypeProfileEnd
case APITypeCount:
*t = APITypeCount
case APITypeTimeEnd:
*t = APITypeTimeEnd
default:
in.AddError(errors.New("unknown APIType value"))
}
}
// UnmarshalJSON satisfies json.Unmarshaler.
func (t *APIType) UnmarshalJSON(buf []byte) error {
return easyjson.Unmarshal(buf, t)
}