Skip to content

Commit d05c65a

Browse files
committed
add -o json to browsers playwright execute
Mirror the --output flag pattern used by other browsers commands (create, list, get, process exec, etc.) so playwright execute can emit raw API JSON for scripting.
1 parent 55a2b93 commit d05c65a

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)