Skip to content

Commit c183fe9

Browse files
authored
add -o json to browsers playwright execute (#158)
## Summary `kernel browsers playwright execute` lacked the `--output/-o` flag that other `browsers` subcommands expose (`create`, `list`, `get`, `view`, `update`, `process exec`, etc.). Add it using the same pattern: `-o json` prints the raw API response via `util.PrintPrettyJSON`, anything else returns the existing pterm tabular output, and unknown values error early. ## Test plan - [x] `make build` — succeeds - [x] `make test` — passes - [x] `./bin/kernel browsers playwright execute --help` shows `-o, --output` - [ ] manual: `kernel browsers playwright execute <id> 'return 1' -o json` returns valid JSON <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Low risk CLI change that only affects formatting/flag parsing for `browsers playwright execute`, with an early validation error for unsupported `--output` values. > > **Overview** > Adds `--output/-o` to `kernel browsers playwright execute` to match other `browsers` subcommands. > > When `-o json` is provided, the command now prints the raw `Execute` API response via `util.PrintPrettyJSON`; otherwise it keeps the existing table/stdout/stderr rendering, and invalid `--output` values fail fast. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit d05c65a. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> Co-authored-by: rgarcia <72655+rgarcia@users.noreply.github.com>
1 parent 55a2b93 commit c183fe9

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

cmd/browsers.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1326,9 +1326,14 @@ type BrowsersPlaywrightExecuteInput struct {
13261326
Identifier string
13271327
Code string
13281328
Timeout int64
1329+
Output string
13291330
}
13301331

13311332
func (b BrowsersCmd) PlaywrightExecute(ctx context.Context, in BrowsersPlaywrightExecuteInput) error {
1333+
if in.Output != "" && in.Output != "json" {
1334+
return fmt.Errorf("unsupported --output value: use 'json'")
1335+
}
1336+
13321337
if b.playwright == nil {
13331338
pterm.Error.Println("playwright service not available")
13341339
return nil
@@ -1346,6 +1351,10 @@ func (b BrowsersCmd) PlaywrightExecute(ctx context.Context, in BrowsersPlaywrigh
13461351
return util.CleanedUpSdkError{Err: err}
13471352
}
13481353

1354+
if in.Output == "json" {
1355+
return util.PrintPrettyJSON(res)
1356+
}
1357+
13491358
rows := pterm.TableData{{"Property", "Value"}, {"Success", fmt.Sprintf("%t", res.Success)}}
13501359
PrintTableNoPad(rows, true)
13511360

@@ -2498,6 +2507,7 @@ func init() {
24982507
playwrightRoot := &cobra.Command{Use: "playwright", Short: "Playwright operations"}
24992508
playwrightExecute := &cobra.Command{Use: "execute <id> [code]", Short: "Execute Playwright/TypeScript code against the browser", Args: cobra.MinimumNArgs(1), RunE: runBrowsersPlaywrightExecute}
25002509
playwrightExecute.Flags().Int64("timeout", 0, "Maximum execution time in seconds (default per server)")
2510+
playwrightExecute.Flags().StringP("output", "o", "", "Output format: json for raw API response")
25012511
playwrightRoot.AddCommand(playwrightExecute)
25022512
browsersCmd.AddCommand(playwrightRoot)
25032513

@@ -2954,8 +2964,9 @@ func runBrowsersPlaywrightExecute(cmd *cobra.Command, args []string) error {
29542964
code = string(data)
29552965
}
29562966
timeout, _ := cmd.Flags().GetInt64("timeout")
2967+
output, _ := cmd.Flags().GetString("output")
29572968
b := BrowsersCmd{browsers: &svc, playwright: &svc.Playwright}
2958-
return b.PlaywrightExecute(cmd.Context(), BrowsersPlaywrightExecuteInput{Identifier: args[0], Code: strings.TrimSpace(code), Timeout: timeout})
2969+
return b.PlaywrightExecute(cmd.Context(), BrowsersPlaywrightExecuteInput{Identifier: args[0], Code: strings.TrimSpace(code), Timeout: timeout, Output: output})
29592970
}
29602971

29612972
func runBrowsersFSNewDirectory(cmd *cobra.Command, args []string) error {

0 commit comments

Comments
 (0)