@@ -193,8 +193,8 @@ type BrowsersCreateInput struct {
193193 StartURL string
194194 Extensions []string
195195 Viewport string
196- TelemetryEnabled bool
197- Output string
196+ TelemetryEnabled bool
197+ Output string
198198}
199199
200200type BrowsersDeleteInput struct {
@@ -234,6 +234,17 @@ type BrowsersTelemetryStopInput struct {
234234 Output string
235235}
236236
237+ type BrowsersTelemetrySetInput struct {
238+ Identifier string
239+ Categories string // e.g. "network=on,page=off"
240+ Output string
241+ }
242+
243+ type BrowsersTelemetryStatusInput struct {
244+ Identifier string
245+ Output string
246+ }
247+
237248type BrowsersTelemetryStreamInput struct {
238249 Identifier string
239250 Categories []string
@@ -715,6 +726,78 @@ func (b BrowsersCmd) TelemetryStop(ctx context.Context, in BrowsersTelemetryStop
715726 return nil
716727}
717728
729+ func (b BrowsersCmd ) TelemetrySet (ctx context.Context , in BrowsersTelemetrySetInput ) error {
730+ if in .Output != "" && in .Output != "json" {
731+ return fmt .Errorf ("unsupported --output value: use 'json'" )
732+ }
733+ p := kernel.BrowserTelemetryCategoriesConfigParam {}
734+ for _ , part := range strings .Split (in .Categories , "," ) {
735+ kv := strings .SplitN (strings .TrimSpace (part ), "=" , 2 )
736+ if len (kv ) != 2 {
737+ return fmt .Errorf ("invalid category assignment %q: expected name=on or name=off" , part )
738+ }
739+ name , val := strings .TrimSpace (kv [0 ]), strings .TrimSpace (kv [1 ])
740+ var enabled bool
741+ switch val {
742+ case "on" :
743+ enabled = true
744+ case "off" :
745+ enabled = false
746+ default :
747+ return fmt .Errorf ("invalid value %q for category %q: must be 'on' or 'off'" , val , name )
748+ }
749+ switch name {
750+ case "console" :
751+ p .Console = kernel.BrowserTelemetryCategoryConfigParam {Enabled : kernel .Opt (enabled )}
752+ case "interaction" :
753+ p .Interaction = kernel.BrowserTelemetryCategoryConfigParam {Enabled : kernel .Opt (enabled )}
754+ case "network" :
755+ p .Network = kernel.BrowserTelemetryCategoryConfigParam {Enabled : kernel .Opt (enabled )}
756+ case "page" :
757+ p .Page = kernel.BrowserTelemetryCategoryConfigParam {Enabled : kernel .Opt (enabled )}
758+ default :
759+ return fmt .Errorf ("unknown category %q: must be one of console, interaction, network, page" , name )
760+ }
761+ }
762+ res , err := b .browsers .Update (ctx , in .Identifier , kernel.BrowserUpdateParams {
763+ Telemetry : kernel.BrowserTelemetryRequestConfigParam {Browser : p },
764+ })
765+ if err != nil {
766+ return util.CleanedUpSdkError {Err : err }
767+ }
768+ if in .Output == "json" {
769+ return util .PrintPrettyJSON (res )
770+ }
771+ pterm .Success .Printf ("Updated telemetry categories for browser %s\n " , in .Identifier )
772+ return nil
773+ }
774+
775+ func (b BrowsersCmd ) TelemetryStatus (ctx context.Context , in BrowsersTelemetryStatusInput ) error {
776+ if in .Output != "" && in .Output != "json" {
777+ return fmt .Errorf ("unsupported --output value: use 'json'" )
778+ }
779+ browser , err := b .browsers .Get (ctx , in .Identifier , kernel.BrowserGetParams {})
780+ if err != nil {
781+ return util.CleanedUpSdkError {Err : err }
782+ }
783+ if in .Output == "json" {
784+ return util .PrintPrettyJSON (browser .Telemetry )
785+ }
786+ cfg := browser .Telemetry .Browser
787+ pterm .Printf ("console: %s\n " , onOff (cfg .Console .Enabled ))
788+ pterm .Printf ("interaction: %s\n " , onOff (cfg .Interaction .Enabled ))
789+ pterm .Printf ("network: %s\n " , onOff (cfg .Network .Enabled ))
790+ pterm .Printf ("page: %s\n " , onOff (cfg .Page .Enabled ))
791+ return nil
792+ }
793+
794+ func onOff (v bool ) string {
795+ if v {
796+ return "on"
797+ }
798+ return "off"
799+ }
800+
718801// eventCategory derives the category prefix from a telemetry event type string.
719802// e.g. "network_response" -> "network", "monitor_screenshot" -> "monitor".
720803func eventCategory (eventType string ) string {
@@ -2400,11 +2483,17 @@ func init() {
24002483 telemetryStream .Flags ().StringSlice ("types" , []string {}, "Filter by event type (e.g. network_response,console_error)" )
24012484 telemetryStream .Flags ().Int64 ("seq" , 0 , "Resume stream from sequence number (Last-Event-ID)" )
24022485 telemetryStream .Flags ().StringP ("output" , "o" , "" , "Output format: json for newline-delimited JSON envelopes" )
2403- telemetryStart := & cobra.Command {Use : "start <id>" , Short : "Start telemetry capture" , Args : cobra .ExactArgs (1 ), RunE : runBrowsersTelemetryStart }
2486+ telemetryStart := & cobra.Command {Use : "start <id>" , Short : "Start telemetry capture (enabled: true) " , Args : cobra .ExactArgs (1 ), RunE : runBrowsersTelemetryStart }
24042487 telemetryStart .Flags ().StringP ("output" , "o" , "" , "Output format: json for raw API response" )
2405- telemetryStop := & cobra.Command {Use : "stop <id>" , Short : "Stop telemetry capture" , Args : cobra .ExactArgs (1 ), RunE : runBrowsersTelemetryStop }
2488+ telemetryStop := & cobra.Command {Use : "stop <id>" , Short : "Stop telemetry capture (enabled: false) " , Args : cobra .ExactArgs (1 ), RunE : runBrowsersTelemetryStop }
24062489 telemetryStop .Flags ().StringP ("output" , "o" , "" , "Output format: json for raw API response" )
2407- telemetryRoot .AddCommand (telemetryStream , telemetryStart , telemetryStop )
2490+ telemetrySet := & cobra.Command {Use : "set <id>" , Short : "Set per-category telemetry config" , Args : cobra .ExactArgs (1 ), RunE : runBrowsersTelemetrySet }
2491+ telemetrySet .Flags ().String ("categories" , "" , "Per-category assignments, e.g. network=on,page=off (console, interaction, network, page)" )
2492+ _ = telemetrySet .MarkFlagRequired ("categories" )
2493+ telemetrySet .Flags ().StringP ("output" , "o" , "" , "Output format: json for raw API response" )
2494+ telemetryStatus := & cobra.Command {Use : "status <id>" , Short : "Show current telemetry configuration" , Args : cobra .ExactArgs (1 ), RunE : runBrowsersTelemetryStatus }
2495+ telemetryStatus .Flags ().StringP ("output" , "o" , "" , "Output format: json for raw API response" )
2496+ telemetryRoot .AddCommand (telemetryStream , telemetryStart , telemetryStop , telemetrySet , telemetryStatus )
24082497 browsersCmd .AddCommand (telemetryRoot )
24092498
24102499 // process
@@ -2636,7 +2725,7 @@ func init() {
26362725 browsersCreateCmd .Flags ().Bool ("viewport-interactive" , false , "Interactively select viewport size from list" )
26372726 browsersCreateCmd .Flags ().String ("pool-id" , "" , "Browser pool ID to acquire from (mutually exclusive with --pool-name)" )
26382727 browsersCreateCmd .Flags ().String ("pool-name" , "" , "Browser pool name to acquire from (mutually exclusive with --pool-id)" )
2639- browsersCreateCmd .Flags ().Bool ("telemetry" , false , "Enable telemetry capture on the new session" )
2728+ browsersCreateCmd .Flags ().Bool ("telemetry" , false , "Enable telemetry capture on the new session (enabled: true) " )
26402729
26412730 // curl
26422731 curlCmd := & cobra.Command {
@@ -2816,8 +2905,8 @@ func runBrowsersCreate(cmd *cobra.Command, args []string) error {
28162905 StartURL : startURL ,
28172906 Extensions : extensions ,
28182907 Viewport : viewport ,
2819- TelemetryEnabled : telemetry ,
2820- Output : output ,
2908+ TelemetryEnabled : telemetry ,
2909+ Output : output ,
28212910 }
28222911
28232912 svc := client .Browsers
@@ -2957,6 +3046,23 @@ func runBrowsersTelemetryStop(cmd *cobra.Command, args []string) error {
29573046 return b .TelemetryStop (cmd .Context (), BrowsersTelemetryStopInput {Identifier : args [0 ], Output : out })
29583047}
29593048
3049+ func runBrowsersTelemetrySet (cmd * cobra.Command , args []string ) error {
3050+ client := getKernelClient (cmd )
3051+ svc := client .Browsers
3052+ out , _ := cmd .Flags ().GetString ("output" )
3053+ categories , _ := cmd .Flags ().GetString ("categories" )
3054+ b := BrowsersCmd {browsers : & svc }
3055+ return b .TelemetrySet (cmd .Context (), BrowsersTelemetrySetInput {Identifier : args [0 ], Categories : categories , Output : out })
3056+ }
3057+
3058+ func runBrowsersTelemetryStatus (cmd * cobra.Command , args []string ) error {
3059+ client := getKernelClient (cmd )
3060+ svc := client .Browsers
3061+ out , _ := cmd .Flags ().GetString ("output" )
3062+ b := BrowsersCmd {browsers : & svc }
3063+ return b .TelemetryStatus (cmd .Context (), BrowsersTelemetryStatusInput {Identifier : args [0 ], Output : out })
3064+ }
3065+
29603066func runBrowsersTelemetryStream (cmd * cobra.Command , args []string ) error {
29613067 client := getKernelClient (cmd )
29623068 svc := client .Browsers
0 commit comments