Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 41 additions & 6 deletions cmd/browsers.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ func (b BrowsersCmd) List(ctx context.Context, in BrowsersListInput) error {
}

// Prepare table data
headers := []string{"Browser ID", "Name", "Created At", "Profile", "Pool", "CDP WS URL", "Live View URL"}
headers := []string{"Browser ID", "Name", "Created At", "Profile", "Save Changes", "Pool", "CDP WS URL", "Live View URL"}
showDeletedAt := in.IncludeDeleted || in.Status == "deleted" || in.Status == "all"
if showDeletedAt {
headers = append(headers, "Deleted At")
Expand All @@ -436,6 +436,7 @@ func (b BrowsersCmd) List(ctx context.Context, in BrowsersListInput) error {
util.OrDash(browser.Name),
util.FormatLocal(browser.CreatedAt),
profile,
util.OrDash(formatProfileSaveChanges(browser.ProfileSaveChanges, browser.JSON.ProfileSaveChanges.Valid())),
pool,
truncateURL(browser.CdpWsURL, 50),
truncateURL(browser.BrowserLiveViewURL, 50),
Expand Down Expand Up @@ -575,20 +576,41 @@ func (b BrowsersCmd) Create(ctx context.Context, in BrowsersCreateInput) error {
return util.PrintPrettyJSON(browser)
}

printBrowserSessionResult(browser.SessionID, browser.CdpWsURL, browser.BrowserLiveViewURL, browser.Profile, browser.StartURL, browser.Name, browser.Tags)
printBrowserSessionResult(
browser.SessionID,
browser.CdpWsURL,
browser.BrowserLiveViewURL,
browser.Profile,
formatProfileSaveChanges(browser.ProfileSaveChanges, browser.JSON.ProfileSaveChanges.Valid()),
browser.StartURL,
browser.Name,
browser.Tags,
)
if in.Telemetry != "" {
printTelemetrySummary(browser.Telemetry)
}
return nil
}

func printBrowserSessionResult(sessionID, cdpURL, liveViewURL string, profile kernel.Profile, startURL, name string, tags kernel.Tags) {
tableData := buildBrowserTableData(sessionID, cdpURL, liveViewURL, profile, startURL, name, tags)
func printBrowserSessionResult(
sessionID, cdpURL, liveViewURL string,
profile kernel.Profile,
profileSaveChanges, startURL, name string,
tags kernel.Tags,
) {
tableData := buildBrowserTableData(sessionID, cdpURL, liveViewURL, profile, profileSaveChanges, startURL, name, tags)
PrintTableNoPad(tableData, true)
}

func formatProfileSaveChanges(value, valid bool) string {
if !valid {
return ""
}
return strconv.FormatBool(value)
}

// buildBrowserTableData creates a base table with common browser session fields.
func buildBrowserTableData(sessionID, cdpURL, liveViewURL string, profile kernel.Profile, startURL, name string, tags kernel.Tags) pterm.TableData {
func buildBrowserTableData(sessionID, cdpURL, liveViewURL string, profile kernel.Profile, profileSaveChanges, startURL, name string, tags kernel.Tags) pterm.TableData {
tableData := pterm.TableData{
{"Property", "Value"},
{"Session ID", sessionID},
Expand All @@ -607,6 +629,9 @@ func buildBrowserTableData(sessionID, cdpURL, liveViewURL string, profile kernel
}
tableData = append(tableData, []string{"Profile", profVal})
}
if profileSaveChanges != "" {
tableData = append(tableData, []string{"Save Changes", profileSaveChanges})
}
if startURL != "" {
tableData = append(tableData, []string{"Start URL", startURL})
}
Expand Down Expand Up @@ -683,6 +708,7 @@ func (b BrowsersCmd) Get(ctx context.Context, in BrowsersGetInput) error {
browser.CdpWsURL,
browser.BrowserLiveViewURL,
browser.Profile,
formatProfileSaveChanges(browser.ProfileSaveChanges, browser.JSON.ProfileSaveChanges.Valid()),
browser.StartURL,
browser.Name,
browser.Tags,
Expand Down Expand Up @@ -2988,7 +3014,16 @@ func runBrowsersCreate(cmd *cobra.Command, args []string) error {
if output == "json" {
return util.PrintPrettyJSON(resp)
}
printBrowserSessionResult(resp.SessionID, resp.CdpWsURL, resp.BrowserLiveViewURL, resp.Profile, resp.StartURL, resp.Name, resp.Tags)
printBrowserSessionResult(
resp.SessionID,
resp.CdpWsURL,
resp.BrowserLiveViewURL,
resp.Profile,
formatProfileSaveChanges(resp.ProfileSaveChanges, resp.JSON.ProfileSaveChanges.Valid()),
resp.StartURL,
resp.Name,
resp.Tags,
)
return nil
}

Expand Down
40 changes: 40 additions & 0 deletions cmd/browsers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,46 @@ func TestBrowsersList_PrintsTableWithRows(t *testing.T) {
assert.Contains(t, out, "sess-2")
}

func TestBrowsersList_PrintsProfileSaveChanges(t *testing.T) {
setupStdoutCapture(t)

var writer kernel.BrowserListResponse
require.NoError(t, json.Unmarshal([]byte(`{
"session_id": "writer",
"profile_save_changes": true
}`), &writer))
var reader kernel.BrowserListResponse
require.NoError(t, json.Unmarshal([]byte(`{
"session_id": "reader",
"profile_save_changes": false
}`), &reader))

fake := &FakeBrowsersService{
ListFunc: func(ctx context.Context, query kernel.BrowserListParams, opts ...option.RequestOption) (*pagination.OffsetPagination[kernel.BrowserListResponse], error) {
return &pagination.OffsetPagination[kernel.BrowserListResponse]{Items: []kernel.BrowserListResponse{writer, reader}}, nil
},
}
b := BrowsersCmd{browsers: fake}
require.NoError(t, b.List(context.Background(), BrowsersListInput{}))

out := outBuf.String()
assert.Contains(t, out, "Save Changes")
assert.Contains(t, out, "true")
assert.Contains(t, out, "false")
}

func TestBuildBrowserTableData_PrintsProfileSaveChangesWhenPresent(t *testing.T) {
tableData := buildBrowserTableData("session", "ws://cdp", "", kernel.Profile{}, "false", "", "", nil)
assert.Contains(t, tableData, []string{"Save Changes", "false"})

tableData = buildBrowserTableData("session", "ws://cdp", "", kernel.Profile{}, "", "", "", nil)
for _, row := range tableData {
if len(row) > 0 {
assert.NotEqual(t, "Save Changes", row[0])
}
}
}

func TestBrowsersList_PrintsErrorOnFailure(t *testing.T) {
setupStdoutCapture(t)

Expand Down
Loading