-
Notifications
You must be signed in to change notification settings - Fork 11
[kernel-1310] browser telemetry - CLI integration #168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 39 commits
e424621
baa3558
6f8006f
4540e3f
e97378f
a4d8cd9
1ccc8c9
9e4ef95
116851b
bd84338
832790f
ba5ea92
1cbcb11
3ac29ac
fc4affb
87922b3
4f4a8ae
c179c81
dac6596
54a7620
4a0ba01
373f618
1c71174
a213e33
92c6805
6df0ac3
26e6b5b
c30484a
93d3168
83b627f
55c83c9
74d2311
79a07d3
c745206
c884b5f
630d0b6
035bb9a
351e6b2
5bfd91b
0e33313
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -175,6 +175,7 @@ type BrowsersCreateInput struct { | |
| StartURL string | ||
| Extensions []string | ||
| Viewport string | ||
| Telemetry string | ||
| Output string | ||
| } | ||
|
|
||
|
|
@@ -202,6 +203,7 @@ type BrowsersUpdateInput struct { | |
| ProfileSaveChanges BoolFlag | ||
| Viewport string | ||
| Force bool | ||
| Telemetry string | ||
| Output string | ||
| } | ||
|
|
||
|
|
@@ -215,6 +217,7 @@ type BrowsersCmd struct { | |
| logs BrowserLogService | ||
| computer BrowserComputerService | ||
| playwright BrowserPlaywrightService | ||
| telemetry BrowserTelemetryService | ||
| } | ||
|
|
||
| type BrowsersListInput struct { | ||
|
|
@@ -331,9 +334,6 @@ func (b BrowsersCmd) Create(ctx context.Context, in BrowsersCreateInput) error { | |
| return err | ||
| } | ||
|
|
||
| if in.Output != "json" { | ||
| pterm.Info.Println("Creating browser session...") | ||
| } | ||
| params := kernel.BrowserNewParams{} | ||
| if in.TimeoutSeconds > 0 { | ||
| params.TimeoutSeconds = kernel.Opt(int64(in.TimeoutSeconds)) | ||
|
|
@@ -410,6 +410,17 @@ func (b BrowsersCmd) Create(ctx context.Context, in BrowsersCreateInput) error { | |
| } | ||
| } | ||
|
|
||
| if in.Telemetry != "" { | ||
| t, err := buildNewTelemetryParam(in.Telemetry) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| params.Telemetry = t | ||
| } | ||
|
|
||
| if in.Output != "json" { | ||
| pterm.Info.Println("Creating browser session...") | ||
| } | ||
| browser, err := b.browsers.New(ctx, params) | ||
| if err != nil { | ||
| return util.CleanedUpSdkError{Err: err} | ||
|
|
@@ -576,8 +587,8 @@ func (b BrowsersCmd) Update(ctx context.Context, in BrowsersUpdateInput) error { | |
| } | ||
|
|
||
| // Validate that at least one update option is provided | ||
| if !hasProxyChange && !hasProfileChange && !hasViewportChange { | ||
| return fmt.Errorf("must specify at least one of: --proxy-id, --clear-proxy, --profile-id, --profile-name, or --viewport") | ||
| if !hasProxyChange && !hasProfileChange && !hasViewportChange && in.Telemetry == "" { | ||
| return fmt.Errorf("must specify at least one of: --proxy-id, --clear-proxy, --profile-id, --profile-name, --viewport, or --telemetry") | ||
| } | ||
|
|
||
| params := kernel.BrowserUpdateParams{} | ||
|
|
@@ -602,6 +613,15 @@ func (b BrowsersCmd) Update(ctx context.Context, in BrowsersUpdateInput) error { | |
| } | ||
| } | ||
|
|
||
| // Handle telemetry changes | ||
| if in.Telemetry != "" { | ||
| t, err := buildUpdateTelemetryParam(in.Telemetry) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| params.Telemetry = t | ||
| } | ||
|
|
||
| // Handle viewport changes | ||
| if hasViewportChange { | ||
| width, height, refreshRate, err := parseViewport(in.Viewport) | ||
|
|
@@ -2229,6 +2249,7 @@ func init() { | |
| browsersUpdateCmd.Flags().Bool("save-changes", false, "If set, save changes back to the profile when the session ends") | ||
| browsersUpdateCmd.Flags().String("viewport", "", "Browser viewport size (e.g., 1920x1080@25). Supported: 2560x1440@10, 1920x1080@25, 1920x1200@25, 1440x900@25, 1024x768@60, 1200x800@60, 1280x800@60") | ||
| browsersUpdateCmd.Flags().Bool("force", false, "Force viewport resize even when a live view or recording/replay is active") | ||
| browsersUpdateCmd.Flags().String("telemetry", "", "Update telemetry: --telemetry=all to enable, --telemetry=off to disable, --telemetry=network=on,page=off for per-category") | ||
|
|
||
| browsersCmd.AddCommand(browsersListCmd) | ||
| browsersCmd.AddCommand(browsersCreateCmd) | ||
|
|
@@ -2494,6 +2515,7 @@ func init() { | |
| browsersCreateCmd.Flags().Bool("viewport-interactive", false, "Interactively select viewport size from list") | ||
| browsersCreateCmd.Flags().String("pool-id", "", "Browser pool ID to acquire from (mutually exclusive with --pool-name)") | ||
| browsersCreateCmd.Flags().String("pool-name", "", "Browser pool name to acquire from (mutually exclusive with --pool-id)") | ||
| browsersCreateCmd.Flags().String("telemetry", "", "Configure telemetry: --telemetry=all to enable, --telemetry=off to disable, --telemetry=network=on,page=off for per-category") | ||
|
|
||
| // curl | ||
| curlCmd := &cobra.Command{ | ||
|
|
@@ -2520,6 +2542,15 @@ followed automatically by Chromium.`, | |
| curlCmd.Flags().BoolP("silent", "s", false, "Suppress progress output") | ||
| browsersCmd.AddCommand(curlCmd) | ||
|
|
||
| telemetryRoot := &cobra.Command{Use: "telemetry", Short: "Browser telemetry operations"} | ||
| telemetryStream := &cobra.Command{Use: "stream <id>", Short: "Stream live telemetry events", Args: cobra.ExactArgs(1), RunE: runBrowsersTelemetryStream} | ||
| telemetryStream.Flags().StringSlice("categories", []string{}, "Filter by API event category (api,console,interaction,network,page,system); system covers monitor_* and cdp_* events") | ||
| telemetryStream.Flags().StringSlice("types", []string{}, "Filter by event type (e.g. network_response,console_error)") | ||
| telemetryStream.Flags().Int64("seq", -1, "Resume stream from sequence number (Last-Event-ID); --seq=1 replays from the first event, default -1 streams from now") | ||
| telemetryStream.Flags().StringP("output", "o", "", "Output format: json for newline-delimited JSON envelopes") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inline output flag instead of shared helperLow Severity The Triggered by learned rule: Use shared JSON output helpers in CLI commands Reviewed by Cursor Bugbot for commit 5bfd91b. Configure here. |
||
| telemetryRoot.AddCommand(telemetryStream) | ||
| browsersCmd.AddCommand(telemetryRoot) | ||
|
|
||
| // no flags for view; it takes a single positional argument | ||
| } | ||
|
|
||
|
|
@@ -2563,6 +2594,7 @@ func runBrowsersCreate(cmd *cobra.Command, args []string) error { | |
| viewportInteractive, _ := cmd.Flags().GetBool("viewport-interactive") | ||
| poolID, _ := cmd.Flags().GetString("pool-id") | ||
| poolName, _ := cmd.Flags().GetString("pool-name") | ||
| telemetry, _ := cmd.Flags().GetString("telemetry") | ||
| output, _ := cmd.Flags().GetString("output") | ||
|
|
||
| if poolID != "" && poolName != "" { | ||
|
|
@@ -2672,6 +2704,7 @@ func runBrowsersCreate(cmd *cobra.Command, args []string) error { | |
| StartURL: startURL, | ||
| Extensions: extensions, | ||
| Viewport: viewport, | ||
| Telemetry: telemetry, | ||
| Output: output, | ||
| } | ||
|
|
||
|
|
@@ -2730,6 +2763,7 @@ func runBrowsersUpdate(cmd *cobra.Command, args []string) error { | |
| saveChanges, _ := cmd.Flags().GetBool("save-changes") | ||
| viewport, _ := cmd.Flags().GetString("viewport") | ||
| force, _ := cmd.Flags().GetBool("force") | ||
| telemetry, _ := cmd.Flags().GetString("telemetry") | ||
|
|
||
| svc := client.Browsers | ||
| b := BrowsersCmd{browsers: &svc} | ||
|
|
@@ -2742,6 +2776,7 @@ func runBrowsersUpdate(cmd *cobra.Command, args []string) error { | |
| ProfileSaveChanges: BoolFlag{Set: cmd.Flags().Changed("save-changes"), Value: saveChanges}, | ||
| Viewport: viewport, | ||
| Force: force, | ||
| Telemetry: telemetry, | ||
| Output: out, | ||
| }) | ||
| } | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wording is an off-by-one, and it leaves
--seq=0as a silent no-op.Resume is strictly after the Last-Event-ID (
--seq=N→ events with seq > N), confirmed live:--seq=1→ min seq 2,--seq=2→ 3,--seq=100→ 101. So--seq=1does not replay the first event (seq 1), and no value does. The same wording is in the error string (browsers_telemetry.go:150) andREADME.md:306.Separately,
--seq=0is accepted by the>= 0validation, sendsLast-Event-ID="0", and the server replays nothing — a silent empty stream with no diagnostic.0is no longer mentioned in any docs, yetTestTelemetryStream_SeqZeroSetsLastEventIDlocks in the0→"0"behavior.Suggestion: reword to "earliest available / lowest retained sequence" (drop "first event"), and either reject/warn on
--seq=0or map it to the earliest retained seq. Minor: the bound copy says "must be >= 0" while the guard is< -1, so-1is actually permitted.