-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbrowsertelemetry.go
More file actions
3034 lines (2831 loc) · 126 KB
/
Copy pathbrowsertelemetry.go
File metadata and controls
3034 lines (2831 loc) · 126 KB
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
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package kernel
import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"net/url"
"slices"
"github.com/kernel/kernel-go-sdk/internal/apijson"
"github.com/kernel/kernel-go-sdk/internal/apiquery"
"github.com/kernel/kernel-go-sdk/internal/requestconfig"
"github.com/kernel/kernel-go-sdk/option"
"github.com/kernel/kernel-go-sdk/packages/pagination"
"github.com/kernel/kernel-go-sdk/packages/param"
"github.com/kernel/kernel-go-sdk/packages/respjson"
"github.com/kernel/kernel-go-sdk/packages/ssestream"
"github.com/kernel/kernel-go-sdk/shared/constant"
)
// Stream live telemetry events from a browser session, and manage the destinations
// sessions export them to.
//
// BrowserTelemetryService contains methods and other services that help with
// interacting with the kernel API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewBrowserTelemetryService] method instead.
type BrowserTelemetryService struct {
Options []option.RequestOption
}
// NewBrowserTelemetryService generates a new service that applies the given
// options to each request. These options are applied after the parent client's
// options (if there is one), and before any request-specific options.
func NewBrowserTelemetryService(opts ...option.RequestOption) (r BrowserTelemetryService) {
r = BrowserTelemetryService{}
r.Options = opts
return
}
// Reads a page of telemetry events for the browser session. To page through
// results, pass the X-Next-Offset value from the previous response as offset and
// repeat while X-Has-More is true. Returns an empty list when telemetry data is
// unavailable.
func (r *BrowserTelemetryService) Events(ctx context.Context, id string, query BrowserTelemetryEventsParams, opts ...option.RequestOption) (res *pagination.OffsetPagination[BrowserTelemetryEventsResponse], err error) {
var raw *http.Response
opts = slices.Concat(r.Options, opts)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
if id == "" {
err = errors.New("missing required id parameter")
return nil, err
}
path := fmt.Sprintf("browsers/%s/telemetry/events", id)
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
if err != nil {
return nil, err
}
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}
// Reads a page of telemetry events for the browser session. To page through
// results, pass the X-Next-Offset value from the previous response as offset and
// repeat while X-Has-More is true. Returns an empty list when telemetry data is
// unavailable.
func (r *BrowserTelemetryService) EventsAutoPaging(ctx context.Context, id string, query BrowserTelemetryEventsParams, opts ...option.RequestOption) *pagination.OffsetPaginationAutoPager[BrowserTelemetryEventsResponse] {
return pagination.NewOffsetPaginationAutoPager(r.Events(ctx, id, query, opts...))
}
// Streams browser telemetry events as a server-sent events (SSE) stream. The
// stream closes when the browser session terminates. Each event frame includes an
// id: field containing a monotonically increasing sequence number; pass it as
// Last-Event-ID on reconnect to resume without gaps. The event: field is never
// set; all frames carry JSON in the data: field. A keepalive comment frame is sent
// every 15 seconds when no events arrive. Returns 404 if the browser session does
// not exist. If telemetry was not enabled on the session, the stream opens but no
// events are delivered. Fresh connections only see new events; pass replay=all to
// start from the oldest retained event instead.
func (r *BrowserTelemetryService) StreamStreaming(ctx context.Context, id string, params BrowserTelemetryStreamParams, opts ...option.RequestOption) (stream *ssestream.Stream[BrowserTelemetryStreamResponse]) {
var (
raw *http.Response
err error
)
if !param.IsOmitted(params.LastEventID) {
opts = append(opts, option.WithHeader("Last-Event-ID", fmt.Sprintf("%v", params.LastEventID.Value)))
}
opts = slices.Concat(r.Options, opts)
opts = append([]option.RequestOption{option.WithHeader("Accept", "text/event-stream")}, opts...)
if id == "" {
err = errors.New("missing required id parameter")
return ssestream.NewStream[BrowserTelemetryStreamResponse](nil, err)
}
path := fmt.Sprintf("browsers/%s/telemetry/stream", id)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, params, &raw, opts...)
return ssestream.NewStream[BrowserTelemetryStreamResponse](ssestream.NewDecoder(raw), err)
}
// An agent-driven HTTP call handled by the in-VM API server.
type BrowserAPICallEvent struct {
Category constant.Control `json:"category" default:"control"`
// Provenance metadata identifying which producer emitted the event.
Source BrowserEventSource `json:"source" api:"required"`
// Event timestamp in Unix microseconds.
Ts int64 `json:"ts" api:"required"`
Type constant.APICall `json:"type" default:"api_call"`
Data BrowserAPICallEventData `json:"data"`
// True if the data field was truncated due to size limits.
Truncated bool `json:"truncated"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Category respjson.Field
Source respjson.Field
Ts respjson.Field
Type respjson.Field
Data respjson.Field
Truncated respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BrowserAPICallEvent) RawJSON() string { return r.JSON.raw }
func (r *BrowserAPICallEvent) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BrowserAPICallEventData struct {
// Wall-clock duration of the handler in milliseconds.
DurationMs float64 `json:"duration_ms" api:"required"`
// OpenAPI operationId of the matched route (e.g. processExec, takeScreenshot).
OperationID string `json:"operation_id" api:"required"`
// Per-request identifier from the in-VM API request middleware.
RequestID string `json:"request_id" api:"required"`
// HTTP response status code.
Status int64 `json:"status" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
DurationMs respjson.Field
OperationID respjson.Field
RequestID respjson.Field
Status respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BrowserAPICallEventData) RawJSON() string { return r.JSON.raw }
func (r *BrowserAPICallEventData) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// CDP Runtime.StackTrace representing the JavaScript call stack at the time of an
// event. Fields use CDP naming conventions rather than snake_case to match the
// Chrome DevTools Protocol wire format.
type BrowserCallStack struct {
// Ordered list of call frames, outermost first.
CallFrames []BrowserCallStackCallFrame `json:"callFrames" api:"required"`
// Optional label for the stack trace (e.g. async cause).
Description string `json:"description"`
// Parent stack trace for async stacks.
Parent *BrowserCallStack `json:"parent"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
CallFrames respjson.Field
Description respjson.Field
Parent respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BrowserCallStack) RawJSON() string { return r.JSON.raw }
func (r *BrowserCallStack) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BrowserCallStackCallFrame struct {
// Zero-based column number within the line.
ColumnNumber int64 `json:"columnNumber" api:"required"`
// JavaScript function name, or empty string for anonymous functions.
FunctionName string `json:"functionName" api:"required"`
// Zero-based line number within the script.
LineNumber int64 `json:"lineNumber" api:"required"`
// CDP script identifier.
ScriptID string `json:"scriptId" api:"required"`
// URL or name of the script file.
URL string `json:"url" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ColumnNumber respjson.Field
FunctionName respjson.Field
LineNumber respjson.Field
ScriptID respjson.Field
URL respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BrowserCallStackCallFrame) RawJSON() string { return r.JSON.raw }
func (r *BrowserCallStackCallFrame) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// A captcha solve attempt reached a terminal outcome.
type BrowserCaptchaSolveResultEvent struct {
Category constant.Captcha `json:"category" default:"captcha"`
// Provenance metadata identifying which producer emitted the event.
Source BrowserEventSource `json:"source" api:"required"`
// Event timestamp in Unix microseconds.
Ts int64 `json:"ts" api:"required"`
Type constant.CaptchaSolveResult `json:"type" default:"captcha_solve_result"`
Data BrowserCaptchaSolveResultEventData `json:"data"`
// True if the data field was truncated due to size limits.
Truncated bool `json:"truncated"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Category respjson.Field
Source respjson.Field
Ts respjson.Field
Type respjson.Field
Data respjson.Field
Truncated respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BrowserCaptchaSolveResultEvent) RawJSON() string { return r.JSON.raw }
func (r *BrowserCaptchaSolveResultEvent) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BrowserCaptchaSolveResultEventData struct {
// Captcha vendor family. Provider-specific task names are normalized into this
// set; anything not covered is reported as other.
//
// Any of "hcaptcha", "recaptcha_v2", "recaptcha_v3", "turnstile", "geetest",
// "other".
CaptchaType string `json:"captcha_type" api:"required"`
// Wall-clock duration from solve start to terminal outcome.
DurationMs float64 `json:"duration_ms" api:"required"`
// Terminal outcome. success: solver returned a usable solution. failure: solver
// returned an error (see error_code). timeout: solver did not return within the
// caller's wait budget. abandoned: caller cancelled or the page navigated away
// mid-solve.
//
// Any of "success", "failure", "timeout", "abandoned".
Status string `json:"status" api:"required"`
// Solver-specific error code on failure (e.g. ERROR_CAPTCHA_UNSOLVABLE). Absent on
// success.
ErrorCode string `json:"error_code"`
// Solver-assigned identifier. Opaque, useful for support cross-references.
TaskID string `json:"task_id"`
// Host of the page where the captcha was solved.
WebsiteHost string `json:"website_host"`
// Path of the page where the captcha was solved. Query string excluded.
WebsitePath string `json:"website_path"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
CaptchaType respjson.Field
DurationMs respjson.Field
Status respjson.Field
ErrorCode respjson.Field
TaskID respjson.Field
WebsiteHost respjson.Field
WebsitePath respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BrowserCaptchaSolveResultEventData) RawJSON() string { return r.JSON.raw }
func (r *BrowserCaptchaSolveResultEventData) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// An external client (e.g. customer SDK, Playwright, Puppeteer) connected to the
// CDP WebSocket proxy on this VM.
type BrowserCdpConnectEvent struct {
Category constant.Connection `json:"category" default:"connection"`
// Provenance metadata identifying which producer emitted the event.
Source BrowserEventSource `json:"source" api:"required"`
// Event timestamp in Unix microseconds.
Ts int64 `json:"ts" api:"required"`
Type constant.CdpConnect `json:"type" default:"cdp_connect"`
// True if the data field was truncated due to size limits.
Truncated bool `json:"truncated"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Category respjson.Field
Source respjson.Field
Ts respjson.Field
Type respjson.Field
Truncated respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BrowserCdpConnectEvent) RawJSON() string { return r.JSON.raw }
func (r *BrowserCdpConnectEvent) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// An external client disconnected from the CDP WebSocket proxy on this VM. Pair
// with the immediately preceding cdp_connect on the same stream.
type BrowserCdpDisconnectEvent struct {
Category constant.Connection `json:"category" default:"connection"`
// Provenance metadata identifying which producer emitted the event.
Source BrowserEventSource `json:"source" api:"required"`
// Event timestamp in Unix microseconds.
Ts int64 `json:"ts" api:"required"`
Type constant.CdpDisconnect `json:"type" default:"cdp_disconnect"`
Data BrowserCdpDisconnectEventData `json:"data"`
// True if the data field was truncated due to size limits.
Truncated bool `json:"truncated"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Category respjson.Field
Source respjson.Field
Ts respjson.Field
Type respjson.Field
Data respjson.Field
Truncated respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BrowserCdpDisconnectEvent) RawJSON() string { return r.JSON.raw }
func (r *BrowserCdpDisconnectEvent) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BrowserCdpDisconnectEventData struct {
// Wall-clock duration of the connection in milliseconds.
DurationMs float64 `json:"duration_ms" api:"required"`
// Number of CDP messages relayed across the connection in either direction.
MessageCount int64 `json:"message_count" api:"required"`
// Why the connection ended. client_close: the client initiated the close.
// upstream_changed: Chromium restarted mid-session and the proxy tore down so the
// client could reconnect against the new upstream. upstream_error: upstream dial
// or message pump errored. context_cancelled: the request context was cancelled
// (typically server shutdown).
//
// Any of "client_close", "upstream_changed", "upstream_error",
// "context_cancelled".
Reason string `json:"reason" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
DurationMs respjson.Field
MessageCount respjson.Field
Reason respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BrowserCdpDisconnectEventData) RawJSON() string { return r.JSON.raw }
func (r *BrowserCdpDisconnectEventData) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// A browser console error or uncaught JavaScript exception event. Emitted from two
// distinct CDP sources with different data shapes. Runtime.consoleAPICalled
// (console.error calls) produces level, text, args, and stack_trace.
// Runtime.exceptionThrown (uncaught exceptions) produces text, line, column,
// source_url, and stack_trace. Fields not applicable to the source are absent.
type BrowserConsoleErrorEvent struct {
Category constant.Console `json:"category" default:"console"`
// Provenance metadata identifying which producer emitted the event.
Source BrowserEventSource `json:"source" api:"required"`
// Event timestamp in Unix microseconds.
Ts int64 `json:"ts" api:"required"`
Type constant.ConsoleError `json:"type" default:"console_error"`
// Browser event context stamped by the browser monitor onto all CDP-sourced
// events. Identifies the target, frame, and navigation epoch in which the event
// occurred.
Data BrowserConsoleErrorEventData `json:"data"`
// True if the data field was truncated due to size limits.
Truncated bool `json:"truncated"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Category respjson.Field
Source respjson.Field
Ts respjson.Field
Type respjson.Field
Data respjson.Field
Truncated respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BrowserConsoleErrorEvent) RawJSON() string { return r.JSON.raw }
func (r *BrowserConsoleErrorEvent) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Browser event context stamped by the browser monitor onto all CDP-sourced
// events. Identifies the target, frame, and navigation epoch in which the event
// occurred.
type BrowserConsoleErrorEventData struct {
// Human-readable error text, as the browser console would display it. For
// console.error() calls, the first argument coerced to a string. For uncaught
// exceptions, the prefix and error message, e.g. "Uncaught Error: boom" or
// "Uncaught (in promise) TypeError: x is not a function".
Text string `json:"text" api:"required"`
// All console arguments coerced to strings. Present only when sourced from
// Runtime.consoleAPICalled.
Args []string `json:"args"`
// Column number in the script where the exception was thrown. Present only when
// sourced from Runtime.exceptionThrown.
Column int64 `json:"column"`
// CDP console type value, always "error". Present only when sourced from
// Runtime.consoleAPICalled.
Level string `json:"level"`
// Line number in the script where the exception was thrown. Present only when
// sourced from Runtime.exceptionThrown.
Line int64 `json:"line"`
// URL of the script file that threw the exception. Present only when sourced from
// Runtime.exceptionThrown.
SourceURL string `json:"source_url"`
// CDP Runtime.StackTrace representing the JavaScript call stack at the time of an
// event. Fields use CDP naming conventions rather than snake_case to match the
// Chrome DevTools Protocol wire format.
StackTrace BrowserCallStack `json:"stack_trace"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Text respjson.Field
Args respjson.Field
Column respjson.Field
Level respjson.Field
Line respjson.Field
SourceURL respjson.Field
StackTrace respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
BrowserEventContext
}
// Returns the unmodified JSON received from the API
func (r BrowserConsoleErrorEventData) RawJSON() string { return r.JSON.raw }
func (r *BrowserConsoleErrorEventData) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// A browser console log event (console.log, console.info, console.warn, etc.).
type BrowserConsoleLogEvent struct {
Category constant.Console `json:"category" default:"console"`
// Provenance metadata identifying which producer emitted the event.
Source BrowserEventSource `json:"source" api:"required"`
// Event timestamp in Unix microseconds.
Ts int64 `json:"ts" api:"required"`
Type constant.ConsoleLog `json:"type" default:"console_log"`
// Browser event context stamped by the browser monitor onto all CDP-sourced
// events. Identifies the target, frame, and navigation epoch in which the event
// occurred.
Data BrowserConsoleLogEventData `json:"data"`
// True if the data field was truncated due to size limits.
Truncated bool `json:"truncated"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Category respjson.Field
Source respjson.Field
Ts respjson.Field
Type respjson.Field
Data respjson.Field
Truncated respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BrowserConsoleLogEvent) RawJSON() string { return r.JSON.raw }
func (r *BrowserConsoleLogEvent) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Browser event context stamped by the browser monitor onto all CDP-sourced
// events. Identifies the target, frame, and navigation epoch in which the event
// occurred.
type BrowserConsoleLogEventData struct {
// All console arguments coerced to strings.
Args []string `json:"args"`
// CDP Runtime.consoleAPICalled type, passed through unfiltered from Chrome. error
// is routed to console_error events instead; all other CDP console types appear
// here. See CDP spec for the full enum.
Level string `json:"level"`
// CDP Runtime.StackTrace representing the JavaScript call stack at the time of an
// event. Fields use CDP naming conventions rather than snake_case to match the
// Chrome DevTools Protocol wire format.
StackTrace BrowserCallStack `json:"stack_trace"`
// First console argument coerced to string.
Text string `json:"text"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Args respjson.Field
Level respjson.Field
StackTrace respjson.Field
Text respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
BrowserEventContext
}
// Returns the unmodified JSON received from the API
func (r BrowserConsoleLogEventData) RawJSON() string { return r.JSON.raw }
func (r *BrowserConsoleLogEventData) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Browser event context stamped by the browser monitor onto all CDP-sourced
// events. Identifies the target, frame, and navigation epoch in which the event
// occurred.
type BrowserEventContext struct {
// CDP frame identifier within the target.
FrameID string `json:"frame_id"`
// CDP document loader identifier, reset on each navigation.
LoaderID string `json:"loader_id"`
// Monotonically increasing navigation sequence number, incremented on each
// top-level navigation within the target.
NavSeq int64 `json:"nav_seq"`
// CDP session identifier for the target connection.
SessionID string `json:"session_id"`
// Browser target identifier (stable across navigations within a tab).
TargetID string `json:"target_id"`
// CDP target type of the page that produced the event.
//
// Any of "page", "background_page", "service_worker", "shared_worker", "other".
TargetType BrowserEventContextTargetType `json:"target_type"`
// URL relevant to this event — page URL for navigation and page events, request
// URL for network events.
URL string `json:"url"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
FrameID respjson.Field
LoaderID respjson.Field
NavSeq respjson.Field
SessionID respjson.Field
TargetID respjson.Field
TargetType respjson.Field
URL respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BrowserEventContext) RawJSON() string { return r.JSON.raw }
func (r *BrowserEventContext) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// CDP target type of the page that produced the event.
type BrowserEventContextTargetType string
const (
BrowserEventContextTargetTypePage BrowserEventContextTargetType = "page"
BrowserEventContextTargetTypeBackgroundPage BrowserEventContextTargetType = "background_page"
BrowserEventContextTargetTypeServiceWorker BrowserEventContextTargetType = "service_worker"
BrowserEventContextTargetTypeSharedWorker BrowserEventContextTargetType = "shared_worker"
BrowserEventContextTargetTypeOther BrowserEventContextTargetType = "other"
)
// Provenance metadata identifying which producer emitted the event.
type BrowserEventSource struct {
// Event producer. cdp: Chrome DevTools Protocol events from the browser.
// kernel_api: Kernel API server. extension: injected Chrome extension.
// local_process: system process running alongside the browser.
//
// Any of "cdp", "kernel_api", "extension", "local_process".
Kind BrowserEventSourceKind `json:"kind" api:"required"`
// Producer-specific event name (e.g. Runtime.consoleAPICalled for CDP-sourced
// console events, Runtime.exceptionThrown for uncaught exceptions).
Event string `json:"event"`
// Producer-specific context (e.g. CDP target/session/frame IDs).
Metadata map[string]string `json:"metadata"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Kind respjson.Field
Event respjson.Field
Metadata respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BrowserEventSource) RawJSON() string { return r.JSON.raw }
func (r *BrowserEventSource) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Event producer. cdp: Chrome DevTools Protocol events from the browser.
// kernel_api: Kernel API server. extension: injected Chrome extension.
// local_process: system process running alongside the browser.
type BrowserEventSourceKind string
const (
BrowserEventSourceKindCdp BrowserEventSourceKind = "cdp"
BrowserEventSourceKindKernelAPI BrowserEventSourceKind = "kernel_api"
BrowserEventSourceKindExtension BrowserEventSourceKind = "extension"
BrowserEventSourceKindLocalProcess BrowserEventSourceKind = "local_process"
)
type BrowserHTTPHeaders map[string]any
// A browser user click event captured via injected page script.
type BrowserInteractionClickEvent struct {
Category constant.Interaction `json:"category" default:"interaction"`
// Provenance metadata identifying which producer emitted the event.
Source BrowserEventSource `json:"source" api:"required"`
// Event timestamp in Unix microseconds.
Ts int64 `json:"ts" api:"required"`
Type constant.InteractionClick `json:"type" default:"interaction_click"`
// Browser event context stamped by the browser monitor onto all CDP-sourced
// events. Identifies the target, frame, and navigation epoch in which the event
// occurred.
Data BrowserInteractionClickEventData `json:"data"`
// True if the data field was truncated due to size limits.
Truncated bool `json:"truncated"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Category respjson.Field
Source respjson.Field
Ts respjson.Field
Type respjson.Field
Data respjson.Field
Truncated respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BrowserInteractionClickEvent) RawJSON() string { return r.JSON.raw }
func (r *BrowserInteractionClickEvent) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Browser event context stamped by the browser monitor onto all CDP-sourced
// events. Identifies the target, frame, and navigation epoch in which the event
// occurred.
type BrowserInteractionClickEventData struct {
// CSS selector path to the clicked element.
Selector string `json:"selector"`
// HTML tag name of the clicked element in uppercase (e.g. BUTTON, A, DIV).
Tag string `json:"tag"`
// Visible text content of the clicked element, trimmed.
Text string `json:"text"`
// Viewport x-coordinate of the click in CSS pixels.
X int64 `json:"x"`
// Viewport y-coordinate of the click in CSS pixels.
Y int64 `json:"y"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Selector respjson.Field
Tag respjson.Field
Text respjson.Field
X respjson.Field
Y respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
BrowserEventContext
}
// Returns the unmodified JSON received from the API
func (r BrowserInteractionClickEventData) RawJSON() string { return r.JSON.raw }
func (r *BrowserInteractionClickEventData) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// A browser keyboard event captured via injected page script.
type BrowserInteractionKeyEvent struct {
Category constant.Interaction `json:"category" default:"interaction"`
// Provenance metadata identifying which producer emitted the event.
Source BrowserEventSource `json:"source" api:"required"`
// Event timestamp in Unix microseconds.
Ts int64 `json:"ts" api:"required"`
Type constant.InteractionKey `json:"type" default:"interaction_key"`
// Browser event context stamped by the browser monitor onto all CDP-sourced
// events. Identifies the target, frame, and navigation epoch in which the event
// occurred.
Data BrowserInteractionKeyEventData `json:"data"`
// True if the data field was truncated due to size limits.
Truncated bool `json:"truncated"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Category respjson.Field
Source respjson.Field
Ts respjson.Field
Type respjson.Field
Data respjson.Field
Truncated respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BrowserInteractionKeyEvent) RawJSON() string { return r.JSON.raw }
func (r *BrowserInteractionKeyEvent) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Browser event context stamped by the browser monitor onto all CDP-sourced
// events. Identifies the target, frame, and navigation epoch in which the event
// occurred.
type BrowserInteractionKeyEventData struct {
// Key value from the KeyboardEvent (e.g. Enter, Backspace, a).
Key string `json:"key"`
// CSS selector path to the element that had focus when the key was pressed.
Selector string `json:"selector"`
// HTML tag name of the focused element in uppercase (e.g. INPUT, TEXTAREA, DIV).
Tag string `json:"tag"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Key respjson.Field
Selector respjson.Field
Tag respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
BrowserEventContext
}
// Returns the unmodified JSON received from the API
func (r BrowserInteractionKeyEventData) RawJSON() string { return r.JSON.raw }
func (r *BrowserInteractionKeyEventData) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// A browser scroll settled event emitted after scroll position stops changing,
// captured via injected page script.
type BrowserInteractionScrollSettledEvent struct {
Category constant.Interaction `json:"category" default:"interaction"`
// Provenance metadata identifying which producer emitted the event.
Source BrowserEventSource `json:"source" api:"required"`
// Event timestamp in Unix microseconds.
Ts int64 `json:"ts" api:"required"`
Type constant.InteractionScrollSettled `json:"type" default:"interaction_scroll_settled"`
// Browser event context stamped by the browser monitor onto all CDP-sourced
// events. Identifies the target, frame, and navigation epoch in which the event
// occurred.
Data BrowserInteractionScrollSettledEventData `json:"data"`
// True if the data field was truncated due to size limits.
Truncated bool `json:"truncated"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Category respjson.Field
Source respjson.Field
Ts respjson.Field
Type respjson.Field
Data respjson.Field
Truncated respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BrowserInteractionScrollSettledEvent) RawJSON() string { return r.JSON.raw }
func (r *BrowserInteractionScrollSettledEvent) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Browser event context stamped by the browser monitor onto all CDP-sourced
// events. Identifies the target, frame, and navigation epoch in which the event
// occurred.
type BrowserInteractionScrollSettledEventData struct {
// Scroll x-position at the start of the scroll gesture in CSS pixels.
FromX int64 `json:"from_x"`
// Scroll y-position at the start of the scroll gesture in CSS pixels.
FromY int64 `json:"from_y"`
// CSS selector path to the scrolled element.
TargetSelector string `json:"target_selector"`
// Final scroll x-position after the gesture settled in CSS pixels.
ToX int64 `json:"to_x"`
// Final scroll y-position after the gesture settled in CSS pixels.
ToY int64 `json:"to_y"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
FromX respjson.Field
FromY respjson.Field
TargetSelector respjson.Field
ToX respjson.Field
ToY respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
BrowserEventContext
}
// Returns the unmodified JSON received from the API
func (r BrowserInteractionScrollSettledEventData) RawJSON() string { return r.JSON.raw }
func (r *BrowserInteractionScrollSettledEventData) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// A live view client connected to the headful browser's WebRTC server. Headful
// only; not emitted for headless images.
type BrowserLiveViewConnectEvent struct {
Category constant.Connection `json:"category" default:"connection"`
// Provenance metadata identifying which producer emitted the event.
Source BrowserEventSource `json:"source" api:"required"`
// Event timestamp in Unix microseconds.
Ts int64 `json:"ts" api:"required"`
Type constant.LiveViewConnect `json:"type" default:"live_view_connect"`
Data BrowserLiveViewConnectEventData `json:"data"`
// True if the data field was truncated due to size limits.
Truncated bool `json:"truncated"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Category respjson.Field
Source respjson.Field
Ts respjson.Field
Type respjson.Field
Data respjson.Field
Truncated respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BrowserLiveViewConnectEvent) RawJSON() string { return r.JSON.raw }
func (r *BrowserLiveViewConnectEvent) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BrowserLiveViewConnectEventData struct {
// Live view session identifier. Stable across reconnects, so a transient network
// blip can emit two events with the same session_id.
SessionID string `json:"session_id" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
SessionID respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BrowserLiveViewConnectEventData) RawJSON() string { return r.JSON.raw }
func (r *BrowserLiveViewConnectEventData) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// A live view client disconnected from the headful browser's WebRTC server. Pair
// with live_view_connect by session_id.
type BrowserLiveViewDisconnectEvent struct {
Category constant.Connection `json:"category" default:"connection"`
// Provenance metadata identifying which producer emitted the event.
Source BrowserEventSource `json:"source" api:"required"`
// Event timestamp in Unix microseconds.
Ts int64 `json:"ts" api:"required"`
Type constant.LiveViewDisconnect `json:"type" default:"live_view_disconnect"`
Data BrowserLiveViewDisconnectEventData `json:"data"`
// True if the data field was truncated due to size limits.
Truncated bool `json:"truncated"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Category respjson.Field
Source respjson.Field
Ts respjson.Field
Type respjson.Field
Data respjson.Field
Truncated respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BrowserLiveViewDisconnectEvent) RawJSON() string { return r.JSON.raw }
func (r *BrowserLiveViewDisconnectEvent) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BrowserLiveViewDisconnectEventData struct {
// Wall-clock duration of the connection in milliseconds.
DurationMs float64 `json:"duration_ms" api:"required"`
// Live view session identifier; matches the corresponding live_view_connect event.
SessionID string `json:"session_id" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
DurationMs respjson.Field
SessionID respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BrowserLiveViewDisconnectEventData) RawJSON() string { return r.JSON.raw }
func (r *BrowserLiveViewDisconnectEventData) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// The CDP connection to Chrome was lost. Telemetry events may be dropped until
// monitor_reconnected arrives. Treat any in-progress computed state (network_idle,
// page_layout_settled) as unreliable until then.
type BrowserMonitorDisconnectedEvent struct {
Category constant.Monitor `json:"category" default:"monitor"`
// Provenance metadata identifying which producer emitted the event.
Source BrowserEventSource `json:"source" api:"required"`
// Event timestamp in Unix microseconds.
Ts int64 `json:"ts" api:"required"`
Type constant.MonitorDisconnected `json:"type" default:"monitor_disconnected"`
Data BrowserMonitorDisconnectedEventData `json:"data"`
// True if the data field was truncated due to size limits.
Truncated bool `json:"truncated"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Category respjson.Field
Source respjson.Field
Ts respjson.Field
Type respjson.Field
Data respjson.Field
Truncated respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BrowserMonitorDisconnectedEvent) RawJSON() string { return r.JSON.raw }
func (r *BrowserMonitorDisconnectedEvent) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BrowserMonitorDisconnectedEventData struct {
// Reason for the disconnection. chrome_restarted: Chrome process restarted.
//
// Any of "chrome_restarted".
Reason string `json:"reason"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Reason respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BrowserMonitorDisconnectedEventData) RawJSON() string { return r.JSON.raw }
func (r *BrowserMonitorDisconnectedEventData) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// The CDP session could not be initialized.
type BrowserMonitorInitFailedEvent struct {
Category constant.Monitor `json:"category" default:"monitor"`
// Provenance metadata identifying which producer emitted the event.
Source BrowserEventSource `json:"source" api:"required"`
// Event timestamp in Unix microseconds.
Ts int64 `json:"ts" api:"required"`
Type constant.MonitorInitFailed `json:"type" default:"monitor_init_failed"`
Data BrowserMonitorInitFailedEventData `json:"data"`
// True if the data field was truncated due to size limits.
Truncated bool `json:"truncated"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Category respjson.Field
Source respjson.Field
Ts respjson.Field
Type respjson.Field
Data respjson.Field
Truncated respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}