From d05c65a6bbeb0cad74abb8d531943bfb63c3a80c Mon Sep 17 00:00:00 2001 From: rgarcia <72655+rgarcia@users.noreply.github.com> Date: Wed, 6 May 2026 00:16:03 +0000 Subject: [PATCH] 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. --- cmd/browsers.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/cmd/browsers.go b/cmd/browsers.go index 6c0ac5d..66a2502 100644 --- a/cmd/browsers.go +++ b/cmd/browsers.go @@ -1326,9 +1326,14 @@ type BrowsersPlaywrightExecuteInput struct { Identifier string Code string Timeout int64 + Output string } func (b BrowsersCmd) PlaywrightExecute(ctx context.Context, in BrowsersPlaywrightExecuteInput) error { + if in.Output != "" && in.Output != "json" { + return fmt.Errorf("unsupported --output value: use 'json'") + } + if b.playwright == nil { pterm.Error.Println("playwright service not available") return nil @@ -1346,6 +1351,10 @@ func (b BrowsersCmd) PlaywrightExecute(ctx context.Context, in BrowsersPlaywrigh return util.CleanedUpSdkError{Err: err} } + if in.Output == "json" { + return util.PrintPrettyJSON(res) + } + rows := pterm.TableData{{"Property", "Value"}, {"Success", fmt.Sprintf("%t", res.Success)}} PrintTableNoPad(rows, true) @@ -2498,6 +2507,7 @@ func init() { playwrightRoot := &cobra.Command{Use: "playwright", Short: "Playwright operations"} playwrightExecute := &cobra.Command{Use: "execute [code]", Short: "Execute Playwright/TypeScript code against the browser", Args: cobra.MinimumNArgs(1), RunE: runBrowsersPlaywrightExecute} playwrightExecute.Flags().Int64("timeout", 0, "Maximum execution time in seconds (default per server)") + playwrightExecute.Flags().StringP("output", "o", "", "Output format: json for raw API response") playwrightRoot.AddCommand(playwrightExecute) browsersCmd.AddCommand(playwrightRoot) @@ -2954,8 +2964,9 @@ func runBrowsersPlaywrightExecute(cmd *cobra.Command, args []string) error { code = string(data) } timeout, _ := cmd.Flags().GetInt64("timeout") + output, _ := cmd.Flags().GetString("output") b := BrowsersCmd{browsers: &svc, playwright: &svc.Playwright} - return b.PlaywrightExecute(cmd.Context(), BrowsersPlaywrightExecuteInput{Identifier: args[0], Code: strings.TrimSpace(code), Timeout: timeout}) + return b.PlaywrightExecute(cmd.Context(), BrowsersPlaywrightExecuteInput{Identifier: args[0], Code: strings.TrimSpace(code), Timeout: timeout, Output: output}) } func runBrowsersFSNewDirectory(cmd *cobra.Command, args []string) error {